| 323 | } |
| 324 | |
| 325 | Result<std::string> UriFromAbsolutePath(std::string_view path) { |
| 326 | if (path.empty()) { |
| 327 | return Status::Invalid( |
| 328 | "UriFromAbsolutePath expected an absolute path, got an empty string"); |
| 329 | } |
| 330 | std::string out; |
| 331 | #ifdef _WIN32 |
| 332 | // Turn "/" separators into "\", as Windows recognizes both but uriparser |
| 333 | // only the latter. |
| 334 | std::string fixed_path(path); |
| 335 | std::replace(fixed_path.begin(), fixed_path.end(), '/', '\\'); |
| 336 | out.resize(8 + 3 * fixed_path.length() + 1); |
| 337 | int r = uriWindowsFilenameToUriStringA(fixed_path.data(), out.data()); |
| 338 | // uriWindowsFilenameToUriStringA basically only fails if a null pointer is given. |
| 339 | ARROW_CHECK_EQ(r, 0) << "uriWindowsFilenameToUriStringA unexpectedly failed"; |
| 340 | #else |
| 341 | out.resize(7 + 3 * path.length() + 1); |
| 342 | int r = uriUnixFilenameToUriStringA(path.data(), out.data()); |
| 343 | // same as above (uriWindowsFilenameToUriStringA) |
| 344 | ARROW_CHECK_EQ(r, 0) << "uriUnixFilenameToUriStringA unexpectedly failed"; |
| 345 | #endif |
| 346 | out.resize(strlen(out.data())); |
| 347 | return out; |
| 348 | } |
| 349 | |
| 350 | } // namespace arrow::util |