@Test public void onlyScheme() { try { SplitUrl.split("http:"); } catch (IllegalArgumentException expected) { assertThat(expected.getMessage(), containsString("missing host")); } }
public static SplitUrl split(String url) { String trim = CodepointMatcher.ASCII_WHITESPACE.trim(url); if (trim.isEmpty()) { return SplitUrl.builder() .path("") .urlType(Type.PATH_RELATIVE) .build(); } Builder builder; if (CodepointMatcher.ALPHA.matches(trim.charAt(0))) { builder = fullUrlOrRelativePath(trim); } else if (slash.matches(trim.charAt(0))) { if (trim.length() == 2 && slash.matches(trim.charAt(1))) { return SplitUrl.builder() .urlType(Type.PROTOCOL_RELATIVE) .build(); } else if (trim.length() > 1 && slash.matches(trim.charAt(1))) { builder = authority(trim, 0).urlType(Type.PROTOCOL_RELATIVE); } else { builder = path(trim, 0).urlType(Type.PATH_ABSOLUTE); } } else if (trim.charAt(0) == '#') { builder = fragment(trim, 0).urlType(Type.FRAGMENT); } else { builder = path(trim, 0).urlType(Type.PATH_RELATIVE); } return builder.build(); }
SplitUrl { public static SplitUrl split(String url) { String trim = CodepointMatcher.ASCII_WHITESPACE.trim(url); if (trim.isEmpty()) { return SplitUrl.builder() .path("") .urlType(Type.PATH_RELATIVE) .build(); } Builder builder; if (CodepointMatcher.ALPHA.matches(trim.charAt(0))) { builder = fullUrlOrRelativePath(trim); } else if (slash.matches(trim.charAt(0))) { if (trim.length() == 2 && slash.matches(trim.charAt(1))) { return SplitUrl.builder() .urlType(Type.PROTOCOL_RELATIVE) .build(); } else if (trim.length() > 1 && slash.matches(trim.charAt(1))) { builder = authority(trim, 0).urlType(Type.PROTOCOL_RELATIVE); } else { builder = path(trim, 0).urlType(Type.PATH_ABSOLUTE); } } else if (trim.charAt(0) == '#') { builder = fragment(trim, 0).urlType(Type.FRAGMENT); } else { builder = path(trim, 0).urlType(Type.PATH_RELATIVE); } return builder.build(); } }
SplitUrl { public static SplitUrl split(String url) { String trim = CodepointMatcher.ASCII_WHITESPACE.trim(url); if (trim.isEmpty()) { return SplitUrl.builder() .path("") .urlType(Type.PATH_RELATIVE) .build(); } Builder builder; if (CodepointMatcher.ALPHA.matches(trim.charAt(0))) { builder = fullUrlOrRelativePath(trim); } else if (slash.matches(trim.charAt(0))) { if (trim.length() == 2 && slash.matches(trim.charAt(1))) { return SplitUrl.builder() .urlType(Type.PROTOCOL_RELATIVE) .build(); } else if (trim.length() > 1 && slash.matches(trim.charAt(1))) { builder = authority(trim, 0).urlType(Type.PROTOCOL_RELATIVE); } else { builder = path(trim, 0).urlType(Type.PATH_ABSOLUTE); } } else if (trim.charAt(0) == '#') { builder = fragment(trim, 0).urlType(Type.FRAGMENT); } else { builder = path(trim, 0).urlType(Type.PATH_RELATIVE); } return builder.build(); }  }
SplitUrl { public static SplitUrl split(String url) { String trim = CodepointMatcher.ASCII_WHITESPACE.trim(url); if (trim.isEmpty()) { return SplitUrl.builder() .path("") .urlType(Type.PATH_RELATIVE) .build(); } Builder builder; if (CodepointMatcher.ALPHA.matches(trim.charAt(0))) { builder = fullUrlOrRelativePath(trim); } else if (slash.matches(trim.charAt(0))) { if (trim.length() == 2 && slash.matches(trim.charAt(1))) { return SplitUrl.builder() .urlType(Type.PROTOCOL_RELATIVE) .build(); } else if (trim.length() > 1 && slash.matches(trim.charAt(1))) { builder = authority(trim, 0).urlType(Type.PROTOCOL_RELATIVE); } else { builder = path(trim, 0).urlType(Type.PATH_ABSOLUTE); } } else if (trim.charAt(0) == '#') { builder = fragment(trim, 0).urlType(Type.FRAGMENT); } else { builder = path(trim, 0).urlType(Type.PATH_RELATIVE); } return builder.build(); }  @Nullable abstract String scheme(); @Nullable abstract String authority(); @Nullable abstract String path(); @Nullable abstract String query(); @Nullable abstract String fragment(); @Nullable abstract Type urlType(); static SplitUrl split(String url); }
SplitUrl { public static SplitUrl split(String url) { String trim = CodepointMatcher.ASCII_WHITESPACE.trim(url); if (trim.isEmpty()) { return SplitUrl.builder() .path("") .urlType(Type.PATH_RELATIVE) .build(); } Builder builder; if (CodepointMatcher.ALPHA.matches(trim.charAt(0))) { builder = fullUrlOrRelativePath(trim); } else if (slash.matches(trim.charAt(0))) { if (trim.length() == 2 && slash.matches(trim.charAt(1))) { return SplitUrl.builder() .urlType(Type.PROTOCOL_RELATIVE) .build(); } else if (trim.length() > 1 && slash.matches(trim.charAt(1))) { builder = authority(trim, 0).urlType(Type.PROTOCOL_RELATIVE); } else { builder = path(trim, 0).urlType(Type.PATH_ABSOLUTE); } } else if (trim.charAt(0) == '#') { builder = fragment(trim, 0).urlType(Type.FRAGMENT); } else { builder = path(trim, 0).urlType(Type.PATH_RELATIVE); } return builder.build(); }  @Nullable abstract String scheme(); @Nullable abstract String authority(); @Nullable abstract String path(); @Nullable abstract String query(); @Nullable abstract String fragment(); @Nullable abstract Type urlType(); static SplitUrl split(String url);  }