MCPcopy Create free account
hub / github.com/apache/arrow / Parse

Method Parse

cpp/src/arrow/util/uri.cc:248–318  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

246const std::string& Uri::ToString() const { return impl_->string_rep_; }
247
248Status Uri::Parse(const std::string& uri_string) {
249 impl_->Reset();
250
251 const auto& s = impl_->KeepString(uri_string);
252 impl_->string_rep_ = s;
253 const char* error_pos;
254 int retval =
255 uriParseSingleUriExA(&impl_->uri_, s.data(), s.data() + s.size(), &error_pos);
256 if (retval != URI_SUCCESS) {
257 if (retval == URI_ERROR_SYNTAX) {
258 return Status::Invalid("Cannot parse URI: '", uri_string,
259 "' due to syntax error at character '", *error_pos,
260 "' (position ", error_pos - s.data(), ")");
261 } else {
262 return Status::Invalid("Cannot parse URI: '", uri_string, "'");
263 }
264 }
265
266 const auto scheme = TextRangeToView(impl_->uri_.scheme);
267 if (scheme.empty()) {
268 return Status::Invalid("URI has empty scheme: '", uri_string, "'");
269 }
270 impl_->is_file_uri_ = (scheme == "file");
271
272 // Gather path segments
273 auto path_seg = impl_->uri_.pathHead;
274 while (path_seg != nullptr) {
275 impl_->path_segments_.push_back(TextRangeToView(path_seg->text));
276 path_seg = path_seg->next;
277 }
278
279 // Decide whether URI path is absolute
280 impl_->is_absolute_path_ = false;
281 if (impl_->uri_.absolutePath == URI_TRUE) {
282 impl_->is_absolute_path_ = true;
283 } else if (has_host() && impl_->path_segments_.size() > 0) {
284 // When there's a host (even empty), uriparser considers the path relative.
285 // Several URI parsers for Python all consider it absolute, though.
286 // For example, the path for "file:///tmp/foo" is "/tmp/foo", not "tmp/foo".
287 // Similarly, the path for "file://localhost/" is "/".
288 // However, the path for "file://localhost" is "".
289 impl_->is_absolute_path_ = true;
290 }
291#ifdef _WIN32
292 // There's an exception on Windows: "file:/C:foo/bar" is relative.
293 if (impl_->is_file_uri_ && impl_->path_segments_.size() > 0) {
294 const auto& first_seg = impl_->path_segments_[0];
295 if (IsDriveSpec(first_seg) && (first_seg.length() >= 3 && first_seg[2] != '/')) {
296 impl_->is_absolute_path_ = false;
297 }
298 }
299#endif
300
301 if (impl_->is_file_uri_ && !impl_->is_absolute_path_) {
302 return Status::Invalid("File URI cannot be relative: '", uri_string, "'");
303 }
304
305 // Parse port number

Callers 7

ARROW_ASSIGN_OR_RAISEFunction · 0.45
ReadArrayDataFunction · 0.45
TestRleBitPackedParserFunction · 0.45
FromStringMethod · 0.45
TESTFunction · 0.45
TESTFunction · 0.45

Calls 10

TextRangeToViewFunction · 0.85
IsDriveSpecFunction · 0.85
push_backMethod · 0.80
InvalidFunction · 0.50
OKFunction · 0.50
ResetMethod · 0.45
dataMethod · 0.45
sizeMethod · 0.45
emptyMethod · 0.45
lengthMethod · 0.45

Tested by 4

TestRleBitPackedParserFunction · 0.36
TESTFunction · 0.36
TESTFunction · 0.36