1 package com.daffodilwoods.daffodildb.utils.parser; 2 3 public class RangeProductionRules extends ProductionRules{ 4 5 RangeProductionRules(ClassLoader classLoader0){ 6 super(classLoader0); 7 ruleKey = nameOfRule; 8 } 9 10 16 Object parsePart(ParseElements pe){ 17 int position = pe.position; 18 char[] val = pe.queryArray; 19 int length = val.length; 20 Object ob = parseComments(pe); 21 if(ob instanceof ParseException ) 22 return ob; 23 position = ((Integer )ob).intValue() ; 24 25 26 if(position >= val.length ) 28 return pe.parseException ; 29 if( checkForDigit(val[position]) ) 30 return pe.parseException; 31 StringBuffer stbfr = new StringBuffer (); while(position < length){ 33 if(position < length && (checkForDigit(val[position]) || checkForAlphabet(val[position])) ){ 34 stbfr.append(val[position]); 35 position ++; 36 } 37 else{ 38 pe.position = position; 39 if ( stbfr.length() == 0 ) 40 return pe.parseException; 41 return stbfr.toString(); 42 } 43 } 44 if ( stbfr.length() != 0 ){ 45 pe.position = position; 46 return stbfr.toString(); 47 } 48 return pe.parseException; 49 } 50 51 private boolean checkForDigit(char c){ 52 if ( c >= 48 && c <= 57 ) 53 return true; 54 return false; 55 } 56 57 private boolean checkForAlphabet(char c){ 58 if ( (c >= 65 && c <= 90) || (c >= 97 && c <= 122) || (c == 95) ) 59 return true; 60 return false; 61 } 62 } 63 | Popular Tags |