MCPcopy Create free account
hub / github.com/grpc/grpc-java / parseAssumedUtf8PathIntoSegments

Method parseAssumedUtf8PathIntoSegments

api/src/main/java/io/grpc/Uri.java:303–333  ·  view source on GitHub ↗
(
      String path, ImmutableList.Builder<String> out)

Source from the content-addressed store, hash-verified

301
302 // Checks a raw path for validity and parses it into segments. Let 'out' be null to just validate.
303 private static void parseAssumedUtf8PathIntoSegments(
304 String path, ImmutableList.Builder<String> out) {
305 // Skip the first slash so it doesn't count as an empty segment at the start.
306 // (e.g., "/a" -> ["a"], not ["", "a"])
307 int start = path.startsWith("/") ? 1 : 0;
308
309 for (int i = start; i < path.length(); ) {
310 int nextSlash = path.indexOf('/', i);
311 String segment;
312 if (nextSlash >= 0) {
313 // Typical segment case (e.g., "foo" in "/foo/bar").
314 segment = path.substring(i, nextSlash);
315 i = nextSlash + 1;
316 } else {
317 // Final segment case (e.g., "bar" in "/foo/bar").
318 segment = path.substring(i);
319 i = path.length();
320 }
321 if (out != null) {
322 out.add(percentDecodeAssumedUtf8(segment));
323 } else {
324 checkPercentEncodedArg(segment, "path segment", pChars);
325 }
326 }
327
328 // RFC 3986 says a trailing slash creates a final empty segment.
329 // (e.g., "/foo/" -> ["foo", ""])
330 if (path.endsWith("/") && out != null) {
331 out.add("");
332 }
333 }
334
335 /** Returns the scheme of this URI. */
336 public String getScheme() {

Callers 2

getPathSegmentsMethod · 0.95
setRawPathMethod · 0.80

Calls 4

addMethod · 0.65
endsWithMethod · 0.45

Tested by

no test coverage detected