MCPcopy Index your code
hub / github.com/OpenFeign/feign / encodeInternal

Method encodeInternal

core/src/main/java/feign/template/UriUtils.java:111–141  ·  view source on GitHub ↗

Encodes the value, preserving all reserved characters.. Values that are already pct-encoded are ignored. @param value inspect. @param charset to use. @return a new String with the reserved characters preserved.

(
      String value, Charset charset, boolean allowReservedCharacters)

Source from the content-addressed store, hash-verified

109 * @return a new String with the reserved characters preserved.
110 */
111 public static String encodeInternal(
112 String value, Charset charset, boolean allowReservedCharacters) {
113 /* value is encoded, we need to split it up and skip the parts that are already encoded */
114 Matcher matcher = PCT_ENCODED_PATTERN.matcher(value);
115
116 if (!matcher.find()) {
117 return encodeChunk(value, charset, true);
118 }
119
120 int length = value.length();
121 StringBuilder encoded = new StringBuilder(length + 8);
122 int index = 0;
123 do {
124 /* split out the value before the encoded value */
125 String before = value.substring(index, matcher.start());
126
127 /* encode it */
128 encoded.append(encodeChunk(before, charset, allowReservedCharacters));
129
130 /* append the encoded value */
131 encoded.append(matcher.group());
132
133 /* update the string search index */
134 index = matcher.end();
135 } while (matcher.find());
136
137 /* append the rest of the string */
138 String tail = value.substring(index, length);
139 encoded.append(encodeChunk(tail, charset, allowReservedCharacters));
140 return encoded.toString();
141 }
142
143 /**
144 * Encode a Uri Chunk, ensuring that all reserved characters are also encoded.

Callers 1

encodeMethod · 0.95

Calls 4

encodeChunkMethod · 0.95
lengthMethod · 0.65
appendMethod · 0.45
toStringMethod · 0.45

Tested by

no test coverage detected