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 /library/cpp/regex/pire/regexp.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 'library/cpp/regex/pire/regexp.h')
-rw-r--r-- | library/cpp/regex/pire/regexp.h | 110 |
1 files changed, 55 insertions, 55 deletions
diff --git a/library/cpp/regex/pire/regexp.h b/library/cpp/regex/pire/regexp.h index 94bba4064b..d5424e359a 100644 --- a/library/cpp/regex/pire/regexp.h +++ b/library/cpp/regex/pire/regexp.h @@ -1,7 +1,7 @@ #pragma once - -#include "pire.h" - + +#include "pire.h" + #include <library/cpp/charset/doccodes.h> #include <library/cpp/charset/recyr.hh> #include <util/generic/maybe.h> @@ -10,26 +10,26 @@ #include <util/generic/vector.h> #include <util/generic/yexception.h> -namespace NRegExp { +namespace NRegExp { struct TMatcher; - + struct TFsmBase { struct TOptions { inline TOptions& SetCaseInsensitive(bool v) noexcept { CaseInsensitive = v; return *this; } - + inline TOptions& SetSurround(bool v) noexcept { Surround = v; return *this; } - + inline TOptions& SetCapture(size_t pos) noexcept { CapturePos = pos; return *this; - } - + } + inline TOptions& SetCharset(ECharset charset) noexcept { Charset = charset; return *this; @@ -68,64 +68,64 @@ namespace NRegExp { if (opts.CaseInsensitive) { lexer.AddFeature(NPire::NFeatures::CaseInsensitive()); - } - + } + if (opts.CapturePos) { lexer.AddFeature(NPire::NFeatures::Capture(*opts.CapturePos)); - } - + } + if (opts.AndNotSupport) { lexer.AddFeature(NPire::NFeatures::AndNotSupport()); } switch (opts.Charset) { - case CODES_UNKNOWN: - break; - case CODES_UTF8: - lexer.SetEncoding(NPire::NEncodings::Utf8()); - break; - case CODES_KOI8: - lexer.SetEncoding(NPire::NEncodings::Koi8r()); - break; - default: - lexer.SetEncoding(NPire::NEncodings::Get(opts.Charset)); - break; + case CODES_UNKNOWN: + break; + case CODES_UTF8: + lexer.SetEncoding(NPire::NEncodings::Utf8()); + break; + case CODES_KOI8: + lexer.SetEncoding(NPire::NEncodings::Koi8r()); + break; + default: + lexer.SetEncoding(NPire::NEncodings::Get(opts.Charset)); + break; } NPire::TFsm ret = lexer.Parse(); if (opts.Surround) { ret.Surround(); - } - + } + if (needDetermine) { ret.Determine(); } - + return ret; } }; - + template <class TScannerType> class TFsmParser: public TFsmBase { public: typedef TScannerType TScanner; - + public: inline explicit TFsmParser(const TStringBuf& regexp, const TOptions& opts = TOptions(), bool needDetermine = true) : Scanner(Parse(regexp, opts, needDetermine).template Compile<TScanner>()) { } - + inline const TScanner& GetScanner() const noexcept { return Scanner; } - + static inline TFsmParser False() { return TFsmParser(NPire::TFsm::MakeFalse().Compile<TScanner>()); } - + inline explicit TFsmParser(const TScanner& compiled) : Scanner(compiled) { @@ -135,12 +135,12 @@ namespace NRegExp { private: TScanner Scanner; - }; - + }; + class TFsm: public TFsmParser<NPire::TNonrelocScanner> { public: inline explicit TFsm(const TStringBuf& regexp, - const TOptions& opts = TOptions()) + const TOptions& opts = TOptions()) : TFsmParser<TScanner>(regexp, opts) { } @@ -150,7 +150,7 @@ namespace NRegExp { { } - static inline TFsm Glue(const TFsm& l, const TFsm& r) { + static inline TFsm Glue(const TFsm& l, const TFsm& r) { return TFsm(TScanner::Glue(l.GetScanner(), r.GetScanner())); } @@ -160,23 +160,23 @@ namespace NRegExp { } }; - static inline TFsm operator|(const TFsm& l, const TFsm& r) { - return TFsm::Glue(l, r); - } - - struct TCapturingFsm : TFsmParser<NPire::TCapturingScanner> { + static inline TFsm operator|(const TFsm& l, const TFsm& r) { + return TFsm::Glue(l, r); + } + + struct TCapturingFsm : TFsmParser<NPire::TCapturingScanner> { inline explicit TCapturingFsm(const TStringBuf& regexp, - TOptions opts = TOptions()) + TOptions opts = TOptions()) : TFsmParser<TScanner>(regexp, - opts.SetSurround(true).CapturePos ? opts : opts.SetCapture(1)) { + opts.SetSurround(true).CapturePos ? opts : opts.SetCapture(1)) { } - + inline TCapturingFsm(const TFsmParser<TScanner>& fsm) : TFsmParser<TScanner>(fsm) { } }; - + struct TSlowCapturingFsm : TFsmParser<NPire::TSlowCapturingScanner> { inline explicit TSlowCapturingFsm(const TStringBuf& regexp, TOptions opts = TOptions()) @@ -194,43 +194,43 @@ namespace NRegExp { class TMatcherBase { public: typedef typename TFsm::TScanner::State TState; - + public: inline explicit TMatcherBase(const TFsm& fsm) : Fsm(fsm) { Fsm.GetScanner().Initialize(State); } - + inline bool Final() const noexcept { return GetScanner().Final(GetState()); } - + protected: inline void Run(const char* data, size_t len, bool addBegin, bool addEnd) noexcept { if (addBegin) { NPire::Step(GetScanner(), State, NPire::BeginMark); - } + } NPire::Run(GetScanner(), State, data, data + len); if (addEnd) { NPire::Step(GetScanner(), State, NPire::EndMark); } } - + inline const typename TFsm::TScanner& GetScanner() const noexcept { return Fsm.GetScanner(); } - + inline const TState& GetState() const noexcept { return State; } - + private: const TFsm& Fsm; TState State; - }; + }; - struct TMatcher : TMatcherBase<TFsm> { + struct TMatcher : TMatcherBase<TFsm> { inline explicit TMatcher(const TFsm& fsm) : TMatcherBase<TFsm>(fsm) { @@ -334,4 +334,4 @@ namespace NRegExp { return *this; } }; -} +} |