1 8 13 package jfun.parsec.tokens; 14 15 import jfun.parsec.Tokenizer; 16 17 23 @Deprecated 24 public class TokenStringLiteral implements java.io.Serializable { 25 29 public static Tokenizer getDoubleQuoteTokenizer(){return sTokenizer;} 30 35 public static Tokenizer getSqlTokenizer(){return sqlTokenizer;} 36 private TokenStringLiteral(){} 37 private static final char escapedChar(final char c){ 38 switch(c){ 39 case 'r': 40 return '\r'; 41 case 'n': 42 return '\n'; 43 case 't': 44 return '\t'; 45 default: 46 return c; 47 48 } 49 } 50 static String tokenizeDoubleQuote(final CharSequence cs, 51 final int from, final int len){ 52 final int end = from + len -1; 53 final StringBuffer buf = new StringBuffer (); 54 for(int i=from+1; i<end;i++){ 55 final char c = cs.charAt(i); 56 if(c!='\\'){ 57 buf.append(c); 58 } 59 else{ 60 final char c1 = cs.charAt(++i); 61 buf.append(escapedChar(c1)); 62 } 63 } 64 return buf.toString(); 65 } 66 private static final Tokenizer sTokenizer = new Tokenizer(){ 67 public Object toToken(final CharSequence cs, final int from, final int len){ 68 return tokenizeDoubleQuote(cs, from, len); 69 } 70 }; 71 72 private static final Tokenizer sqlTokenizer = new Tokenizer(){ 73 public Object toToken(final CharSequence cs, final int from, final int len){ 74 final int end = from+len-1; 75 final StringBuffer buf = new StringBuffer (); 76 for(int i=from+1; i<end; i++){ 77 final char c = cs.charAt(i); 78 if(c!='\'') 79 buf.append(c); 80 else{ 81 buf.append('\''); 82 i++; 83 } 84 } 85 return buf.toString(); 86 } 87 }; 88 } 89 | Popular Tags |