Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public ParseResult parse(@Nullable HttpUrl httpUrl, String str) {
- int i;
- int delimiterOffset;
- int i2;
- HttpUrl httpUrl2 = httpUrl;
- String str2 = str;
- int skipLeadingAsciiWhitespace = Util.skipLeadingAsciiWhitespace(str2, 0, str.length());
- int skipTrailingAsciiWhitespace = Util.skipTrailingAsciiWhitespace(str2, skipLeadingAsciiWhitespace, str.length());
- if (schemeDelimiterOffset(str2, skipLeadingAsciiWhitespace, skipTrailingAsciiWhitespace) != -1) {
- if (str.regionMatches(true, skipLeadingAsciiWhitespace, "https:", 0, 6)) {
- this.scheme = "https";
- skipLeadingAsciiWhitespace += "https:".length();
- } else {
- if (!str.regionMatches(true, skipLeadingAsciiWhitespace, "http:", 0, 5)) {
- return ParseResult.UNSUPPORTED_SCHEME;
- }
- this.scheme = "http";
- skipLeadingAsciiWhitespace += "http:".length();
- }
- } else if (httpUrl2 == null) {
- return ParseResult.MISSING_SCHEME;
- } else {
- this.scheme = httpUrl2.scheme;
- }
- int slashCount = slashCount(str2, skipLeadingAsciiWhitespace, skipTrailingAsciiWhitespace);
- char c = '#';
- if (slashCount >= 2 || httpUrl2 == null || !httpUrl2.scheme.equals(this.scheme)) {
- int i3 = skipLeadingAsciiWhitespace + slashCount;
- boolean z = false;
- boolean z2 = false;
- while (true) {
- delimiterOffset = Util.delimiterOffset(str2, i3, skipTrailingAsciiWhitespace, "@/\\?#");
- char charAt = delimiterOffset != skipTrailingAsciiWhitespace ? str2.charAt(delimiterOffset) : 65535;
- if (!(charAt == 65535 || charAt == c || charAt == '/' || charAt == '\\')) {
- switch (charAt) {
- case '?':
- break;
- case '@':
- if (!z) {
- int delimiterOffset2 = Util.delimiterOffset(str2, i3, delimiterOffset, ':');
- int i4 = delimiterOffset2;
- i2 = delimiterOffset;
- String canonicalize = HttpUrl.canonicalize(str, i3, delimiterOffset2, " \"':;<=>@[]^`{}|/\\?#", true, false, false, true, null);
- if (z2) {
- StringBuilder sb = new StringBuilder();
- sb.append(this.encodedUsername);
- sb.append("%40");
- sb.append(canonicalize);
- canonicalize = sb.toString();
- }
- this.encodedUsername = canonicalize;
- if (i4 != i2) {
- this.encodedPassword = HttpUrl.canonicalize(str, i4 + 1, i2, " \"':;<=>@[]^`{}|/\\?#", true, false, false, true, null);
- z = true;
- }
- z2 = true;
- } else {
- i2 = delimiterOffset;
- StringBuilder sb2 = new StringBuilder();
- sb2.append(this.encodedPassword);
- sb2.append("%40");
- sb2.append(HttpUrl.canonicalize(str, i3, i2, " \"':;<=>@[]^`{}|/\\?#", true, false, false, true, null));
- this.encodedPassword = sb2.toString();
- }
- i3 = i2 + 1;
- continue;
- }
- }
- c = '#';
- }
- i = delimiterOffset;
- int portColonOffset = portColonOffset(str2, i3, i);
- int i5 = portColonOffset + 1;
- if (i5 < i) {
- this.host = canonicalizeHost(str2, i3, portColonOffset);
- this.port = parsePort(str2, i5, i);
- if (this.port == -1) {
- return ParseResult.INVALID_PORT;
- }
- } else {
- this.host = canonicalizeHost(str2, i3, portColonOffset);
- this.port = HttpUrl.defaultPort(this.scheme);
- }
- if (this.host == null) {
- return ParseResult.INVALID_HOST;
- }
- } else {
- this.encodedUsername = httpUrl.encodedUsername();
- this.encodedPassword = httpUrl.encodedPassword();
- this.host = httpUrl2.host;
- this.port = httpUrl2.port;
- this.encodedPathSegments.clear();
- this.encodedPathSegments.addAll(httpUrl.encodedPathSegments());
- if (skipLeadingAsciiWhitespace == skipTrailingAsciiWhitespace || str2.charAt(skipLeadingAsciiWhitespace) == '#') {
- encodedQuery(httpUrl.encodedQuery());
- }
- i = skipLeadingAsciiWhitespace;
- }
- int delimiterOffset3 = Util.delimiterOffset(str2, i, skipTrailingAsciiWhitespace, "?#");
- resolvePath(str2, i, delimiterOffset3);
- if (delimiterOffset3 < skipTrailingAsciiWhitespace && str2.charAt(delimiterOffset3) == '?') {
- int delimiterOffset4 = Util.delimiterOffset(str2, delimiterOffset3, skipTrailingAsciiWhitespace, '#');
- this.encodedQueryNamesAndValues = HttpUrl.queryStringToNamesAndValues(HttpUrl.canonicalize(str, delimiterOffset3 + 1, delimiterOffset4, HttpUrl.QUERY_ENCODE_SET, true, false, true, true, null));
- delimiterOffset3 = delimiterOffset4;
- }
- if (delimiterOffset3 < skipTrailingAsciiWhitespace && str2.charAt(delimiterOffset3) == '#') {
- this.encodedFragment = HttpUrl.canonicalize(str, 1 + delimiterOffset3, skipTrailingAsciiWhitespace, "", true, false, false, false, null);
- }
- return ParseResult.SUCCESS;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement