(
String path, ImmutableList.Builder<String> out)
| 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() { |
no test coverage detected