Skip over comments and quoted names present in an SQL statement

@param statement character array containing SQL statement
@param position  current position of statement
@return next position to process after any comments or quotes are skipped
771390
private static int skipCommentsAndQuotes(char[] statement, int position) {
        for (int i = 0; i < START_SKIP.length; i++) {
            if (statement[position] == START_SKIP[i].charAt(0)) {
                boolean match = true;
                for (int j = 1; j < START_SKIP[i].length(); j++) {
                    if (!(statement[position + j] == START_SKIP[i].charAt(j))) {
                        match = false;
                        break;
                    }
                }
                if (match) {
                    int offset = START_SKIP[i].length();
                    for (int m = position + offset; m < statement.length; m++) {
                        if (statement[m] == STOP_SKIP[i].charAt(0)) {
                            boolean endMatch = true;
                            int endPos = m;
                            for (int n = 1; n < STOP_SKIP[i].length(); n++) {
                                if (m + n >= statement.length) {
                                    // last comment not closed properly
                                    return statement.length;
                                }
                                if (!(statement[m + n] == STOP_SKIP[i].charAt(n))) {
                                    endMatch = false;
                                    break;
                                }
                                endPos = m + n;
                            }
                            if (endMatch) {
                                // found character sequence ending comment or quote
                                return endPos + 1;
                            }
                        }
                    }
                    // character sequence ending comment or quote not found
                    return statement.length;
                }

            }
        }
        return position;
    }
687078
public static String parseEchoStatement(String statement)
    {
        Matcher matcher = EchoToken.matcher(statement);
        if (matcher.matches()) {
            String commandWordTerminator = matcher.group(1);
            if (OneWhitespace.matcher(commandWordTerminator).matches()) {
                return matcher.group(2);
            }
            return "";
        }
        return null;
    }
1130480
function processQuote(sql, startIdx) {
    const start = sql[startIdx];
    for(let i = startIdx + 1; i < sql.length; i++) {
        if(sql[i] === "\\") {
            i++;
            continue;
        }

        if(sql[i] === start) {
            return i;
        }
    }

    return sql.length;
}
1342335
public static Statement getStatement(CompilationUnit compilationUnit, MethodDeclaration method, int startLine, int endLine)
            throws StatementNotFoundException {
        requireNonNull(compilationUnit, "compilation unit");
        requireNonNull(method, "method declaration");

        Statement statement = searchStatement(compilationUnit, method.getBody().statements(), startLine, endLine);
        if (statement == null) {
            throw new StatementNotFoundException(compilationUnit, startLine, endLine);
        }
        return statement;
    }
418098
public int skipComment() {
        char current = charAt(offset);
        char next = charAt(offset + 1);
        if (isSingleLineCommentBegin(current, next)) {
            return skipSingleLineComment(COMMENT_BEGIN_SYMBOL_LENGTH);
        } else if ('#' == current) {
            return skipSingleLineComment(MYSQL_SPECIAL_COMMENT_BEGIN_SYMBOL_LENGTH);
        } else if (isMultipleLineCommentBegin(current, next)) {
            return skipMultiLineComment();
        }
        return offset;
    }
276130
public static String parseEchoErrorStatement(String statement) {
        Matcher matcher = EchoErrorToken.matcher(statement);
        if (matcher.matches()) {
            String commandWordTerminator = matcher.group(1);
            if (OneWhitespace.matcher(commandWordTerminator).matches()) {
                return matcher.group(2);
            }
            return "";
        }
        return null;
    }
488055
private final int skipPadding(String text, int position) {
        while (position < text.length() && text.charAt(position) == pad) {
            ++position;
        }
        return position;
    }
948624
public static void closeStatement(Statement statement, String sql) {
		if (statement != null) {
			try {
				statement.close();
			} catch (SQLException e) {
				log.log(Level.WARNING, "Failed to close SQL Statement: " + sql,
						e);
			}
		}
	}
611371
public void bind(SQLiteStatement statement) {
		if (this.compiledStatement != null) {
			// already binded
			return;
		}

		int index = 1;

		statement.clearBindings();
		Object value;

		for (int j = 0; j < args.size(); j++) {
			value = args.get(j);
			switch (valueType.get(index - 1)) {
			case BOOLEAN:
				statement.bindLong(index, (long) (((Boolean) value) == true ? 1 : 0));
				break;
			case BYTE:
				statement.bindLong(index, (byte) value);
				break;
			case SHORT:
				statement.bindLong(index, (short) value);
				break;
			case INTEGER:
				statement.bindLong(index, (int) value);
				break;
			case CHARACTER:
				statement.bindLong(index, Character.getNumericValue((char)value));
				break;
			case LONG:
				statement.bindLong(index, (long) value);
				break;
			case BYTE_ARRAY:
				statement.bindBlob(index, (byte[]) value);
				break;
			case FLOAT:
				statement.bindDouble(index, (float) value);
				break;
			case DOUBLE:
				statement.bindDouble(index, (double) value);
				break;
			case NULL:
				statement.bindNull(index);
				break;
			case STRING:
				statement.bindString(index, (String) value);
				break;
			}
			index++;
		}

		for (int i = 0; i < whereArgs.size(); i++, index++) {
			statement.bindString(index, whereArgs.get(i));
		}
	}
1182181
private String readComment(boolean returnText) throws IOException, KriptonRuntimeException {
		read(START_COMMENT);

		if (relaxed) {
			return readUntil(END_COMMENT, returnText);
		}

		String commentText = readUntil(COMMENT_DOUBLE_DASH, returnText);
		if (peekCharacter() != '>') {
			throw new KriptonRuntimeException("Comments may not contain --", true, this.getLineNumber(), this.getColumnNumber(), getPositionDescription(), null);
		}
		position++;
		return commentText;
	}
16958
private String formatWithStatementLocation(String format, StatementInfo statementInfo, Object... args) {
        return format(format, args) + format(" [%s:%s]", statementInfo.getSourceFileName(), statementInfo.getLineNumber());
    }
309536
public final hqlParser.statement_return statement() throws RecognitionException {
		hqlParser.statement_return retval = new hqlParser.statement_return();
		retval.start = input.LT(1);

		CommonTree root_0 = null;

		Token EOF5=null;
		ParserRuleReturnScope updateStatement1 =null;
		ParserRuleReturnScope deleteStatement2 =null;
		ParserRuleReturnScope selectStatement3 =null;
		ParserRuleReturnScope insertStatement4 =null;

		CommonTree EOF5_tree=null;

		try {
			// hql.g:161:2: ( ( updateStatement | deleteStatement | selectStatement | insertStatement ) EOF !)
			// hql.g:161:4: ( updateStatement | deleteStatement | selectStatement | insertStatement ) EOF !
			{
			root_0 = (CommonTree)adaptor.nil();


			// hql.g:161:4: ( updateStatement | deleteStatement | selectStatement | insertStatement )
			int alt1=4;
			switch ( input.LA(1) ) {
			case UPDATE:
				{
				alt1=1;
				}
				break;
			case DELETE:
				{
				alt1=2;
				}
				break;
			case EOF:
			case CLOSE:
			case FROM:
			case GROUP:
			case HAVING:
			case ORDER:
			case SELECT:
			case SKIP:
			case TAKE:
			case UNION:
			case WHERE:
				{
				alt1=3;
				}
				break;
			case INSERT:
				{
				alt1=4;
				}
				break;
			default:
				NoViableAltException nvae =
					new NoViableAltException("", 1, 0, input);
				throw nvae;
			}
			switch (alt1) {
				case 1 :
					// hql.g:161:6: updateStatement
					{
					pushFollow(FOLLOW_updateStatement_in_statement599);
					updateStatement1=updateStatement();
					state._fsp--;

					adaptor.addChild(root_0, updateStatement1.getTree());

					}
					break;
				case 2 :
					// hql.g:161:24: deleteStatement
					{
					pushFollow(FOLLOW_deleteStatement_in_statement603);
					deleteStatement2=deleteStatement();
					state._fsp--;

					adaptor.addChild(root_0, deleteStatement2.getTree());

					}
					break;
				case 3 :
					// hql.g:161:42: selectStatement
					{
					pushFollow(FOLLOW_selectStatement_in_statement607);
					selectStatement3=selectStatement();
					state._fsp--;

					adaptor.addChild(root_0, selectStatement3.getTree());

					}
					break;
				case 4 :
					// hql.g:161:60: insertStatement
					{
					pushFollow(FOLLOW_insertStatement_in_statement611);
					insertStatement4=insertStatement();
					state._fsp--;

					adaptor.addChild(root_0, insertStatement4.getTree());

					}
					break;

			}

			EOF5=(Token)match(input,EOF,FOLLOW_EOF_in_statement615);
			}

			retval.stop = input.LT(-1);

			retval.tree = (CommonTree)adaptor.rulePostProcessing(root_0);
			adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop);

		}
		catch (RecognitionException re) {
			reportError(re);
			recover(input,re);
			retval.tree = (CommonTree)adaptor.errorNode(input, retval.start, input.LT(-1), re);
		}
		finally {
			// do for sure before leaving
		}
		return retval;
	}
