MCPcopy Index your code
hub / github.com/apache/tomcat / encodeURL

Method encodeURL

java/org/apache/tomcat/util/buf/UEncoder.java:85–125  ·  view source on GitHub ↗

URL Encode string, using a specified encoding. @param s string to be encoded @param start the beginning index, inclusive @param end the ending index, exclusive @return A new CharChunk contained the URL encoded string @throws IOException If an I/O error occurs

(String s, int start, int end)

Source from the content-addressed store, hash-verified

83 * @throws IOException If an I/O error occurs
84 */
85 public CharChunk encodeURL(String s, int start, int end) throws IOException {
86 if (c2b == null) {
87 bb = new ByteChunk(8); // small enough.
88 cb = new CharChunk(2); // small enough.
89 output = new CharChunk(64); // small enough.
90 c2b = new C2BConverter(StandardCharsets.UTF_8);
91 } else {
92 bb.recycle();
93 cb.recycle();
94 output.recycle();
95 }
96
97 for (int i = start; i < end; i++) {
98 char c = s.charAt(i);
99 if (safeChars.get(c)) {
100 output.append(c);
101 } else {
102 cb.append(c);
103 c2b.convert(cb, bb);
104
105 // "surrogate" - UTF is _not_ 16 bit, but 21 !!!!
106 // ( while UCS is 31 ). Amazing...
107 if (c >= 0xD800 && c <= 0xDBFF) {
108 if ((i + 1) < end) {
109 char d = s.charAt(i + 1);
110 if (d >= 0xDC00 && d <= 0xDFFF) {
111 cb.append(d);
112 c2b.convert(cb, bb);
113 i++;
114 }
115 }
116 }
117
118 urlEncode(output, bb);
119 cb.recycle();
120 bb.recycle();
121 }
122 }
123
124 return output;
125 }
126
127 private void urlEncode(CharChunk out, ByteChunk bb) throws IOException {
128 byte[] bytes = bb.getBuffer();

Callers 1

Calls 6

urlEncodeMethod · 0.95
charAtMethod · 0.80
recycleMethod · 0.65
getMethod · 0.65
appendMethod · 0.45
convertMethod · 0.45

Tested by 1