|
23 | 23 | #include <string> |
24 | 24 | #include <string_view> |
25 | 25 |
|
| 26 | +#include "absl/status/status.h" |
26 | 27 | #include "absl/strings/ascii.h" |
27 | 28 | #include "absl/strings/match.h" |
28 | 29 | #include "tensorstore/internal/ascii_set.h" |
@@ -87,17 +88,18 @@ void PercentDecodeAppend(std::string_view src, std::string& dest) { |
87 | 88 | } |
88 | 89 | } |
89 | 90 |
|
90 | | -ParsedGenericUri ParseGenericUri(std::string_view uri) { |
91 | | - static constexpr std::string_view kSchemeSep("://"); |
| 91 | +namespace { |
| 92 | +ParsedGenericUri ParseGenericUriImpl(std::string_view uri, |
| 93 | + std::string_view scheme_delimiter) { |
92 | 94 | ParsedGenericUri result; |
93 | | - const auto scheme_start = uri.find(kSchemeSep); |
| 95 | + const auto scheme_start = uri.find(scheme_delimiter); |
94 | 96 | std::string_view uri_suffix; |
95 | 97 | if (scheme_start == std::string_view::npos) { |
96 | 98 | // No scheme |
97 | 99 | uri_suffix = uri; |
98 | 100 | } else { |
99 | 101 | result.scheme = uri.substr(0, scheme_start); |
100 | | - uri_suffix = uri.substr(scheme_start + kSchemeSep.size()); |
| 102 | + uri_suffix = uri.substr(scheme_start + scheme_delimiter.size()); |
101 | 103 | } |
102 | 104 | const auto fragment_start = uri_suffix.find('#'); |
103 | 105 | const auto query_start = uri_suffix.substr(0, fragment_start).find('?'); |
@@ -127,6 +129,32 @@ ParsedGenericUri ParseGenericUri(std::string_view uri) { |
127 | 129 | } |
128 | 130 | return result; |
129 | 131 | } |
| 132 | +} // namespace |
| 133 | + |
| 134 | +ParsedGenericUri ParseGenericUri(std::string_view uri) { |
| 135 | + return ParseGenericUriImpl(uri, "://"); |
| 136 | +} |
| 137 | + |
| 138 | +ParsedGenericUri ParseGenericUriWithoutSlashSlash(std::string_view uri) { |
| 139 | + return ParseGenericUriImpl(uri, ":"); |
| 140 | +} |
| 141 | + |
| 142 | +absl::Status EnsureNoQueryOrFragment(const ParsedGenericUri& parsed_uri) { |
| 143 | + if (!parsed_uri.query.empty()) { |
| 144 | + return absl::InvalidArgumentError("Query string not supported"); |
| 145 | + } |
| 146 | + if (!parsed_uri.fragment.empty()) { |
| 147 | + return absl::InvalidArgumentError("Fragment identifier not supported"); |
| 148 | + } |
| 149 | + return absl::OkStatus(); |
| 150 | +} |
| 151 | + |
| 152 | +absl::Status EnsureNoPathOrQueryOrFragment(const ParsedGenericUri& parsed_uri) { |
| 153 | + if (!parsed_uri.authority_and_path.empty()) { |
| 154 | + return absl::InvalidArgumentError("Path not supported"); |
| 155 | + } |
| 156 | + return EnsureNoQueryOrFragment(parsed_uri); |
| 157 | +} |
130 | 158 |
|
131 | 159 | std::optional<HostPort> SplitHostPort(std::string_view host_port) { |
132 | 160 | if (host_port.empty()) return std::nullopt; |
|
0 commit comments