274663
private void executeAssumeStatement(Tree statement)
    {
        if (!CliMain.isConnected() || !hasKeySpace())
            return;

        String cfName = CliCompiler.getColumnFamily(statement, currentCfDefs());

        // VALIDATOR | COMPARATOR | KEYS | SUB_COMPARATOR
        String assumptionElement = statement.getChild(1).getText().toUpperCase();


        // Could be UTF8Type, IntegerType, LexicalUUIDType etc.
        String defaultType = CliUtils.unescapeSQLString(statement.getChild(2).getText());

        if (applyAssumption(cfName, assumptionElement, defaultType))
        {
            assumptions.addAssumption(keySpace, cfName, assumptionElement, defaultType);
            sessionState.out.println(String.format("Assumption for column family '%s' added successfully.", cfName));
        }
    }
1266813
public void statementGuaranteesDeterminism(boolean hasLimitOrOffset,
                                               boolean order,
                                               String contentDeterminismDetail) {
        m_statementHasLimitOrOffset = hasLimitOrOffset;
        m_statementIsOrderDeterministic = order;
        if (contentDeterminismDetail != null) {
            m_contentDeterminismDetail = contentDeterminismDetail;
        }
    }
1140164
function serializeStatements (statements) {
  var source = statements.map(function (st) { return st.toNT() })
  source = source.join('\n')
  return source
}
1252262
public static String parseExplainViewCall(String statement)
    {
        Matcher matcher = ExplainViewCallPreamble.matcher(statement);
        if ( ! matcher.lookingAt()) {
            return null;
        }
        // This all could probably be done more elegantly via a group extracted
        // from a more comprehensive regexp.
        // Clean up any extra spaces around the remainder of the line,
        // which should be a view name.
        return statement.substring(matcher.end()).trim();
    }
17908
private String readComment() {
    if (pos == data.length || data[pos] != '/') throw new AssertionError();
    pos++;
    int commentType = pos < data.length ? data[pos++] : -1;
    if (commentType == '*') {
      StringBuilder result = new StringBuilder();
      boolean startOfLine = true;

      for (; pos + 1 < data.length; pos++) {
        char c = data[pos];
        if (c == '*' && data[pos + 1] == '/') {
          pos += 2;
          return result.toString().trim();
        }
        if (c == '\n') {
          result.append('\n');
          newline();
          startOfLine = true;
        } else if (!startOfLine) {
          result.append(c);
        } else if (c == '*') {
          if (data[pos + 1] == ' ') {
            pos += 1; // Skip a single leading space, if present.
          }
          startOfLine = false;
        } else if (!Character.isWhitespace(c)) {
          result.append(c);
          startOfLine = false;
        }
      }
      throw unexpected("unterminated comment");
    } else if (commentType == '/') {
      if (pos < data.length && data[pos] == ' ') {
        pos += 1; // Skip a single leading space, if present.
      }
      int start = pos;
      while (pos < data.length) {
        char c = data[pos++];
        if (c == '\n') {
          newline();
          break;
        }
      }
      return new String(data, start, pos - 1 - start);
    } else {
      throw unexpected("unexpected '/'");
    }
  }