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

Function UriFromAbsolutePath

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

Source from the content-addressed store, hash-verified

324}
325
326Result<std::string> UriFromAbsolutePath(std::string_view path) {
327 if (path.empty()) {
328 return Status::Invalid(
329 "UriFromAbsolutePath expected an absolute path, got an empty string");
330 }
331 std::string out;
332#ifdef _WIN32
333 // Turn "/" separators into "\", as Windows recognizes both but uriparser
334 // only the latter.
335 std::string fixed_path(path);
336 std::replace(fixed_path.begin(), fixed_path.end(), '/', '\\');
337 out.resize(8 + 3 * fixed_path.length() + 1);
338 int r = uriWindowsFilenameToUriStringA(fixed_path.data(), out.data());
339 // uriWindowsFilenameToUriStringA basically only fails if a null pointer is given.
340 ARROW_CHECK_EQ(r, 0) << "uriWindowsFilenameToUriStringA unexpectedly failed";
341#else
342 // uriUnixFilenameToUriStringA scans its argument as a NUL-terminated C string,
343 // but a std::string_view is not required to be NUL-terminated. Copy into a
344 // std::string first (as the Windows branch above already does) so the routine
345 // cannot read past the end of the view.
346 std::string fixed_path(path);
347 out.resize(7 + 3 * fixed_path.length() + 1);
348 int r = uriUnixFilenameToUriStringA(fixed_path.data(), out.data());
349 // same as above (uriWindowsFilenameToUriStringA)
350 ARROW_CHECK_EQ(r, 0) << "uriUnixFilenameToUriStringA unexpectedly failed";
351#endif
352 out.resize(strlen(out.data()));
353 return out;
354}
355
356} // namespace arrow::util

Callers 2

localfs_test.ccFile · 0.85
TESTFunction · 0.85

Calls 7

resizeMethod · 0.80
InvalidFunction · 0.50
emptyMethod · 0.45
beginMethod · 0.45
endMethod · 0.45
lengthMethod · 0.45
dataMethod · 0.45

Tested by 1

TESTFunction · 0.68