Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4028902

StreamTokenizer erroneously generates leading space

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P3 P3
    • None
    • 1.1
    • core-libs
    • None
    • x86
    • windows_95



      Name: mc57594 Date: 01/29/97


      StreamTokenizer erroneously generates leading space in sval when
      space is defined not to be a whitespace-character. Possible cause
      implicit processing of peekc, which is initialized as ' ', at the beginning
      of an extraction.
      --- Example code follows
      public class c
      {
      public static void main (String args[]) {
      try {
      BufferedInputStream input = new BufferedInputStream(new FileInputStream("D:\\VIEWER\\TB96286"));
      StreamTokenizer st = new StreamTokenizer(input);
      st.resetSyntax();
      st.eolIsSignificant(false);

      st.wordChars(0, 255);
      st.ordinaryChars('+', '+');
      st.ordinaryChars(':', ':');
      st.ordinaryChars('\'', '\'');
      st.ordinaryChars('?', '?');

      String lastVal;
      for (int tokenType = st.nextToken();
      tokenType != StreamTokenizer.TT_EOF;
      tokenType = st.nextToken()) {
      switch (tokenType) {
      case StreamTokenizer.TT_NUMBER:
      // Not reached
      break;
      case StreamTokenizer.TT_WORD:
      System.out.println("'" + st.sval.substring(1) + "'"); // Need to ignore spurious space at beginning - library error
      lastVal = st.sval.substring(1);
      break;
      default: // Ordinary Character
      }
      }
      } catch (FileNotFoundException e) {
      System.out.println("File not found");
      } catch (IOException e) {
      System.out.println("I/O failure");
      }
      }
      }
      ======================================================================

            mr Mark Reinhold
            mchamnessunw Mark Chamness (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: