1 8 13 package jfun.parsec.tokens; 14 15 import jfun.parsec.Tokenizer; 16 17 24 @Deprecated 25 public class TokenLong implements java.io.Serializable { 26 private TokenLong(){} 27 private static int toDecDigit(final char c){ 28 return c - '0'; 29 } 30 private static int toOctDigit(final char c){ 31 return c - '0'; 32 } 33 private static int toHexDigit(final char c){ 34 if(c>='0' && c<='9') return c-'0'; 35 if(c>='a' && c<='h') return c-'a'+10; 36 else return c-'A'+10; 37 } 38 private static final Tokenizer dTokenizer = new Tokenizer(){ 39 public Object toToken(final CharSequence cs, final int from, final int len){ 40 final int end = from + len; 41 long n = 0; 42 for(int i=from; i<end; i++){ 43 n = n*10 + toDecDigit(cs.charAt(i)); 44 } 45 return new Long (n); 46 } 47 }; 48 private static final Tokenizer oTokenizer = new Tokenizer(){ 49 public Object toToken(final CharSequence cs, final int from, final int len){ 50 final int end = from + len; 51 long n = 0; 52 for(int i=from; i<end; i++){ 53 n = n*8 + toOctDigit(cs.charAt(i)); 54 } 55 return new Long (n); 56 } 57 }; 58 private static final Tokenizer hTokenizer = new Tokenizer(){ 59 public Object toToken(final CharSequence cs, final int from, final int len){ 60 if(len < 3) throw new IllegalStateException ("illegal hex number"); 61 final int end = from + len; 62 long n = 0; 63 for(int i=from+2; i<end; i++){ 64 n = n*16 + toHexDigit(cs.charAt(i)); 65 } 66 return new Long (n); 67 } 68 }; 69 73 public static Tokenizer getDecTokenizer(){return dTokenizer;} 74 78 public static Tokenizer getOctTokenizer(){return oTokenizer;} 79 83 public static Tokenizer getHexTokenizer(){return hTokenizer;} 84 } 85 | Popular Tags |