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

Function IsAncestorOf

cpp/src/arrow/filesystem/path_util.cc:229–251  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

227}
228
229bool IsAncestorOf(std::string_view ancestor, std::string_view descendant) {
230 ancestor = RemoveTrailingSlash(ancestor);
231 if (ancestor == "") {
232 // everything is a descendant of the root directory
233 return true;
234 }
235
236 descendant = RemoveTrailingSlash(descendant);
237 if (!descendant.starts_with(ancestor)) {
238 // an ancestor path is a prefix of descendant paths
239 return false;
240 }
241
242 descendant.remove_prefix(ancestor.size());
243
244 if (descendant.empty()) {
245 // "/hello" is an ancestor of "/hello"
246 return true;
247 }
248
249 // "/hello/w" is not an ancestor of "/hello/world"
250 return descendant.starts_with(std::string{kSep});
251}
252
253std::optional<std::string_view> RemoveAncestor(std::string_view ancestor,
254 std::string_view descendant) {

Callers 4

TESTFunction · 0.70
TEST_FFunction · 0.70
RemoveAncestorFunction · 0.70
MinimalCreateDirSetFunction · 0.70

Calls 3

RemoveTrailingSlashFunction · 0.70
sizeMethod · 0.45
emptyMethod · 0.45

Tested by 2

TESTFunction · 0.56
TEST_FFunction · 0.56