code: static int nextPrintfTerm(String message, int pos) throws ParseException {
      while (pos < message.length()) {
        if (message.charAt(pos++) != '%') {
          continue;
        }
        if (pos < message.length()) {
          char c = message.charAt(pos);
          if (c == '%' || c == 'n') {
            // We encountered '%%' or '%n', so keep going (these will be unescaped later).
            pos += 1;
            continue;
          }
          // We were pointing at the character after the '%', so adjust back by one.
          return pos - 1;
        }
        // We ran off the end while looking for the character after the first '%'.
        throw ParseException.withStartPosition("trailing unquoted '%' character", message, pos - 1);
      }
      // We never found another unescaped '%'.
      return -1;
    }
docs: VisibleForTesting