static int indexOfUnicodeEscape(@NotNull String text, int offset) {
    final int length = text.length();
    for (int i = 0; i < length; i++) {
      final char c = text.charAt(i);
      if (c != '\\') {
        continue;
      }
      boolean isEscape = true;
      int previousChar = i - 1;
      while (previousChar >= 0 && text.charAt(previousChar) == '\\') {
        isEscape = !isEscape;
        previousChar--;
      }
      if (!isEscape) {
        continue;
      }
      int nextChar = i;
      do {
        nextChar++;
        if (nextChar >= length) {
          break;
        }
      }
      while (text.charAt(nextChar) == 'u'); // \uuuuFFFD is a legal unicode escape
      if (nextChar == i + 1 || nextChar + 3 >= length) {
        break;
      }
      if (StringUtil.isHexDigit(text.charAt(nextChar)) &&
          StringUtil.isHexDigit(text.charAt(nextChar + 1)) &&
          StringUtil.isHexDigit(text.charAt(nextChar + 2)) &&
          StringUtil.isHexDigit(text.charAt(nextChar + 3))) {
        final int escapeEnd = nextChar + 4;
        if (offset <= escapeEnd) {
          final char d = (char)Integer.parseInt(text.substring(nextChar, nextChar + 4), 16);
          if (d == '\r') return -1; // carriage return not allowed
          return i;
        }
      }
    }
    return -1;
  }
static int indexOfUnicodeEscape(@NotNull String text, int offset)