diff options
author | akhropov <akhropov@yandex-team.ru> | 2022-02-10 16:46:32 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:46:32 +0300 |
commit | 298c6da79f1d8f35089a67f463f0b541bec36d9b (patch) | |
tree | 1a2c5ffcf89eb53ecd79dbc9bc0a195c27404d0c /library/cpp/regex | |
parent | 00afc96e9c0298054b7386fa7fb9e3cc3d67b974 (diff) | |
download | ydb-298c6da79f1d8f35089a67f463f0b541bec36d9b.tar.gz |
Restoring authorship annotation for <akhropov@yandex-team.ru>. Commit 2 of 2.
Diffstat (limited to 'library/cpp/regex')
-rw-r--r-- | library/cpp/regex/pcre/regexp.cpp | 64 | ||||
-rw-r--r-- | library/cpp/regex/pcre/regexp.h | 34 |
2 files changed, 49 insertions, 49 deletions
diff --git a/library/cpp/regex/pcre/regexp.cpp b/library/cpp/regex/pcre/regexp.cpp index dc288c2c61..575c09cee4 100644 --- a/library/cpp/regex/pcre/regexp.cpp +++ b/library/cpp/regex/pcre/regexp.cpp @@ -137,7 +137,7 @@ protected: int CompileOptions; TString RegExpr; regex_t Preg; - + public: TRegExBaseImpl() : CompileOptions(0) @@ -156,8 +156,8 @@ public: regerror(rc, &Preg, errbuf, ERRBUF_SIZE); Error = "Error: regular expression " + re + " is wrong: " + errbuf; ythrow yexception() << "RegExp " << re << ": " << Error.data(); - } - } + } + } int Exec(const char* str, regmatch_t pmatch[], int eflags, int nmatches) const { if (!RegExpr) { @@ -205,7 +205,7 @@ TRegExBase::TRegExBase(const TString& re, int cflags) { Compile(re, cflags); } -TRegExBase::~TRegExBase() { +TRegExBase::~TRegExBase() { } void TRegExBase::Compile(const TString& re, int cflags) { @@ -234,7 +234,7 @@ TRegExMatch::TRegExMatch(const char* re, int cflags) : TRegExBase(re, cflags) { } - + TRegExMatch::TRegExMatch(const TString& re, int cflags) : TRegExBase(re, cflags) { @@ -242,47 +242,47 @@ TRegExMatch::TRegExMatch(const TString& re, int cflags) bool TRegExMatch::Match(const char* str) const { return Exec(str, nullptr, 0, 0) == 0; -} - +} + TRegExSubst::TRegExSubst(const char* re, int cflags) : TRegExBase(re, cflags) , Replacement(nullptr) -{ - memset(Brfs, 0, sizeof(TBackReferences) * NMATCHES); -} - +{ + memset(Brfs, 0, sizeof(TBackReferences) * NMATCHES); +} + TString TRegExSubst::Replace(const char* str, int eflags) { TString s; - if (BrfsCount) { - if (Exec(str, PMatch, eflags) == 0) { + if (BrfsCount) { + if (Exec(str, PMatch, eflags) == 0) { int i; for (i = 0; i < BrfsCount; i++) { s += TString(Replacement, Brfs[i].Beg, Brfs[i].End - Brfs[i].Beg); - if (Brfs[i].Refer >= 0 && Brfs[i].Refer < NMATCHES) + if (Brfs[i].Refer >= 0 && Brfs[i].Refer < NMATCHES) s += TString(str, PMatch[Brfs[i].Refer].rm_so, int(PMatch[Brfs[i].Refer].rm_eo - PMatch[Brfs[i].Refer].rm_so)); } s += TString(Replacement, Brfs[i].Beg, Brfs[i].End - Brfs[i].Beg); } } else { - s = Replacement; + s = Replacement; } return s; } //*** // ��� ������������ ������ aaa.$1.$$$$.$2.bbb.$$$ccc Brfs ����� �����: -// {beg = 0, end = 4, Refer = 1} => "aaa." + $1_match -// {beg = 6, end = 8, Refer = -1} => ".$" -// {beg = 9, end = 10, Refer = -1} => "$" -// {beg = 11, end = 12, Refer = 2} => "." + $2_match -// {beg = 14, end = 20, Refer = -1} => ".bbb.$" -// {beg = 21, end = 22, Refer = -1} => "$" -// {beg = 22, end = 25, Refer = -1} => "ccc" -// {beg = 0, end = 0, Refer = 0} +// {beg = 0, end = 4, Refer = 1} => "aaa." + $1_match +// {beg = 6, end = 8, Refer = -1} => ".$" +// {beg = 9, end = 10, Refer = -1} => "$" +// {beg = 11, end = 12, Refer = 2} => "." + $2_match +// {beg = 14, end = 20, Refer = -1} => ".bbb.$" +// {beg = 21, end = 22, Refer = -1} => "$" +// {beg = 22, end = 25, Refer = -1} => "ccc" +// {beg = 0, end = 0, Refer = 0} //*** int TRegExSubst::ParseReplacement(const char* repl) { - Replacement = repl; - if (!Replacement || *Replacement == 0) + Replacement = repl; + if (!Replacement || *Replacement == 0) return 0; char* pos = (char*)Replacement; char* pos1 = nullptr; @@ -290,7 +290,7 @@ int TRegExSubst::ParseReplacement(const char* repl) { int i = 0; while (pos && *pos && i < NMATCHES) { pos1 = strchr(pos, '$'); - Brfs[i].Refer = -1; + Brfs[i].Refer = -1; pos2 = pos1; if (pos1) { pos2 = pos1 + 1; @@ -302,16 +302,16 @@ int TRegExSubst::ParseReplacement(const char* repl) { pos1++; if (*pos2 == '$') pos2++; - Brfs[i].Refer = -1; + Brfs[i].Refer = -1; } } - Brfs[i].Beg = int(pos - (char*)Replacement); + Brfs[i].Beg = int(pos - (char*)Replacement); Brfs[i].End = (pos1 == nullptr ? (int)strlen(Replacement) : int(pos1 - Replacement)); pos = pos2; i++; } - Brfs[i].Beg = Brfs[i].End = 0; - Brfs[i].Refer = -1; - BrfsCount = i; - return BrfsCount; + Brfs[i].Beg = Brfs[i].End = 0; + Brfs[i].Refer = -1; + BrfsCount = i; + return BrfsCount; } diff --git a/library/cpp/regex/pcre/regexp.h b/library/cpp/regex/pcre/regexp.h index 9862a9b85b..bc610bd2f3 100644 --- a/library/cpp/regex/pcre/regexp.h +++ b/library/cpp/regex/pcre/regexp.h @@ -17,15 +17,15 @@ class TRegExBaseImpl; class TRegExBase { -protected: +protected: TSimpleIntrusivePtr<TRegExBaseImpl> Impl; -public: +public: TRegExBase(const char* regExpr = nullptr, int cflags = REG_EXTENDED); TRegExBase(const TString& regExpr, int cflags = REG_EXTENDED); virtual ~TRegExBase(); - + int Exec(const char* str, regmatch_t pmatch[], int eflags, int nmatches = NMATCHES) const; void Compile(const TString& regExpr, int cflags = REG_EXTENDED); bool IsCompiled() const; @@ -34,30 +34,30 @@ public: }; class TRegExMatch: public TRegExBase { -public: +public: TRegExMatch(const char* regExpr = nullptr, int cflags = REG_NOSUB | REG_EXTENDED); TRegExMatch(const TString& regExpr, int cflags = REG_NOSUB | REG_EXTENDED); bool Match(const char* str) const; -}; +}; struct TBackReferences { - int Beg; - int End; - int Refer; -}; + int Beg; + int End; + int Refer; +}; class TRegExSubst: public TRegExBase { -private: - const char* Replacement; +private: + const char* Replacement; regmatch_t PMatch[NMATCHES]; - - TBackReferences Brfs[NMATCHES]; - int BrfsCount; - -public: + + TBackReferences Brfs[NMATCHES]; + int BrfsCount; + +public: TRegExSubst(const char* regExpr = nullptr, int cflags = REG_EXTENDED); - + TString Replace(const char* str, int eflags = 0); int ParseReplacement(const char* replacement); }; |