+ public SpannableString getTestMatch() {
+ return testMatch;
+ }
+ public void checkPatternMatch() {
+ patternError = null;
+ testMatch = null;
+
+ if (pattern != null) {
+ try {
+ if (Misc.emptyIsNull(testText) != null) {
+ SpannableString ss = new SpannableString(testText);
+ Matcher m = compiledPattern.matcher(testText);
+ if (m.find()) {
+ if (m.start() > 0)
+ ss.setSpan(notMatchedSpan(), 0, m.start(),
+ Spanned.SPAN_INCLUSIVE_INCLUSIVE);
+ if (m.end() < testText.length() - 1)
+ ss.setSpan(notMatchedSpan(), m.end(), testText.length(),
+ Spanned.SPAN_INCLUSIVE_INCLUSIVE);
+
+ ss.setSpan(matchedSpan(), m.start(0), m.end(0),
+ Spanned.SPAN_INCLUSIVE_INCLUSIVE);
+
+ if (m.groupCount() > 0) {
+ for (int g = 1; g <= m.groupCount(); g++) {
+ ss.setSpan(capturedSpan(), m.start(g), m.end(g),
+ Spanned.SPAN_INCLUSIVE_INCLUSIVE);
+ }
+ }
+ }
+ else {
+ patternError = "Pattern does not match";
+ ss.setSpan(new ForegroundColorSpan(Color.GRAY), 0,
+ testText.length() - 1, Spanned.SPAN_INCLUSIVE_INCLUSIVE);
+ }
+
+ testMatch = ss;
+ }
+ }
+ catch (PatternSyntaxException e) {
+ this.compiledPattern = null;
+ this.patternError = e.getMessage();
+ }
+ }
+ else {
+ patternError = "Missing pattern";
+ }
+ }
+ public String getPatternError() {
+ return patternError;
+ }
+ public SpannableString testMatch() {
+ return testMatch;
+ }