/[classpath]/classpath/java/util/StringTokenizer.java
ViewVC logotype

Diff of /classpath/java/util/StringTokenizer.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.9 by ericb, Fri Feb 22 05:50:50 2002 UTC revision 1.10 by ericb, Fri Feb 22 07:08:04 2002 UTC
# Line 68  public class StringTokenizer implements Line 68  public class StringTokenizer implements
68    /**    /**
69     * The string that should be split into tokens.     * The string that should be split into tokens.
70     */     */
71    private String str;    private final String str;
72    
73      /**
74       * The length of the string.
75       */
76      private final int len;
77    
78    /**    /**
79     * The string containing the delimiter characters.     * The string containing the delimiter characters.
# Line 78  public class StringTokenizer implements Line 83  public class StringTokenizer implements
83    /**    /**
84     * Tells, if we should return the delimiters.     * Tells, if we should return the delimiters.
85     */     */
86    private boolean retDelims;    private final boolean retDelims;
87    
88    /**    /**
89     * Creates a new StringTokenizer for the string <code>str</code>,     * Creates a new StringTokenizer for the string <code>str</code>,
# Line 122  public class StringTokenizer implements Line 127  public class StringTokenizer implements
127     */     */
128    public StringTokenizer(String str, String delim, boolean returnDelims)    public StringTokenizer(String str, String delim, boolean returnDelims)
129    {    {
130        len = str.length();
131      this.str = str;      this.str = str;
132      this.delim = delim;      // The toString() hack causes the NullPointerException.
133        this.delim = delim.toString();
134      this.retDelims = returnDelims;      this.retDelims = returnDelims;
135      this.pos = 0;      this.pos = 0;
136    }    }
# Line 137  public class StringTokenizer implements Line 144  public class StringTokenizer implements
144    {    {
145      if (! retDelims)      if (! retDelims)
146        {        {
147          while (pos < str.length() && delim.indexOf(str.charAt(pos)) > -1)          while (pos < len && delim.indexOf(str.charAt(pos)) >= 0)
148            pos++;            pos++;
149        }        }
150      return pos < str.length();      return pos < len;
151    }    }
152    
153    /**    /**
# Line 152  public class StringTokenizer implements Line 159  public class StringTokenizer implements
159     * @param delim a string containing the new delimiter characters     * @param delim a string containing the new delimiter characters
160     * @return the next token with respect to the new delimiter characters     * @return the next token with respect to the new delimiter characters
161     * @throws NoSuchElementException if there are no more tokens     * @throws NoSuchElementException if there are no more tokens
162       * @throws NullPointerException if delim is null
163     */     */
164    public String nextToken(String delim) throws NoSuchElementException    public String nextToken(String delim) throws NoSuchElementException
165    {    {
# Line 167  public class StringTokenizer implements Line 175  public class StringTokenizer implements
175     */     */
176    public String nextToken() throws NoSuchElementException    public String nextToken() throws NoSuchElementException
177    {    {
178      if (pos < str.length() && delim.indexOf(str.charAt(pos)) > -1)      if (pos < len && delim.indexOf(str.charAt(pos)) >= 0)
179        {        {
180          if (retDelims)          if (retDelims)
181            return str.substring(pos, ++pos);            return str.substring(pos, ++pos);
182            while (++pos < len && delim.indexOf(str.charAt(pos)) >= 0);
         while (++pos < str.length() && delim.indexOf(str.charAt(pos)) > -1);  
183        }        }
184      if (pos < str.length())      if (pos < len)
185        {        {
186          int start = pos;          int start = pos;
187          while (++pos < str.length() && delim.indexOf(str.charAt(pos)) == -1);          while (++pos < len && delim.indexOf(str.charAt(pos)) < 0);
188    
189          return str.substring(start, pos);          return str.substring(start, pos);
190        }        }
# Line 226  public class StringTokenizer implements Line 233  public class StringTokenizer implements
233      // Note for efficiency, we count up the delimiters rather than check      // Note for efficiency, we count up the delimiters rather than check
234      // retDelims every time we encounter one.  That way, we can      // retDelims every time we encounter one.  That way, we can
235      // just do the conditional once at the end of the method      // just do the conditional once at the end of the method
236      while (tmpPos < str.length())      while (tmpPos < len)
237        {        {
238          if (delim.indexOf(str.charAt(tmpPos++)) > -1)          if (delim.indexOf(str.charAt(tmpPos++)) >= 0)
239            {            {
240              if (tokenFound)              if (tokenFound)
241                {                {
# Line 236  public class StringTokenizer implements Line 243  public class StringTokenizer implements
243                  count++;                  count++;
244                  tokenFound = false;                  tokenFound = false;
245                }                }
   
246              delimiterCount++; // Increment for this delimiter              delimiterCount++; // Increment for this delimiter
247            }            }
248          else          else
249            {            {
250              tokenFound = true;              tokenFound = true;
   
251              // Get to the end of the token              // Get to the end of the token
252              while (tmpPos < str.length()              while (tmpPos < len
253                     && delim.indexOf(str.charAt(tmpPos)) == -1)                     && delim.indexOf(str.charAt(tmpPos)) < 0)
254                ++tmpPos;                ++tmpPos;
255            }            }
256        }        }

Legend:
Removed from v.1.9  
changed lines
  Added in v.1.10

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26