diff options
author | yazevnul <[email protected]> | 2022-02-10 16:46:46 +0300 |
---|---|---|
committer | Daniil Cherednik <[email protected]> | 2022-02-10 16:46:46 +0300 |
commit | 8cbc307de0221f84c80c42dcbe07d40727537e2c (patch) | |
tree | 625d5a673015d1df891e051033e9fcde5c7be4e5 /util/stream/tokenizer.h | |
parent | 30d1ef3941e0dc835be7609de5ebee66958f215a (diff) |
Restoring authorship annotation for <[email protected]>. Commit 1 of 2.
Diffstat (limited to 'util/stream/tokenizer.h')
-rw-r--r-- | util/stream/tokenizer.h | 80 |
1 files changed, 40 insertions, 40 deletions
diff --git a/util/stream/tokenizer.h b/util/stream/tokenizer.h index b2398efdd1a..bc27650ce44 100644 --- a/util/stream/tokenizer.h +++ b/util/stream/tokenizer.h @@ -2,10 +2,10 @@ #include "input.h" -#include <util/generic/buffer.h> -#include <util/generic/mem_copy.h> -#include <util/generic/strbuf.h> -#include <util/system/compiler.h> +#include <util/generic/buffer.h> +#include <util/generic/mem_copy.h> +#include <util/generic/strbuf.h> +#include <util/system/compiler.h> #include <util/system/yassert.h> /** @@ -20,12 +20,12 @@ * @tparam TEndOfToken Predicate for token delimiter characters. * @see TEol */ -template <typename TEndOfToken> +template <typename TEndOfToken> class TStreamTokenizer { public: class TIterator { public: - inline TIterator(TStreamTokenizer* const parent) + inline TIterator(TStreamTokenizer* const parent) : Parent_(parent) , AtEnd_(!Parent_->Next(Data_, Len_)) { @@ -53,21 +53,21 @@ public: return !(*this == l); } - /** - * @return Return null-terminated character array with current token. - * The pointer may be invalid after iterator increment. - */ + /** + * @return Return null-terminated character array with current token. + * The pointer may be invalid after iterator increment. + */ inline const char* Data() const noexcept { - Y_ASSERT(!AtEnd_); + Y_ASSERT(!AtEnd_); return Data_; } - /** - * @return Length of current token. - */ + /** + * @return Length of current token. + */ inline size_t Length() const noexcept { - Y_ASSERT(!AtEnd_); + Y_ASSERT(!AtEnd_); return Len_; } @@ -77,27 +77,27 @@ public: } inline TStringBuf operator*() noexcept { - return TStringBuf{Data_, Len_}; + return TStringBuf{Data_, Len_}; } private: inline void Next() { - Y_ASSERT(Parent_); + Y_ASSERT(Parent_); AtEnd_ = !Parent_->Next(Data_, Len_); } private: - TStreamTokenizer* const Parent_; + TStreamTokenizer* const Parent_; char* Data_; size_t Len_; bool AtEnd_; }; - inline TStreamTokenizer(IInputStream* const input, const TEndOfToken& eot = TEndOfToken(), - const size_t initial = 1024) + inline TStreamTokenizer(IInputStream* const input, const TEndOfToken& eot = TEndOfToken(), + const size_t initial = 1024) : Input_(input) - , Buf_(initial) + , Buf_(initial) , Cur_(BufBegin()) , End_(BufBegin()) , Eot_(eot) @@ -112,7 +112,7 @@ public: do { while (it != End_) { if (Eot_(*it)) { - *it = '\0'; + *it = '\0'; buf = Cur_; len = it - Cur_; @@ -125,7 +125,7 @@ public: } if (Fill() == 0 && End_ != BufEnd()) { - *it = '\0'; + *it = '\0'; buf = Cur_; len = it - Cur_; @@ -135,25 +135,25 @@ public: } } while (it != BufEnd()); - Y_ASSERT(it == BufEnd()); - Y_ASSERT(End_ == BufEnd()); + Y_ASSERT(it == BufEnd()); + Y_ASSERT(End_ == BufEnd()); const size_t blen = End_ - Cur_; if (Cur_ == BufBegin()) { - Y_ASSERT(blen == Buf_.Capacity()); + Y_ASSERT(blen == Buf_.Capacity()); /* * do reallocate */ - Buf_.Reserve(Buf_.Capacity() * 4); + Buf_.Reserve(Buf_.Capacity() * 4); CheckBuf(); } else { /* * do move */ - MemMove(BufBegin(), Cur_, blen); + MemMove(BufBegin(), Cur_, blen); } Cur_ = BufBegin(); @@ -162,14 +162,14 @@ public: } } - inline TIterator begin() { - return TIterator{this}; - } - + inline TIterator begin() { + return TIterator{this}; + } + inline TIterator end() noexcept { - return {}; - } - + return {}; + } + private: inline size_t Fill() { const size_t avail = BufEnd() - End_; @@ -181,22 +181,22 @@ private: } inline char* BufBegin() noexcept { - return Buf_.Data(); + return Buf_.Data(); } inline char* BufEnd() noexcept { - return Buf_.Data() + Buf_.Capacity(); + return Buf_.Data() + Buf_.Capacity(); } inline void CheckBuf() const { - if (!Buf_.Data()) { + if (!Buf_.Data()) { throw std::bad_alloc(); } } private: - IInputStream* const Input_; - TBuffer Buf_; + IInputStream* const Input_; + TBuffer Buf_; char* Cur_; char* End_; TEndOfToken Eot_; |