KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > daffodilwoods > daffodildb > utils > parser > StringProductionRulesWithoutSpace


1 package com.daffodilwoods.daffodildb.utils.parser;
2
3 public class StringProductionRulesWithoutSpace extends StringProductionRules implements java.io.Serializable JavaDoc{
4
5    StringProductionRulesWithoutSpace(ClassLoader JavaDoc classLoader0){
6      super(classLoader0);
7    }
8
9    Object JavaDoc parsePart(ParseElements pe){
10
11       if(pe.position >= pe.query.length() || pe.recursiveObject != null){
12          pe.parseException.setPosition(pe.getIndexPosition(pe.position));
13          return pe.parseException;
14       }
15
16       int cmp = checkString(pe.queryArray,string,pe.position);
17       if ( cmp == 0 ) {
18           pe.position += ((String JavaDoc)result).length();
19           if ( pe.position <= pe.queryArray.length - 1)
20                return new Object JavaDoc[]{result};
21           if ( pe.position == pe.queryArray.length )
22                  return new Object JavaDoc[]{result};
23       }
24       cmp = cmp > 0 ? 1 : cmp < 0 ? -1 : 0;
25       pe.parseException.setReturnType(cmp);
26       pe.parseException.setPosition(pe.getIndexPosition(pe.position));
27       return pe.parseException;
28    }
29
30    private int checkString(char []source, char[] target,int position){
31      int compare = 0;
32      int i = position;
33      for(int j = 0; i < source.length && j < target.length && compare == 0; ++j,++i)
34           compare = source[i] - target[j];
35      return compare;
36    }
37
38    public String JavaDoc toString(){
39       return new StringBuffer JavaDoc(" STRING PROD RULE WITHOUT SPACE ").append(result).toString();
40    }
41
42 }
43
Popular Tags