docs: public static SplitStmtResults splitStatements(final String sql) {
          List<String> statements = new ArrayList<>();
  
          // Use a character array for efficient character-at-a-time scanning.
          char[] buf = sql.toCharArray();
          // Set to null outside of quoted segments or the quote character inside them.
          Character cQuote = null;
          // Set to null outside of comments or to the string that ends the comment.
          String sCommentEnd = null;
          // Index to start of current statement.
          int iStart = 0;
          boolean statementIsComment = false;
          boolean inStatement = false;
          // To indicate if inside multi statement procedure
          boolean inBegin = false;
          // Set to true when we've processed an AS, as in
          // CREATE PROCEDURE <proc> AS BEGIN ... END
          boolean checkForNextBegin = false;
          // To indicate if inside CASE .. WHEN .. END
          int inCase = 0;
          // Index to current character.
          // IMPORTANT: The loop is structured in a way that requires all if/else/... blocks to bump
          // iCur appropriately. Failure of a corner case to bump iCur will cause an infinite loop.
          int iCur = 0;
          // A string builder for the current statment
          StringBuilder currentStmt = new StringBuilder();
          while (iCur < buf.length) {
              // Eat up whitespace outside of a statement
              if (!inStatement) {
                  if (Character.isWhitespace(buf[iCur])) {
                      iCur++;
                      iStart = iCur;
                  }
                  else {
                      inStatement = true;
                  }
              }
              else if (sCommentEnd != null) {
                  // Processing the interior of a comment.
                  if (matchesStringAtIndex(buf, iCur, sCommentEnd)) {
                      // Move past the comment end.
                      iCur += sCommentEnd.length();
                      // If the comment is the whole of the statement so far, do not add to output
                      if (statementIsComment) {
                          iStart = iCur;
                          statementIsComment = false;
                          inStatement = false;
                      }
  
                      // Put a single space for C-style comments, or a newline for -- comments
                      if (sCommentEnd.charAt(0) == '\n') {
                          currentStmt.append('\n');
                      }
                      else {
                          currentStmt.append(" ");
                      }
                      sCommentEnd = null;
  
                  } else {
                      // Keep going inside the comment.
                      iCur++;
                  }
              } else if (cQuote != null) {
                  // Processing the interior of a quoted string.
                  if (buf[iCur] == '\\') {
                      // Skip the '\' escape and the trailing single escaped character.
                      // Doesn't matter if iCur is beyond the end, it won't be used in that case.
                      currentStmt.append(buf[iCur]);
                      if (iCur + 1 < buf.length) {
                          currentStmt.append(buf[iCur + 1]);
                      }
                      iCur += 2;
                  } else if (buf[iCur] == cQuote) {
                      // Look at the next character to distinguish a double escaped quote
                      // from the end of the quoted string.
                      currentStmt.append(buf[iCur]);
                      iCur++;
                      if (iCur < buf.length) {
                          if (buf[iCur] != cQuote) {
                              // Not a double escaped quote - end of quoted string.
                              cQuote = null;
                          } else {
                              // Move past the double escaped quote.
                              currentStmt.append(buf[iCur]);
                              iCur++;
                          }
                      }
                  } else {
                      // Move past an ordinary character.
                      currentStmt.append(buf[iCur]);
                      iCur++;
                  }
              } else {
                  // Outside of a quoted string or comment - watch for the next separator, quote or comment.
  
                  // 'BEGIN' should only follow 'AS'
                  if (checkForNextBegin && matchTokenFast(buf, iCur, "begin") ) {
                      // 'BEGIN' should only be followed after 'AS'
                      // otherwise it is a column or table name
                      inBegin = true;
                      currentStmt.append(sql.substring(iCur, iCur + 5));
                      iCur += 5;
                  }
                  else if (matchTokenFast(buf, iCur, "case") ) {
                      checkForNextBegin = false;
                      inCase++;
                      currentStmt.append(sql.substring(iCur, iCur + 4));
                      iCur += 4;
                  }
                  else if (matchTokenFast(buf, iCur, "as") ) {
                      checkForNextBegin = true;
                      currentStmt.append(sql.substring(iCur, iCur + 2));
                      iCur += 2;
                  }
                  else if (! inBegin && buf[iCur] == ';') {
                      // Add terminated statement (if not empty after trimming).
                      // if it is not in a AS BEGIN ... END
                      if (currentStmt.length() > 0) {
                          statements.add(currentStmt.toString().trim());
                      }
                      currentStmt = new StringBuilder();
                      iCur++;
                      iStart = iCur;
                      inStatement = false;
                      inBegin = false;
                      inCase = 0;
                      checkForNextBegin = false;
                  }
                  else if (buf[iCur] == '"' || buf[iCur] == '\'') {
                      checkForNextBegin = false;
                      // Start of quoted string.
                      cQuote = buf[iCur];
                      currentStmt.append(buf[iCur]);
                      iCur++;
                  }
                  else if ( matchToken(sql, iCur, "end") ) {
                      checkForNextBegin = false;
                      if (inCase > 0) {
                          inCase--;
                      } else {
                          // we can terminate AS BEGIN ... END for multi stmt proc
                          // after all CASE ... END stmts are completed
                          inBegin = false;
                      }
                      currentStmt.append(sql.substring(iCur, iCur + 3));
                      iCur += 3;
                  }
                  else if (matchesStringAtIndex(buf, iCur, "/*")) {
                      // Multi-line C-style comment start.
                      sCommentEnd = "*/";
                      if (iCur == iStart) {
                          statementIsComment = true;
                      }
                      iCur += 2;
  
                  }
                  else if (matchesStringAtIndex(buf, iCur, "--")) {
                      // Single-line comment start (--)
                      sCommentEnd = "\n";
                      if (iCur == iStart) {
                          statementIsComment = true;
                      }
                      iCur += 2;
                  }
                  else {
                      // Move past a non-quote/non-separator character.
                      if (! Character.isWhitespace(buf[iCur])) {
                          checkForNextBegin = false;
                      }
  
                      currentStmt.append(buf[iCur]);
                      iCur++;
                  }
              }
          }
  
          // Get the last statement, if any.
          // we are still processing a multi-statement procedure if we are still in begin...end
          String incompleteStmt = null;
          int incompleteStmtOffset = -1;
          if (iStart < buf.length && !statementIsComment) {
              if (!inBegin) {
                  String statement = currentStmt.toString().trim();
                  if (!statement.isEmpty()) {
                      statements.add(statement);
                  }
              } else {
                  // we only check for incomplete multi statement procedures right now
                  // add a mandatory space..
                  incompleteStmtOffset = iStart;
                  incompleteStmt = String.copyValueOf(buf, iStart, iCur - iStart);
              }
          }
  
          return new SplitStmtResults(statements, incompleteStmt, incompleteStmtOffset);
      }