Advertisement
Guest User

Untitled

a guest
Oct 15th, 2019
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.47 KB | None | 0 0
  1. public ParseResult parse(@Nullable HttpUrl httpUrl, String str) {
  2. int i;
  3. int delimiterOffset;
  4. int i2;
  5. HttpUrl httpUrl2 = httpUrl;
  6. String str2 = str;
  7. int skipLeadingAsciiWhitespace = Util.skipLeadingAsciiWhitespace(str2, 0, str.length());
  8. int skipTrailingAsciiWhitespace = Util.skipTrailingAsciiWhitespace(str2, skipLeadingAsciiWhitespace, str.length());
  9. if (schemeDelimiterOffset(str2, skipLeadingAsciiWhitespace, skipTrailingAsciiWhitespace) != -1) {
  10. if (str.regionMatches(true, skipLeadingAsciiWhitespace, "https:", 0, 6)) {
  11. this.scheme = "https";
  12. skipLeadingAsciiWhitespace += "https:".length();
  13. } else {
  14. if (!str.regionMatches(true, skipLeadingAsciiWhitespace, "http:", 0, 5)) {
  15. return ParseResult.UNSUPPORTED_SCHEME;
  16. }
  17. this.scheme = "http";
  18. skipLeadingAsciiWhitespace += "http:".length();
  19. }
  20. } else if (httpUrl2 == null) {
  21. return ParseResult.MISSING_SCHEME;
  22. } else {
  23. this.scheme = httpUrl2.scheme;
  24. }
  25. int slashCount = slashCount(str2, skipLeadingAsciiWhitespace, skipTrailingAsciiWhitespace);
  26. char c = '#';
  27. if (slashCount >= 2 || httpUrl2 == null || !httpUrl2.scheme.equals(this.scheme)) {
  28. int i3 = skipLeadingAsciiWhitespace + slashCount;
  29. boolean z = false;
  30. boolean z2 = false;
  31. while (true) {
  32. delimiterOffset = Util.delimiterOffset(str2, i3, skipTrailingAsciiWhitespace, "@/\\?#");
  33. char charAt = delimiterOffset != skipTrailingAsciiWhitespace ? str2.charAt(delimiterOffset) : 65535;
  34. if (!(charAt == 65535 || charAt == c || charAt == '/' || charAt == '\\')) {
  35. switch (charAt) {
  36. case '?':
  37. break;
  38. case '@':
  39. if (!z) {
  40. int delimiterOffset2 = Util.delimiterOffset(str2, i3, delimiterOffset, ':');
  41. int i4 = delimiterOffset2;
  42. i2 = delimiterOffset;
  43. String canonicalize = HttpUrl.canonicalize(str, i3, delimiterOffset2, " \"':;<=>@[]^`{}|/\\?#", true, false, false, true, null);
  44. if (z2) {
  45. StringBuilder sb = new StringBuilder();
  46. sb.append(this.encodedUsername);
  47. sb.append("%40");
  48. sb.append(canonicalize);
  49. canonicalize = sb.toString();
  50. }
  51. this.encodedUsername = canonicalize;
  52. if (i4 != i2) {
  53. this.encodedPassword = HttpUrl.canonicalize(str, i4 + 1, i2, " \"':;<=>@[]^`{}|/\\?#", true, false, false, true, null);
  54. z = true;
  55. }
  56. z2 = true;
  57. } else {
  58. i2 = delimiterOffset;
  59. StringBuilder sb2 = new StringBuilder();
  60. sb2.append(this.encodedPassword);
  61. sb2.append("%40");
  62. sb2.append(HttpUrl.canonicalize(str, i3, i2, " \"':;<=>@[]^`{}|/\\?#", true, false, false, true, null));
  63. this.encodedPassword = sb2.toString();
  64. }
  65. i3 = i2 + 1;
  66. continue;
  67. }
  68. }
  69. c = '#';
  70. }
  71. i = delimiterOffset;
  72. int portColonOffset = portColonOffset(str2, i3, i);
  73. int i5 = portColonOffset + 1;
  74. if (i5 < i) {
  75. this.host = canonicalizeHost(str2, i3, portColonOffset);
  76. this.port = parsePort(str2, i5, i);
  77. if (this.port == -1) {
  78. return ParseResult.INVALID_PORT;
  79. }
  80. } else {
  81. this.host = canonicalizeHost(str2, i3, portColonOffset);
  82. this.port = HttpUrl.defaultPort(this.scheme);
  83. }
  84. if (this.host == null) {
  85. return ParseResult.INVALID_HOST;
  86. }
  87. } else {
  88. this.encodedUsername = httpUrl.encodedUsername();
  89. this.encodedPassword = httpUrl.encodedPassword();
  90. this.host = httpUrl2.host;
  91. this.port = httpUrl2.port;
  92. this.encodedPathSegments.clear();
  93. this.encodedPathSegments.addAll(httpUrl.encodedPathSegments());
  94. if (skipLeadingAsciiWhitespace == skipTrailingAsciiWhitespace || str2.charAt(skipLeadingAsciiWhitespace) == '#') {
  95. encodedQuery(httpUrl.encodedQuery());
  96. }
  97. i = skipLeadingAsciiWhitespace;
  98. }
  99. int delimiterOffset3 = Util.delimiterOffset(str2, i, skipTrailingAsciiWhitespace, "?#");
  100. resolvePath(str2, i, delimiterOffset3);
  101. if (delimiterOffset3 < skipTrailingAsciiWhitespace && str2.charAt(delimiterOffset3) == '?') {
  102. int delimiterOffset4 = Util.delimiterOffset(str2, delimiterOffset3, skipTrailingAsciiWhitespace, '#');
  103. this.encodedQueryNamesAndValues = HttpUrl.queryStringToNamesAndValues(HttpUrl.canonicalize(str, delimiterOffset3 + 1, delimiterOffset4, HttpUrl.QUERY_ENCODE_SET, true, false, true, true, null));
  104. delimiterOffset3 = delimiterOffset4;
  105. }
  106. if (delimiterOffset3 < skipTrailingAsciiWhitespace && str2.charAt(delimiterOffset3) == '#') {
  107. this.encodedFragment = HttpUrl.canonicalize(str, 1 + delimiterOffset3, skipTrailingAsciiWhitespace, "", true, false, false, false, null);
  108. }
  109. return ParseResult.SUCCESS;
  110. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement