1 8 13 package jfun.parsec.tokens; 14 15 import jfun.parsec.Tokenizer; 16 17 24 public class TokenQuoted implements java.io.Serializable { 25 private final String open; 26 private final String close; 27 private final String quoted; 28 29 34 35 TokenQuoted(final String open, final String close, final String quoted) { 36 this.open = open; 37 this.close = close; 38 this.quoted = quoted; 39 } 40 41 public boolean equals(Object obj) { 42 if(obj instanceof TokenQuoted){ 43 final TokenQuoted tq2 = (TokenQuoted)obj; 44 return open.equals(tq2.open) && close.equals(tq2.close) 45 && quoted.equals(tq2.quoted); 46 } 47 else return false; 48 } 49 public int hashCode() { 50 return open.hashCode() + quoted.hashCode() + close.hashCode(); 51 } 52 public String toString(){ 53 return open+quoted+close; 54 } 55 62 public static Tokenizer getTokenizer(final char open, final char close){ 63 return getTokenizer(""+open, ""+close); 64 } 65 72 public static Tokenizer getTokenizer(final String open, final String close){ 73 return new Tokenizer(){ 74 public Object toToken(final CharSequence cs, final int from, final int len){ 75 final int start = from + open.length(); 76 final int end = from + len - close.length(); 77 return new TokenQuoted(open, close, cs.subSequence(start, end).toString()); 78 } 79 }; 80 } 81 85 public final String getClose() { 86 return close; 87 } 88 92 public final String getQuoted() { 93 return quoted; 94 } 95 99 public final String getOpen() { 100 return open; 101 } 102 } 103 | Popular Tags |