1 43 44 package org.exolab.jms.selector.parser; 45 46 import org.exolab.jms.selector.SelectorException; 47 48 49 58 final class PatternValidator { 59 60 63 private PatternValidator() { 64 } 65 66 73 public static void validate(final SelectorAST patternNode, 74 final SelectorAST escapeNode) 75 throws SelectorException { 76 77 String pattern = patternNode.getText(); 78 79 if (escapeNode != null) { 80 String escape = escapeNode.getText(); 81 if (escape.length() != 1) { 82 String msg = "escape must be a single character"; 83 throw new SelectorException(escapeNode.getContext(), msg); 84 } 85 86 char esc = escape.charAt(0); 87 for (int i = 0; i < pattern.length(); ++i) { 88 char ch = pattern.charAt(i); 89 if (pattern.charAt(i) == esc) { 90 if (++i >= pattern.length()) { 91 String msg = "invalid pattern: no character " 92 + "following last escape character"; 93 throw new SelectorException(patternNode.getContext(), 94 msg); 95 } 96 } 97 } 98 } 99 } 100 101 } | Popular Tags |