code: private void appendEncoded(StringBuilder builder, String s, Charset charset,
              boolean isPartiallyEncoded) {
          if (s == null) {
              throw new NullPointerException("s == null");
          }
  
          int escapeStart = -1;
          for (int i = 0; i < s.length(); i++) {
              char c = s.charAt(i);
              if ((c >= 'a' && c <= 'z')
                      || (c >= 'A' && c <= 'Z')
                      || (c >= '0' && c <= '9')
                      || isRetained(c)
                      || (c == '%' && isPartiallyEncoded)) {
                  if (escapeStart != -1) {
                      appendHex(builder, s.substring(escapeStart, i), charset);
                      escapeStart = -1;
                  }
                  if (c == '%' && isPartiallyEncoded) {
                      // this is an encoded 3-character sequence like "%20"
                      builder.append(s, i, Math.min(i + 3, s.length()));
                      i += 2;
                  } else if (c == ' ') {
                      builder.append('+');
                  } else {
                      builder.append(c);
                  }
              } else if (escapeStart == -1) {
                  escapeStart = i;
              }
          }
          if (escapeStart != -1) {
              appendHex(builder, s.substring(escapeStart, s.length()), charset);
          }
      }
docs: Encodes {@code s} and appends the result to {@code builder}.
  
  @param isPartiallyEncoded true to fix input that has already been
  partially or fully encoded. For example, input of "hello%20world" is
  unchanged with isPartiallyEncoded=true but would be double-escaped to
  "hello%2520world" otherwise.