1 19 20 package gnu.regexp; 21 22 25 final class RETokenWordBoundary extends REToken { 26 private boolean negated; 27 private int where; 28 static final int BEGIN = 1; 29 static final int END = 2; 30 31 RETokenWordBoundary(int subIndex, int where, boolean negated) { 32 super(subIndex); 33 this.where = where; 34 this.negated = negated; 35 } 36 37 boolean match(CharIndexed input, REMatch mymatch) { 38 boolean after = false; boolean before = false; char ch; 47 48 if (((mymatch.eflags & RE.REG_ANCHORINDEX) != RE.REG_ANCHORINDEX) 50 || (mymatch.offset + mymatch.index > mymatch.anchor)) { 51 if ((ch = input.charAt(mymatch.index - 1)) != CharIndexed.OUT_OF_BOUNDS) { 52 before = Character.isLetterOrDigit(ch) || (ch == '_'); 53 } 54 } 55 56 if ((ch = input.charAt(mymatch.index)) != CharIndexed.OUT_OF_BOUNDS) { 57 after = Character.isLetterOrDigit(ch) || (ch == '_'); 58 } 59 60 boolean doNext = false; 63 64 if ((where & BEGIN) == BEGIN) { 65 doNext = after && !before; 66 } 67 if ((where & END) == END) { 68 doNext ^= before && !after; 69 } 70 71 if (negated) doNext = !doNext; 72 73 return (doNext ? next(input, mymatch) : false); 74 } 75 76 void dump(StringBuffer os) { 77 if (where == (BEGIN | END)) { 78 os.append( negated ? "\\B" : "\\b" ); 79 } else if (where == BEGIN) { 80 os.append("\\<"); 81 } else { 82 os.append("\\>"); 83 } 84 } 85 } 86 | Popular Tags |