Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: cxtable/xLineSplit.java


1   package cxtable;
2   
3   /*This class takes a string filled with tags.... and when queried with
4   the key, returns either a single string (ssplit) or a string[] (split) of
5   all of the strings in between those tags...
6   
7   This could be one source of slow-down || inefficiency... but it hasn't
8   yet proven itself that way in the limited benchmarking...  
9   
10  The core of the communication in the program is done with tagged strings
11  (line by line) and so this is a major piece of the program...
12  */
13    
14  
15   import java.util.Vector;
16  
17      public class xLineSplit{
18     
19        boolean debug = false;
20        private String log,key,skey,ekey;
21        private int offset;
22     
23        public xLineSplit ()
24        {
25           key ="";
26           log ="";
27        }    
28     
29        public void setKey(String k_ey)
30        {key = k_ey;
31           skey = new String("<"+key+">");
32           ekey = new String("</"+key+">");
33           offset = skey.length();
34        }
35     
36     
37        public void setLog(String l_og)
38        {
39           log = l_og;
40        }
41     
42        private String[] split_()
43        {  String[] result;
44           Vector v= new Vector();
45           int point = 0;
46           int ln = log.length(); 
47           int counter =0;
48           int s,e;   
49           while(point<ln)
50           { 
51              s=log.indexOf(skey,point);
52              if (s==-1){
53                 break;}
54              s=s+offset;
55              e=log.indexOf(ekey,s);
56           
57              try{add(v,s,e);} 
58                 catch(Exception ez){
59                    System.out.println(ez.toString());}
60              point = e; 
61              e = 0; s = 0;
62           }
63        
64           if (v.size() < 1){result = new String[0];
65              return result;}
66           result = new String[v.size()];
67           for (int i=0; i<result.length;i++)
68           {
69              try{result[i] = (String)v.elementAt(i);
70              }
71                 catch(ClassCastException cce){
72                    result[i] ="";}
73           }
74           return result;      
75        }
76        public String ssplit(String k_ey, String l_og)
77        {
78        /*returns the first occurrance of a 'key' tag's contents*/
79           setKey(k_ey);setLog(l_og);
80           return single();
81        }
82     
83        public String[] split(String k_ey)
84        {
85           setKey(k_ey);
86           return split_();
87        }
88     
89        public String[] split(String k_ey, String l_og)
90        {setLog(l_og); setKey(k_ey); 
91           if (debug){System.out.println("k_ey:"+k_ey);}
92           return split_();}
93     
94     private String single()
95     {
96      String it ="";
97      int s_,e_;
98      try{
99      s_ = log.indexOf(skey,0);
100     s_=s_+offset;
101     e_ = log.indexOf(ekey,s_);
102     it = log.substring(s_,e_);
103     }
104     catch(Exception e){it="";}
105     return it;
106    }
107    
108       public void add(Vector c,int st, int en)
109       {
110          c.addElement(new String(log.substring(st,en)));}
111    
112    }
113 
114