diff options
author | tldr <tldr@yandex-team.ru> | 2022-02-10 16:50:18 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:50:18 +0300 |
commit | 42d219fbd63ee173b0cb7db1b26a3ec615f0bb71 (patch) | |
tree | 5d5cb817648f650d76cf1076100726fd9b8448e8 /util | |
parent | fb217752f4b5a81abe9df05e38c5a71d080fc2a8 (diff) | |
download | ydb-42d219fbd63ee173b0cb7db1b26a3ec615f0bb71.tar.gz |
Restoring authorship annotation for <tldr@yandex-team.ru>. Commit 2 of 2.
Diffstat (limited to 'util')
-rw-r--r-- | util/folder/path.cpp | 38 | ||||
-rw-r--r-- | util/folder/path.h | 40 | ||||
-rw-r--r-- | util/folder/path_ut.cpp | 82 |
3 files changed, 80 insertions, 80 deletions
diff --git a/util/folder/path.cpp b/util/folder/path.cpp index 400fa90741..bfe0c67d68 100644 --- a/util/folder/path.cpp +++ b/util/folder/path.cpp @@ -40,25 +40,25 @@ bool TFsPath::IsSubpathOf(const TFsPath& that) const { return std::equal(rsplit.begin(), rsplit.end(), split.begin()); } -bool TFsPath::IsNonStrictSubpathOf(const TFsPath& that) const { - const TSplit& split = GetSplit(); - const TSplit& rsplit = that.GetSplit(); - - if (rsplit.IsAbsolute != split.IsAbsolute) { - return false; - } - - if (rsplit.Drive != split.Drive) { - return false; - } - - if (rsplit.size() > split.size()) { - return false; - } - - return std::equal(rsplit.begin(), rsplit.end(), split.begin()); -} - +bool TFsPath::IsNonStrictSubpathOf(const TFsPath& that) const { + const TSplit& split = GetSplit(); + const TSplit& rsplit = that.GetSplit(); + + if (rsplit.IsAbsolute != split.IsAbsolute) { + return false; + } + + if (rsplit.Drive != split.Drive) { + return false; + } + + if (rsplit.size() > split.size()) { + return false; + } + + return std::equal(rsplit.begin(), rsplit.end(), split.begin()); +} + TFsPath TFsPath::RelativeTo(const TFsPath& root) const { TSplit split = GetSplit(); const TSplit& rsplit = root.GetSplit(); diff --git a/util/folder/path.h b/util/folder/path.h index 4582b3fe7b..2fb4d6b4ef 100644 --- a/util/folder/path.h +++ b/util/folder/path.h @@ -88,27 +88,27 @@ public: bool IsAbsolute() const; bool IsRelative() const; - /** - * TFsPath("/a/b").IsSubpathOf("/a") -> true - * - * TFsPath("/a").IsSubpathOf("/a") -> false - * - * TFsPath("/a").IsSubpathOf("/other/path") -> false - * @param that - presumable parent path of this - * @return True if this is a subpath of that and false otherwise. - */ + /** + * TFsPath("/a/b").IsSubpathOf("/a") -> true + * + * TFsPath("/a").IsSubpathOf("/a") -> false + * + * TFsPath("/a").IsSubpathOf("/other/path") -> false + * @param that - presumable parent path of this + * @return True if this is a subpath of that and false otherwise. + */ bool IsSubpathOf(const TFsPath& that) const; - - /** - * TFsPath("/a/b").IsNonStrictSubpathOf("/a") -> true - * - * TFsPath("/a").IsNonStrictSubpathOf("/a") -> true - * - * TFsPath("/a").IsNonStrictSubpathOf("/other/path") -> false - * @param that - presumable parent path of this - * @return True if this is a subpath of that or they are equivalent and false otherwise. - */ - bool IsNonStrictSubpathOf(const TFsPath& that) const; + + /** + * TFsPath("/a/b").IsNonStrictSubpathOf("/a") -> true + * + * TFsPath("/a").IsNonStrictSubpathOf("/a") -> true + * + * TFsPath("/a").IsNonStrictSubpathOf("/other/path") -> false + * @param that - presumable parent path of this + * @return True if this is a subpath of that or they are equivalent and false otherwise. + */ + bool IsNonStrictSubpathOf(const TFsPath& that) const; bool IsContainerOf(const TFsPath& that) const { return that.IsSubpathOf(*this); diff --git a/util/folder/path_ut.cpp b/util/folder/path_ut.cpp index d8cc8ac133..e6a3451016 100644 --- a/util/folder/path_ut.cpp +++ b/util/folder/path_ut.cpp @@ -293,47 +293,47 @@ Y_UNIT_TEST_SUITE(TFsPathTests) { #endif } - Y_UNIT_TEST(TestNonStrictSubpathOf) { - UNIT_ASSERT(TFsPath("/a/b/c/d").IsNonStrictSubpathOf("/a/b")); - - UNIT_ASSERT(TFsPath("/a").IsNonStrictSubpathOf("/")); - UNIT_ASSERT(!TFsPath("/").IsNonStrictSubpathOf("/a")); - - UNIT_ASSERT(TFsPath("/a/b").IsNonStrictSubpathOf("/a")); - UNIT_ASSERT(TFsPath("a/b").IsNonStrictSubpathOf("a")); - UNIT_ASSERT(!TFsPath("/a/b").IsNonStrictSubpathOf("/b")); - UNIT_ASSERT(!TFsPath("a/b").IsNonStrictSubpathOf("b")); - - // mixing absolute/relative - UNIT_ASSERT(!TFsPath("a").IsNonStrictSubpathOf("/")); - UNIT_ASSERT(!TFsPath("a").IsNonStrictSubpathOf("/a")); - UNIT_ASSERT(!TFsPath("/a").IsNonStrictSubpathOf("a")); - UNIT_ASSERT(!TFsPath("a/b").IsNonStrictSubpathOf("/a")); - UNIT_ASSERT(!TFsPath("/a/b").IsNonStrictSubpathOf("a")); - - // equal paths - UNIT_ASSERT(TFsPath("").IsNonStrictSubpathOf("")); - UNIT_ASSERT(TFsPath("/").IsNonStrictSubpathOf("/")); - UNIT_ASSERT(TFsPath("a").IsNonStrictSubpathOf("a")); - UNIT_ASSERT(TFsPath("/a").IsNonStrictSubpathOf("/a")); - UNIT_ASSERT(TFsPath("/a").IsNonStrictSubpathOf("/a/")); - UNIT_ASSERT(TFsPath("/a/").IsNonStrictSubpathOf("/a")); - UNIT_ASSERT(TFsPath("/a/").IsNonStrictSubpathOf("/a/")); - -#ifdef _win_ - UNIT_ASSERT(TFsPath("x:/a/b").IsNonStrictSubpathOf("x:/a")); - - UNIT_ASSERT(TFsPath("x:/a").IsNonStrictSubpathOf("x:/a")); - UNIT_ASSERT(TFsPath("x:/a/").IsNonStrictSubpathOf("x:/a")); - UNIT_ASSERT(TFsPath("x:/a").IsNonStrictSubpathOf("x:/a/")); - UNIT_ASSERT(TFsPath("x:/a/").IsNonStrictSubpathOf("x:/a/")); - - UNIT_ASSERT(!TFsPath("x:/").IsNonStrictSubpathOf("y:/")); - UNIT_ASSERT(!TFsPath("x:/a/b").IsNonStrictSubpathOf("y:/a")); - UNIT_ASSERT(!TFsPath("x:/a/b").IsNonStrictSubpathOf("a")); -#endif - } - + Y_UNIT_TEST(TestNonStrictSubpathOf) { + UNIT_ASSERT(TFsPath("/a/b/c/d").IsNonStrictSubpathOf("/a/b")); + + UNIT_ASSERT(TFsPath("/a").IsNonStrictSubpathOf("/")); + UNIT_ASSERT(!TFsPath("/").IsNonStrictSubpathOf("/a")); + + UNIT_ASSERT(TFsPath("/a/b").IsNonStrictSubpathOf("/a")); + UNIT_ASSERT(TFsPath("a/b").IsNonStrictSubpathOf("a")); + UNIT_ASSERT(!TFsPath("/a/b").IsNonStrictSubpathOf("/b")); + UNIT_ASSERT(!TFsPath("a/b").IsNonStrictSubpathOf("b")); + + // mixing absolute/relative + UNIT_ASSERT(!TFsPath("a").IsNonStrictSubpathOf("/")); + UNIT_ASSERT(!TFsPath("a").IsNonStrictSubpathOf("/a")); + UNIT_ASSERT(!TFsPath("/a").IsNonStrictSubpathOf("a")); + UNIT_ASSERT(!TFsPath("a/b").IsNonStrictSubpathOf("/a")); + UNIT_ASSERT(!TFsPath("/a/b").IsNonStrictSubpathOf("a")); + + // equal paths + UNIT_ASSERT(TFsPath("").IsNonStrictSubpathOf("")); + UNIT_ASSERT(TFsPath("/").IsNonStrictSubpathOf("/")); + UNIT_ASSERT(TFsPath("a").IsNonStrictSubpathOf("a")); + UNIT_ASSERT(TFsPath("/a").IsNonStrictSubpathOf("/a")); + UNIT_ASSERT(TFsPath("/a").IsNonStrictSubpathOf("/a/")); + UNIT_ASSERT(TFsPath("/a/").IsNonStrictSubpathOf("/a")); + UNIT_ASSERT(TFsPath("/a/").IsNonStrictSubpathOf("/a/")); + +#ifdef _win_ + UNIT_ASSERT(TFsPath("x:/a/b").IsNonStrictSubpathOf("x:/a")); + + UNIT_ASSERT(TFsPath("x:/a").IsNonStrictSubpathOf("x:/a")); + UNIT_ASSERT(TFsPath("x:/a/").IsNonStrictSubpathOf("x:/a")); + UNIT_ASSERT(TFsPath("x:/a").IsNonStrictSubpathOf("x:/a/")); + UNIT_ASSERT(TFsPath("x:/a/").IsNonStrictSubpathOf("x:/a/")); + + UNIT_ASSERT(!TFsPath("x:/").IsNonStrictSubpathOf("y:/")); + UNIT_ASSERT(!TFsPath("x:/a/b").IsNonStrictSubpathOf("y:/a")); + UNIT_ASSERT(!TFsPath("x:/a/b").IsNonStrictSubpathOf("a")); +#endif + } + Y_UNIT_TEST(TestRelativePath) { UNIT_ASSERT_VALUES_EQUAL(TFsPath("/a/b/c/d").RelativePath(TFsPath("/a/b")), TFsPath("c/d")); UNIT_ASSERT_VALUES_EQUAL(TFsPath("/a/b/c/d").RelativePath(TFsPath("/a/b/e/f")), TFsPath("../../c/d")); |