String readIdentifierPart()

in src/main/java/com/google/cloud/spanner/pgadapter/statements/SimpleParser.java [707:745]


  String readIdentifierPart() {
    skipWhitespaces();
    if (pos >= sql.length()) {
      return null;
    }
    boolean quoted = sql.charAt(pos) == '"';
    int start = pos;
    if (quoted) {
      pos++;
    }
    boolean first = true;
    while (pos < sql.length()) {
      if (quoted) {
        if (sql.charAt(pos) == '"') {
          if (pos < (sql.length() - 1) && sql.charAt(pos + 1) == '"') {
            pos++;
          } else {
            return sql.substring(start, ++pos);
          }
        }
      } else {
        if (first) {
          if (!isValidIdentifierFirstChar(sql.charAt(pos))) {
            return null;
          }
          first = false;
        } else {
          if (!isValidIdentifierChar(sql.charAt(pos))) {
            return sql.substring(start, pos);
          }
        }
      }
      pos++;
    }
    if (quoted) {
      return null;
    }
    return sql.substring(start);
  }