diff options
author | Anton Samokhvalov <pg83@yandex.ru> | 2022-02-10 16:45:15 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:45:15 +0300 |
commit | 72cb13b4aff9bc9cf22e49251bc8fd143f82538f (patch) | |
tree | da2c34829458c7d4e74bdfbdf85dff449e9e7fb8 /util/folder/pathsplit.h | |
parent | 778e51ba091dc39e7b7fcab2b9cf4dbedfb6f2b5 (diff) | |
download | ydb-72cb13b4aff9bc9cf22e49251bc8fd143f82538f.tar.gz |
Restoring authorship annotation for Anton Samokhvalov <pg83@yandex.ru>. Commit 1 of 2.
Diffstat (limited to 'util/folder/pathsplit.h')
-rw-r--r-- | util/folder/pathsplit.h | 168 |
1 files changed, 84 insertions, 84 deletions
diff --git a/util/folder/pathsplit.h b/util/folder/pathsplit.h index d134338e35..c6c0458398 100644 --- a/util/folder/pathsplit.h +++ b/util/folder/pathsplit.h @@ -1,113 +1,113 @@ -#pragma once - -#include <util/generic/vector.h> -#include <util/generic/strbuf.h> +#pragma once + +#include <util/generic/vector.h> +#include <util/generic/strbuf.h> #include <util/generic/string.h> #include <util/string/ascii.h> - -//do not own any data + +//do not own any data struct TPathSplitStore: public TVector<TStringBuf> { - TStringBuf Drive; - bool IsAbsolute = false; - + TStringBuf Drive; + bool IsAbsolute = false; + void AppendComponent(const TStringBuf comp); - TStringBuf Extension() const; - -protected: + TStringBuf Extension() const; + +protected: TString DoReconstruct(const TStringBuf slash) const; - - inline void DoAppendHint(size_t hint) { - reserve(size() + hint); - } -}; - -struct TPathSplitTraitsUnix: public TPathSplitStore { + + inline void DoAppendHint(size_t hint) { + reserve(size() + hint); + } +}; + +struct TPathSplitTraitsUnix: public TPathSplitStore { static constexpr char MainPathSep = '/'; inline TString Reconstruct() const { return DoReconstruct(TStringBuf("/")); - } - + } + static constexpr bool IsPathSep(const char c) noexcept { - return c == '/'; - } - + return c == '/'; + } + static inline bool IsAbsolutePath(const TStringBuf path) noexcept { - return path && IsPathSep(path[0]); - } - + return path && IsPathSep(path[0]); + } + void DoParseFirstPart(const TStringBuf part); void DoParsePart(const TStringBuf part); -}; - -struct TPathSplitTraitsWindows: public TPathSplitStore { +}; + +struct TPathSplitTraitsWindows: public TPathSplitStore { static constexpr char MainPathSep = '\\'; inline TString Reconstruct() const { return DoReconstruct(TStringBuf("\\")); - } - + } + static constexpr bool IsPathSep(char c) noexcept { - return c == '/' || c == '\\'; - } - + return c == '/' || c == '\\'; + } + static inline bool IsAbsolutePath(const TStringBuf path) noexcept { return path && (IsPathSep(path[0]) || (path.size() > 1 && path[1] == ':' && IsAsciiAlpha(path[0]) && (path.size() == 2 || IsPathSep(path[2])))); - } - + } + void DoParseFirstPart(const TStringBuf part); void DoParsePart(const TStringBuf part); -}; - -#if defined(_unix_) -using TPathSplitTraitsLocal = TPathSplitTraitsUnix; -#else -using TPathSplitTraitsLocal = TPathSplitTraitsWindows; -#endif - -template <class TTraits> -class TPathSplitBase: public TTraits { -public: +}; + +#if defined(_unix_) +using TPathSplitTraitsLocal = TPathSplitTraitsUnix; +#else +using TPathSplitTraitsLocal = TPathSplitTraitsWindows; +#endif + +template <class TTraits> +class TPathSplitBase: public TTraits { +public: inline TPathSplitBase() = default; - + inline TPathSplitBase(const TStringBuf part) { - this->ParseFirstPart(part); - } - - inline TPathSplitBase& AppendHint(size_t hint) { - this->DoAppendHint(hint); - - return *this; - } - + this->ParseFirstPart(part); + } + + inline TPathSplitBase& AppendHint(size_t hint) { + this->DoAppendHint(hint); + + return *this; + } + inline TPathSplitBase& ParseFirstPart(const TStringBuf part) { - this->DoParseFirstPart(part); - - return *this; - } - + this->DoParseFirstPart(part); + + return *this; + } + inline TPathSplitBase& ParsePart(const TStringBuf part) { - this->DoParsePart(part); - - return *this; - } - - template <class It> - inline TPathSplitBase& AppendMany(It b, It e) { - this->AppendHint(e - b); - - while (b != e) { - this->AppendComponent(*b++); - } - - return *this; - } -}; - -using TPathSplit = TPathSplitBase<TPathSplitTraitsLocal>; -using TPathSplitUnix = TPathSplitBase<TPathSplitTraitsUnix>; -using TPathSplitWindows = TPathSplitBase<TPathSplitTraitsWindows>; - + this->DoParsePart(part); + + return *this; + } + + template <class It> + inline TPathSplitBase& AppendMany(It b, It e) { + this->AppendHint(e - b); + + while (b != e) { + this->AppendComponent(*b++); + } + + return *this; + } +}; + +using TPathSplit = TPathSplitBase<TPathSplitTraitsLocal>; +using TPathSplitUnix = TPathSplitBase<TPathSplitTraitsUnix>; +using TPathSplitWindows = TPathSplitBase<TPathSplitTraitsWindows>; + TString JoinPaths(const TPathSplit& p1, const TPathSplit& p2); TStringBuf CutExtension(const TStringBuf fileName); |