public char readChar()

in netflix-sel/src/main/java/com/netflix/sel/ast/JavaCharStream.java [223:301]


  public char readChar() throws java.io.IOException {
    if (inBuf > 0) {
      --inBuf;

      if (++bufpos == bufsize) bufpos = 0;

      return buffer[bufpos];
    }

    char c;

    if (++bufpos == available) AdjustBuffSize();

    if ((buffer[bufpos] = c = ReadByte()) == '\\') {
      if (trackLineColumn) {
        UpdateLineColumn(c);
      }

      int backSlashCnt = 1;

      for (; ; ) // Read all the backslashes
      {
        if (++bufpos == available) AdjustBuffSize();

        try {
          if ((buffer[bufpos] = c = ReadByte()) != '\\') {
            if (trackLineColumn) {
              UpdateLineColumn(c);
            }
            // found a non-backslash char.
            if ((c == 'u') && ((backSlashCnt & 1) == 1)) {
              if (--bufpos < 0) bufpos = bufsize - 1;

              break;
            }

            backup(backSlashCnt);
            return '\\';
          }
        } catch (java.io.IOException e) {
          // We are returning one backslash so we should only backup (count-1)
          if (backSlashCnt > 1) backup(backSlashCnt - 1);

          return '\\';
        }

        if (trackLineColumn) {
          UpdateLineColumn(c);
        }
        backSlashCnt++;
      }

      // Here, we have seen an odd number of backslash's followed by a 'u'
      try {
        while ((c = ReadByte()) == 'u') ++column;

        buffer[bufpos] =
            c =
                (char)
                    (hexval(c) << 12
                        | hexval(ReadByte()) << 8
                        | hexval(ReadByte()) << 4
                        | hexval(ReadByte()));

        column += 4;
      } catch (java.io.IOException e) {
        throw new Error("Invalid escape character at line " + line + " column " + column + ".");
      }

      if (backSlashCnt == 1) return c;
      else {
        backup(backSlashCnt - 1);
        return '\\';
      }
    } else {
      UpdateLineColumn(c);
      return c;
    }
  }