diff options
author | Devtools Arcadia <arcadia-devtools@yandex-team.ru> | 2022-02-07 18:08:42 +0300 |
---|---|---|
committer | Devtools Arcadia <arcadia-devtools@mous.vla.yp-c.yandex.net> | 2022-02-07 18:08:42 +0300 |
commit | 1110808a9d39d4b808aef724c861a2e1a38d2a69 (patch) | |
tree | e26c9fed0de5d9873cce7e00bc214573dc2195b7 /util/string/strspn.h | |
download | ydb-1110808a9d39d4b808aef724c861a2e1a38d2a69.tar.gz |
intermediate changes
ref:cde9a383711a11544ce7e107a78147fb96cc4029
Diffstat (limited to 'util/string/strspn.h')
-rw-r--r-- | util/string/strspn.h | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/util/string/strspn.h b/util/string/strspn.h new file mode 100644 index 0000000000..8229e74a9c --- /dev/null +++ b/util/string/strspn.h @@ -0,0 +1,65 @@ +#pragma once + +#include "cstriter.h" + +#include <util/generic/bitmap.h> + +template <class TSetType> +class TStrSpnImpl { +public: + inline TStrSpnImpl(const char* b, const char* e) { + Init(b, e); + } + + inline TStrSpnImpl(const char* s) { + Init(s, TCStringEndIterator()); + } + + //FirstOf + template <class It> + inline It FindFirstOf(It b, const char* e) const noexcept { + return FindFirst<false>(b, e); + } + + template <class It> + inline It FindFirstOf(It s) const noexcept { + return FindFirst<false>(s, TCStringEndIterator()); + } + + //FirstNotOf + template <class It> + inline It FindFirstNotOf(It b, const char* e) const noexcept { + return FindFirst<true>(b, e); + } + + template <class It> + inline It FindFirstNotOf(It s) const noexcept { + return FindFirst<true>(s, TCStringEndIterator()); + } + + inline void Set(ui8 b) noexcept { + S_.Set(b); + } + +private: + template <bool Result, class It1, class It2> + inline It1 FindFirst(It1 b, It2 e) const noexcept { + while (b != e && (S_.Get((ui8)*b) == Result)) { + ++b; + } + + return b; + } + + template <class It1, class It2> + inline void Init(It1 b, It2 e) { + while (b != e) { + this->Set((ui8)*b++); + } + } + +private: + TSetType S_; +}; + +using TCompactStrSpn = TStrSpnImpl<TBitMap<256>>; |