示例#1
0
  public void parseBlockComments(String text) {
    blockComments = new Vector();
    StringReader buffer = new StringReader(text);
    int ch;
    boolean blkComment = false;
    int cnt = 0;
    int[] offsets = new int[2];
    boolean done = false;

    try {
      while (!done) {
        switch (ch = buffer.read()) {
          case -1:
            {
              if (blkComment) {
                offsets[1] = cnt;
                blockComments.addElement(offsets);
              }
              done = true;
              break;
            }
          case '/':
            {
              ch = buffer.read();
              if ((ch == '*') && (!blkComment)) {
                offsets = new int[2];
                offsets[0] = cnt;
                blkComment = true;
                cnt++;
              } else {
                cnt++;
              }
              cnt++;
              break;
            }
          case '*':
            {
              if (blkComment) {
                ch = buffer.read();
                cnt++;
                if (ch == '/') {
                  blkComment = false;
                  offsets[1] = cnt;
                  blockComments.addElement(offsets);
                }
              }
              cnt++;
              break;
            }
          default:
            {
              cnt++;
              break;
            }
        }
      }
    } catch (IOException e) {
      // ignore errors
    }
  }
示例#2
0
 private static int nextNibble(StringReader r) throws IOException {
   while (true) {
     int ch = r.read();
     if (ch == -1) {
       return -1;
     } else if ((ch >= '0') && (ch <= '9')) {
       return ch - '0';
     } else if ((ch >= 'a') && (ch <= 'f')) {
       return ch - 'a' + 10;
     } else if ((ch >= 'A') && (ch <= 'F')) {
       return ch - 'A' + 10;
     }
   }
 }