core/src/main/java/com/orientechnologies/common/parser/OStringParser.java
public static int indexOfOutsideStrings(final String iText, final char iToFind, int iFrom, int iTo) {
    if (iTo == -1)
      iTo = iText.length() - 1;
    if (iFrom == -1)
      iFrom = iText.length() - 1;

    char c;
    char stringChar = ' ';
    boolean escape = false;

    final StringBuilder buffer = new StringBuilder(1024);

    int i = iFrom;
    while (true) {
      c = iText.charAt(i);

      if (!escape && c == '\\' && ((i + 1) < iText.length())) {
        if (iText.charAt(i + 1) == 'u') {
          i = readUnicode(iText, i + 2, buffer);
        } else
          escape = true;
      } else {
        if (c == '\'' || c == '"') {
          // BEGIN/END STRING
          if (stringChar == ' ') {
            // BEGIN
            stringChar = c;
          } else {
            // END
            if (!escape && c == stringChar)
              stringChar = ' ';
          }
        }

        if (c == iToFind && stringChar == ' ')
          return i;

        if (escape)
          escape = false;
      }

      if (iFrom < iTo) {
        // MOVE FORWARD
        if (++i > iTo)
          break;
      } else {
        // MOVE BACKWARD
        if (--i < iFrom)
          break;
      }
    }
    return -1;
  }
public static int indexOfOutsideStrings(final String iText, final char iToFind, int iFrom, int iTo) {
    if (iTo == -1)
      iTo = iText.length() - 1;
    if (iFrom == -1)
      iFrom = iText.length() - 1;

    char c;
    char stringChar = ' ';
    boolean escape = false;

    final StringBuilder buffer = new StringBuilder(1024);

    int i = iFrom;
    while (true) {
      c = iText.charAt(i);

      if (!escape && c == '\\' && ((i + 1) < iText.length())) {
        if (iText.charAt(i + 1) == 'u') {
          i = readUnicode(iText, i + 2, buffer);
        } else
          escape = true;
      } else {
        if (c == '\'' || c == '"') {
          // BEGIN/END STRING
          if (stringChar == ' ') {
            // BEGIN
            stringChar = c;
          } else {
            // END
            if (!escape && c == stringChar)
              stringChar = ' ';
          }
        }

        if (c == iToFind && stringChar == ' ')
          return i;

        if (escape)
          escape = false;
      }

      if (iFrom < iTo) {
        // MOVE FORWARD
        if (++i > iTo)
          break;
      } else {
        // MOVE BACKWARD
        if (--i < iFrom)
          break;
      }
    }
    return -1;
  }
Finds a character inside a string specyfing the limits and direction. If iFrom is minor than iTo, then it moves forward,
otherwise backward.