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

Class ChunkTokenizer

core/src/main/java/feign/template/Template.java:261–330  ·  view source on GitHub ↗

Splits a Uri into Chunks that exists inside and outside of an expression, delimited by curly braces "{}". Nested expressions are treated as literals, for example "foo{bar{baz}}" will be treated as "foo, {bar{baz}}". Inspired by Apache CXF Jax-RS.

Source from the content-addressed store, hash-verified

259 * treated as "foo, {bar{baz}}". Inspired by Apache CXF Jax-RS.
260 */
261 static class ChunkTokenizer {
262
263 private List<String> tokens = new ArrayList<>();
264 private int index;
265
266 ChunkTokenizer(String template) {
267 boolean outside = true;
268 int level = 0;
269 int lastIndex = 0;
270 int idx;
271
272 /* loop through the template, character by character */
273 for (idx = 0; idx < template.length(); idx++) {
274 if (template.charAt(idx) == '{') {
275 /* start of an expression */
276 if (outside) {
277 /* outside of an expression */
278 if (lastIndex < idx) {
279 /* this is the start of a new token */
280 tokens.add(template.substring(lastIndex, idx));
281 }
282 lastIndex = idx;
283
284 /*
285 * no longer outside of an expression, additional characters will be treated as in an
286 * expression
287 */
288 outside = false;
289 } else {
290 /* nested braces, increase our nesting level */
291 level++;
292 }
293 } else if (template.charAt(idx) == '}' && !outside) {
294 /* the end of an expression */
295 if (level > 0) {
296 /*
297 * sometimes we see nested expressions, we only want the outer most expression
298 * boundaries.
299 */
300 level--;
301 } else {
302 /* outermost boundary */
303 if (lastIndex < idx) {
304 /* this is the end of an expression token */
305 tokens.add(template.substring(lastIndex, idx + 1));
306 }
307 lastIndex = idx + 1;
308
309 /* outside an expression */
310 outside = true;
311 }
312 }
313 }
314 if (lastIndex < idx) {
315 /* grab the remaining chunk */
316 tokens.add(template.substring(lastIndex, idx));
317 }
318 }

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected