code: static int nextBraceFormatTerm(String message, int pos) throws ParseException {
      // We can assume that we start in unquoted mode.
      while (pos < message.length()) {
        char c = message.charAt(pos++);
        if (c == '{') {
          // We found an unquoted open bracket. Hurrah!
          return pos - 1;
        }
        if (c != '\'') {
          // Non-special char (common case) means continue.
          continue;
        }
        if (pos == message.length()) {
          throw ParseException.withStartPosition("trailing single quote", message, pos - 1);
        }
        if (message.charAt(pos++) == '\'') {
          // A doubled single-quote means continue as normal.
          continue;
        }
        // Quoted mode - just scan for terminating quote.
        int quote = pos - 2;
        do {
          // If we run out of string it was badly formatted (a non-terminating quote).
          if (pos == message.length()) {
            throw ParseException.withStartPosition("unmatched single quote", message, quote);
          }
        } while (message.charAt(pos++) != '\'');
        // The last character was consumed was a quote, so we are back in unquoted mode.
      }
      return -1;
    }
docs: VisibleForTesting