package com.github.aureliano.evtbridge.core.matcher;

import java.util.regex.Pattern;

import com.github.aureliano.evtbridge.common.helper.StringHelper;

public class SingleLineMatcher implements IMatcher {

	private String prefixRegex;
	private String suffixRegex;
	
	private Pattern pattern;
	
	public SingleLineMatcher() {
		this(null);
	}
	
	public SingleLineMatcher(String prefixRegex) {
		this.prefixRegex = prefixRegex;
		this.suffixRegex = ".+$";
		
		if (StringHelper.isEmpty(this.prefixRegex)) {
			this.prefixRegex = "^(.+)";
			this.suffixRegex = "$";
		}
		
		this.pattern = Pattern.compile(this.prefixRegex);
	}

	@Override
	public boolean partialMatch(String text) {
		return this.pattern.matcher(text).find();
	}

	@Override
	public boolean matches(String text) {
		return text.matches(this.prefixRegex + this.suffixRegex);
	}

	@Override
	public String endMatch(String text) {
		return this.matches(text) ? text : null;
	}

	@Override
	public boolean isMultiLine() {
		return false;
	}
}
@@ -443,17 +443,17 @@
 gex = %22.
-+
+*
 $%22;%0A%09%09%0A%09
@@ -525,17 +525,17 @@
 x = %22%5E(.
-+
+*
 )%22;%0A%09%09%09t

Fix regular expression to also match an empty line.