File indexing completed on 2025-08-28 08:26:59
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018 #pragma once
0019
0020 #include <optional>
0021 #include <string>
0022 #include <string_view>
0023 #include <utility>
0024 #include <vector>
0025
0026 #include "arrow/type_fwd.h"
0027
0028 namespace arrow {
0029 namespace fs {
0030 namespace internal {
0031
0032 constexpr char kSep = '/';
0033
0034
0035
0036
0037
0038 ARROW_EXPORT
0039 std::vector<std::string> SplitAbstractPath(const std::string& path, char sep = kSep);
0040
0041
0042
0043
0044
0045
0046 ARROW_EXPORT
0047 std::string SliceAbstractPath(const std::string& path, int offset, int length,
0048 char sep = kSep);
0049
0050
0051 ARROW_EXPORT std::string GetAbstractPathExtension(const std::string& s);
0052
0053
0054
0055
0056
0057
0058
0059 ARROW_EXPORT int GetAbstractPathDepth(std::string_view path);
0060
0061
0062
0063 ARROW_EXPORT
0064 std::pair<std::string, std::string> GetAbstractPathParent(const std::string& s);
0065
0066
0067 ARROW_EXPORT
0068 Status ValidateAbstractPath(std::string_view path);
0069
0070
0071 ARROW_EXPORT
0072 Status ValidateAbstractPathParts(const std::vector<std::string>& parts);
0073
0074
0075 ARROW_EXPORT
0076 std::string ConcatAbstractPath(std::string_view base, std::string_view stem);
0077
0078
0079 ARROW_EXPORT
0080 Result<std::string> MakeAbstractPathRelative(const std::string& base,
0081 const std::string& path);
0082
0083 ARROW_EXPORT
0084 std::string EnsureLeadingSlash(std::string_view s);
0085
0086 ARROW_EXPORT
0087 std::string_view RemoveLeadingSlash(std::string_view s);
0088
0089 ARROW_EXPORT
0090 std::string EnsureTrailingSlash(std::string_view s);
0091
0092
0093
0094
0095 ARROW_EXPORT
0096 std::string_view RemoveTrailingSlash(std::string_view s, bool preserve_root = false);
0097
0098 ARROW_EXPORT
0099 Status AssertNoTrailingSlash(std::string_view s);
0100
0101 inline bool HasTrailingSlash(std::string_view s) {
0102 return !s.empty() && s.back() == kSep;
0103 }
0104
0105 inline bool HasLeadingSlash(std::string_view s) {
0106 return !s.empty() && s.front() == kSep;
0107 }
0108
0109 ARROW_EXPORT
0110 bool IsAncestorOf(std::string_view ancestor, std::string_view descendant);
0111
0112 ARROW_EXPORT
0113 std::optional<std::string_view> RemoveAncestor(std::string_view ancestor,
0114 std::string_view descendant);
0115
0116
0117
0118
0119
0120 ARROW_EXPORT
0121 std::vector<std::string> AncestorsFromBasePath(std::string_view base_path,
0122 std::string_view descendant);
0123
0124
0125
0126
0127 ARROW_EXPORT
0128 std::vector<std::string> MinimalCreateDirSet(std::vector<std::string> dirs);
0129
0130
0131 template <class StringIt>
0132 std::string JoinAbstractPath(StringIt it, StringIt end, char sep = kSep) {
0133 std::string path;
0134 for (; it != end; ++it) {
0135 if (it->empty()) continue;
0136
0137 if (!path.empty()) {
0138 path += sep;
0139 }
0140 path += *it;
0141 }
0142 return path;
0143 }
0144
0145 template <class StringRange>
0146 std::string JoinAbstractPath(const StringRange& range, char sep = kSep) {
0147 return JoinAbstractPath(range.begin(), range.end(), sep);
0148 }
0149
0150
0151 ARROW_EXPORT
0152 std::string ToBackslashes(std::string_view s);
0153
0154
0155
0156 ARROW_EXPORT
0157 std::string ToSlashes(std::string_view s);
0158
0159 ARROW_EXPORT
0160 bool IsEmptyPath(std::string_view s);
0161
0162 ARROW_EXPORT
0163 bool IsLikelyUri(std::string_view s);
0164
0165 class ARROW_EXPORT Globber {
0166 public:
0167 ~Globber();
0168 explicit Globber(std::string pattern);
0169 bool Matches(const std::string& path);
0170
0171 protected:
0172 struct Impl;
0173 std::unique_ptr<Impl> impl_;
0174 };
0175
0176 }
0177 }
0178 }