Ignore:
Timestamp:
Apr 27, 2004, 8:39:34 PM (22 years ago)
Author:
bird
Message:

GCC v3.3.3 sources.

Location:
branches/GNU/src/gcc
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/GNU/src/gcc

    • Property svn:ignore
      •  

        old new  
        2626configure.vr
        2727configure.vrs
         28
        2829Makefile
        29 dir.info
        3030lost+found
        3131update.out
  • branches/GNU/src/gcc/libjava/java/util/StringTokenizer.java

    • Property cvs2svn:cvs-rev changed from 1.1 to 1.1.1.2
    r1390 r1391  
    1 /* java.util.StringTokenizer
    2    Copyright (C) 1998, 1999, 2001 Free Software Foundation, Inc.
     1/*
     2   Copyright (C) 1998, 1999, 2001 Free Software Foundation, Inc.
    33
    44This file is part of GNU Classpath.
     
    4040
    4141/**
    42  * This class splits a string into tokens.  The caller can set on which 
     42 * This class splits a string into tokens.  The caller can set on which
    4343 * delimiters the string should be split and if the delimiters should be
    44  * returned.
     44 * returned.
    4545 *
    46  * You may change the delimiter set on the fly by calling
     46 * You may change the delimiter set on the fly by calling
    4747 * nextToken(String).  But the semantic is quite difficult; it even
    4848 * depends on calling <code>hasMoreTokens()</code>.  You should call
    4949 * <code>hasMoreTokens()</code> before, otherwise the old delimiters
    50  * after the last token are returned.
     50 * after the last token are returned.
    5151 *
    52  * If you want to get the delimiters, you have to use the three argument
     52 * If you want to get the delimiters, you have to use the three argument
    5353 * constructor.  The delimiters are returned as token consisting of a
    54  * single character. 
     54 * single character.
    5555 *
    5656 * @author Jochen Hoenicke
    5757 * @author Warren Levy <[email protected]>
     58
     59
    5860 */
    5961public class StringTokenizer implements Enumeration
    6062{
     63
     64
     65
    6166  /**
    6267   * The position in the str, where we currently are.
    6368   */
    6469  private int pos;
     70
    6571  /**
    6672   * The string that should be split into tokens.
    6773   */
    68   private String str;
     74  private final String str;
     75
     76  /**
     77   * The length of the string.
     78   */
     79  private final int len;
     80
    6981  /**
    7082   * The string containing the delimiter characters.
    7183   */
    7284  private String delim;
     85
    7386  /**
    7487   * Tells, if we should return the delimiters.
    7588   */
    76   private boolean retDelims;
    77 
    78   /*{
    79      invariant {
    80      pos >= 0 :: "position is negative";
    81      pos <= str.length() :: "position is out of string";
    82      str != null :: "String is null";
    83      delim != null :: "Delimiters are null";
    84      }
    85      } */
     89  private final boolean retDelims;
    8690
    8791  /**
    8892   * Creates a new StringTokenizer for the string <code>str</code>,
    89    * that should split on the default delimiter set (space, tap,
     93   * that should split on the default delimiter set (space, ta,
    9094   * newline, return and formfeed), and which doesn't return the
    9195   * delimiters.
    92    * @param str The string to split.
     96   *
     97   * @param str The string to split
     98   * @throws NullPointerException if str is null
    9399   */
    94100  public StringTokenizer(String str)
    95     /*{ require { str != null :: "str must not be null"; } } */
    96101  {
    97102    this(str, " \t\n\r\f", false);
     
    99104
    100105  /**
    101    * Create a new StringTokenizer, that splits the given string on 
     106   * Create a new StringTokenizer, that splits the given string on
    102107   * the given delimiter characters.  It doesn't return the delimiter
    103108   * characters.
    104109   *
    105    * @param str The string to split.
    106    * @param delim A string containing all delimiter characters.
     110   * @param str the string to split
     111   * @param delim a string containing all delimiter characters
     112   * @throws NullPointerException if either argument is null
    107113   */
    108114  public StringTokenizer(String str, String delim)
    109     /*{ require { str != null :: "str must not be null";
    110        delim != null :: "delim must not be null"; } } */
    111115  {
    112116    this(str, delim, false);
     
    120124   * tokens always consist of a single character.
    121125   *
    122    * @param str The string to split.
    123    * @param delim A string containing all delimiter characters.
    124    * @param returnDelims Tells, if you want to get the delimiters.
     126   * @param str the string to split
     127   * @param delim a string containing all delimiter characters
     128   * @param returnDelims tells, if you want to get the delimiters
     129   * @throws NullPointerException if str or delim is null
    125130   */
    126131  public StringTokenizer(String str, String delim, boolean returnDelims)
    127     /*{ require { str != null :: "str must not be null";
    128        delim != null :: "delim must not be null"; } } */
    129   {
     132  {
     133    len = str.length();
    130134    this.str = str;
    131     this.delim = delim;
     135    // The toString() hack causes the NullPointerException.
     136    this.delim = delim.toString();
    132137    this.retDelims = returnDelims;
    133138    this.pos = 0;
     
    136141  /**
    137142   * Tells if there are more tokens.
    138    * @return True, if the next call of nextToken() succeeds, false otherwise.
     143   *
     144   * @return true if the next call of nextToken() will succeed
    139145   */
    140146  public boolean hasMoreTokens()
    141147  {
    142     if (!retDelims)
    143       {
    144         while (pos < str.length() && delim.indexOf(str.charAt(pos)) > -1)
    145           {
    146             pos++;
    147           }
    148       }
    149     return pos < str.length();
     148    if (! retDelims)
     149      {
     150        while (pos < len && delim.indexOf(str.charAt(pos)) >= 0)
     151          pos++;
     152      }
     153    return pos < len;
    150154  }
    151155
     
    155159   * permanent, ie. the next call of nextToken(), uses the same
    156160   * delimiter set.
    157    * @param delim a string containing the new delimiter characters.
    158    * @return the next token with respect to the new delimiter characters.
    159    * @exception NoSuchElementException if there are no more tokens.
     161   *
     162   * @param delim a string containing the new delimiter characters
     163   * @return the next token with respect to the new delimiter characters
     164   * @throws NoSuchElementException if there are no more tokens
     165   * @throws NullPointerException if delim is null
    160166   */
    161167  public String nextToken(String delim) throws NoSuchElementException
    162     /*{ require { hasMoreTokens() :: "no more Tokens available";
    163        ensure { $return != null && $return.length() > 0; } } */
    164168  {
    165169    this.delim = delim;
     
    169173  /**
    170174   * Returns the nextToken of the string.
    171    * @param delim a string containing the new delimiter characters.
    172    * @return the next token with respect to the new delimiter characters.
    173    * @exception NoSuchElementException if there are no more tokens.
     175   *
     176   * @return the next token with respect to the
     177   * @
    174178   */
    175179  public String nextToken() throws NoSuchElementException
    176     /*{ require { hasMoreTokens() :: "no more Tokens available";
    177        ensure { $return != null && $return.length() > 0; } } */
    178   {
    179     if (pos < str.length() && delim.indexOf(str.charAt(pos)) > -1)
    180       {
    181         if (retDelims)
    182           return str.substring(pos, ++pos);
    183 
    184         while (++pos < str.length() && delim.indexOf(str.charAt(pos)) > -1)
    185           {
    186             /* empty */
    187           }
    188       }
    189     if (pos < str.length())
    190       {
    191         int start = pos;
    192         while (++pos < str.length() && delim.indexOf(str.charAt(pos)) == -1)
    193           {
    194             /* empty */
    195           }
    196         return str.substring(start, pos);
     180  {
     181    if (pos < len && delim.indexOf(str.charAt(pos)) >= 0)
     182      {
     183        if (retDelims)
     184          return str.substring(pos, ++pos);
     185        while (++pos < len && delim.indexOf(str.charAt(pos)) >= 0);
     186      }
     187    if (pos < len)
     188      {
     189        int start = pos;
     190        while (++pos < len && delim.indexOf(str.charAt(pos)) < 0);
     191
     192        return str.substring(start, pos);
    197193      }
    198194    throw new NoSuchElementException();
     
    202198   * This does the same as hasMoreTokens. This is the
    203199   * <code>Enumeration</code interface method.
    204    * @return True, if the next call of nextElement() succeeds, false
    205    * otherwise. 
    206    * @see #hasMoreTokens
     200   *
     201   *
     202   * @see #hasMoreTokens
    207203   */
    208204  public boolean hasMoreElements()
     
    214210   * This does the same as nextTokens. This is the
    215211   * <code>Enumeration</code interface method.
    216    * @return the next token with respect to the new delimiter characters.
    217    * @exception NoSuchElementException if there are no more tokens.
    218    * @see #nextToken
     212   *
     213   * @return the next token with respect to the current delimiter characters
     214   * @throws NoSuchElementException if there are no more tokens
     215   * @see #nextToken()
    219216   */
    220217  public Object nextElement() throws NoSuchElementException
     
    226223   * This counts the number of remaining tokens in the string, with
    227224   * respect to the current delimiter set.
    228    * @return the number of times <code>nextTokens()</code> will
    229    * succeed. 
    230    * @see #nextToken
     225   *
     226   *
     227   * @see #nextToken
    231228   */
    232229  public int countTokens()
     
    234231    int count = 0;
    235232    int delimiterCount = 0;
    236     boolean tokenFound = false;         // Set when a non-delimiter is found
     233    boolean tokenFound = false;// Set when a non-delimiter is found
    237234    int tmpPos = pos;
    238235
     
    240237    // retDelims every time we encounter one.  That way, we can
    241238    // just do the conditional once at the end of the method
    242     while (tmpPos < str.length())
    243       {
    244         if (delim.indexOf(str.charAt(tmpPos++)) > -1)
    245           {
    246             if (tokenFound)
    247               {
    248                 // Got to the end of a token
    249                 count++;
    250                 tokenFound = false;
    251               }
    252 
    253             delimiterCount++;           // Increment for this delimiter
    254           }
    255         else
    256           {
    257             tokenFound = true;
    258 
    259             // Get to the end of the token
    260             while (tmpPos < str.length()
    261                    && delim.indexOf(str.charAt(tmpPos)) == -1)
    262               ++tmpPos;
    263           }
    264       }
    265 
    266     // Make sure to count the last token
     239    while (tmpPos < len)
     240      {
     241        if (delim.indexOf(str.charAt(tmpPos++)) >= 0)
     242          {
     243            if (tokenFound)
     244              {
     245                // Got to the end of a token
     246                count++;
     247                tokenFound = false;
     248              }
     249            delimiterCount++; // Increment for this delimiter
     250          }
     251        else
     252          {
     253            tokenFound = true;
     254            // Get to the end of the token
     255            while (tmpPos < len
     256                   && delim.indexOf(str.charAt(tmpPos)) < 0)
     257              ++tmpPos;
     258          }
     259      }
     260
     261    // Make sure to count the last token
    267262    if (tokenFound)
    268263      count++;
     
    271266    return retDelims ? count + delimiterCount : count;
    272267  }
    273 }
     268}
Note: See TracChangeset for help on using the changeset viewer.