findClosingQuote function

int findClosingQuote(
  1. String content,
  2. int start
)

Finds the index of the closing double quote in a string, accounting for escape sequences.

@param content The string to search in @param start The index of the opening quote @returns The index of the closing quote, or -1 if not found

Implementation

int findClosingQuote(String content, int start) {
  int i = start + 1;
  while (i < content.length) {
    if (content[i] == backslash && i + 1 < content.length) {
      // Skip escaped character
      i += 2;
      continue;
    }
    if (content[i] == doubleQuote) {
      return i;
    }
    i++;
  }
  return -1; // Not found
}