aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/regex/pcre/regexp.cpp
diff options
context:
space:
mode:
authorAnton Samokhvalov <pg83@yandex.ru>2022-02-10 16:45:17 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:45:17 +0300
commitd3a398281c6fd1d3672036cb2d63f842d2cb28c5 (patch)
treedd4bd3ca0f36b817e96812825ffaf10d645803f2 /library/cpp/regex/pcre/regexp.cpp
parent72cb13b4aff9bc9cf22e49251bc8fd143f82538f (diff)
downloadydb-d3a398281c6fd1d3672036cb2d63f842d2cb28c5.tar.gz
Restoring authorship annotation for Anton Samokhvalov <pg83@yandex.ru>. Commit 2 of 2.
Diffstat (limited to 'library/cpp/regex/pcre/regexp.cpp')
-rw-r--r--library/cpp/regex/pcre/regexp.cpp122
1 files changed, 61 insertions, 61 deletions
diff --git a/library/cpp/regex/pcre/regexp.cpp b/library/cpp/regex/pcre/regexp.cpp
index e7108ae5e9..575c09cee4 100644
--- a/library/cpp/regex/pcre/regexp.cpp
+++ b/library/cpp/regex/pcre/regexp.cpp
@@ -1,21 +1,21 @@
-#include "regexp.h"
-
+#include "regexp.h"
+
#include <util/generic/string.h>
#include <util/string/ascii.h>
#include <util/system/defaults.h>
-
+
#include <cstdlib>
#include <util/generic/noncopyable.h>
-
+
class TGlobalImpl : TNonCopyable {
private:
- const char* Str;
- regmatch_t* Pmatch;
+ const char* Str;
+ regmatch_t* Pmatch;
int Options;
int StrLen;
int StartOffset, NotEmptyOpts, MatchPos;
int MatchBuf[NMATCHES * 3];
- pcre* PregComp;
+ pcre* PregComp;
enum StateCode {
TGI_EXIT,
@@ -26,25 +26,25 @@ private:
private:
void CopyResults(int count) {
for (int i = 0; i < count; i++) {
- Pmatch[MatchPos].rm_so = MatchBuf[2 * i];
- Pmatch[MatchPos].rm_eo = MatchBuf[2 * i + 1];
+ Pmatch[MatchPos].rm_so = MatchBuf[2 * i];
+ Pmatch[MatchPos].rm_eo = MatchBuf[2 * i + 1];
MatchPos++;
if (MatchPos >= NMATCHES) {
ythrow yexception() << "TRegExBase::Exec(): Not enough space in internal buffer.";
}
- }
+ }
}
int DoPcreExec(int opts) {
int rc = pcre_exec(
- PregComp, /* the compiled pattern */
- nullptr, /* no extra data - we didn't study the pattern */
- Str, /* the subject string */
- StrLen, /* the length of the subject */
- StartOffset, /* start at offset 0 in the subject */
- opts, /* default options */
- MatchBuf, /* output vector for substring information */
- NMATCHES); /* number of elements in the output vector */
+ PregComp, /* the compiled pattern */
+ nullptr, /* no extra data - we didn't study the pattern */
+ Str, /* the subject string */
+ StrLen, /* the length of the subject */
+ StartOffset, /* start at offset 0 in the subject */
+ opts, /* default options */
+ MatchBuf, /* output vector for substring information */
+ NMATCHES); /* number of elements in the output vector */
if (rc == 0) {
ythrow yexception() << "TRegExBase::Exec(): Not enough space in internal buffer.";
@@ -55,7 +55,7 @@ private:
StateCode CheckEmptyCase() {
if (MatchBuf[0] == MatchBuf[1]) { // founded an empty string
- if (MatchBuf[0] == StrLen) { // at the end
+ if (MatchBuf[0] == StrLen) { // at the end
return TGI_EXIT;
}
NotEmptyOpts = PCRE_NOTEMPTY | PCRE_ANCHORED; // trying to find non empty string
@@ -65,25 +65,25 @@ private:
StateCode CheckNoMatch(int rc) {
if (rc == PCRE_ERROR_NOMATCH) {
- if (NotEmptyOpts == 0) {
+ if (NotEmptyOpts == 0) {
return TGI_EXIT;
}
-
- MatchBuf[1] = StartOffset + 1; // we have failed to find non-empty-string. trying to find again shifting "previous match offset"
+
+ MatchBuf[1] = StartOffset + 1; // we have failed to find non-empty-string. trying to find again shifting "previous match offset"
return TGI_CONTINUE;
}
return TGI_WALKTHROUGH;
}
public:
- TGlobalImpl(const char* st, regmatch_t& pma, int opts, pcre* pc_re)
- : Str(st)
- , Pmatch(&pma)
- , Options(opts)
- , StartOffset(0)
- , NotEmptyOpts(0)
- , MatchPos(0)
- , PregComp(pc_re)
+ TGlobalImpl(const char* st, regmatch_t& pma, int opts, pcre* pc_re)
+ : Str(st)
+ , Pmatch(&pma)
+ , Options(opts)
+ , StartOffset(0)
+ , NotEmptyOpts(0)
+ , MatchPos(0)
+ , PregComp(pc_re)
{
memset(Pmatch, -1, sizeof(regmatch_t) * NMATCHES);
StrLen = strlen(Str);
@@ -114,29 +114,29 @@ public:
return 0;
case TGI_WALKTHROUGH:
default:
- break;
- }
+ break;
+ }
if (rc < 0) {
return rc;
}
CopyResults(rc);
- } while (true);
+ } while (true);
- return 0;
+ return 0;
}
-
+
private:
};
-class TRegExBaseImpl: public TAtomicRefCount<TRegExBaseImpl> {
+class TRegExBaseImpl: public TAtomicRefCount<TRegExBaseImpl> {
friend class TRegExBase;
protected:
- int CompileOptions;
+ int CompileOptions;
TString RegExpr;
- regex_t Preg;
+ regex_t Preg;
public:
TRegExBaseImpl()
@@ -159,7 +159,7 @@ public:
}
}
- int Exec(const char* str, regmatch_t pmatch[], int eflags, int nmatches) const {
+ int Exec(const char* str, regmatch_t pmatch[], int eflags, int nmatches) const {
if (!RegExpr) {
ythrow yexception() << "Regular expression is not compiled";
}
@@ -170,12 +170,12 @@ public:
return regexec(&Preg, str, nmatches, pmatch, eflags);
} else {
int options = 0;
- if ((eflags & REG_NOTBOL) != 0)
- options |= PCRE_NOTBOL;
- if ((eflags & REG_NOTEOL) != 0)
- options |= PCRE_NOTEOL;
+ if ((eflags & REG_NOTBOL) != 0)
+ options |= PCRE_NOTBOL;
+ if ((eflags & REG_NOTEOL) != 0)
+ options |= PCRE_NOTEOL;
- return TGlobalImpl(str, pmatch[0], options, (pcre*)Preg.re_pcre).ExecGlobal();
+ return TGlobalImpl(str, pmatch[0], options, (pcre*)Preg.re_pcre).ExecGlobal();
}
}
@@ -195,12 +195,12 @@ bool TRegExBase::IsCompiled() const {
return Impl && Impl->IsCompiled();
}
-TRegExBase::TRegExBase(const char* re, int cflags) {
+TRegExBase::TRegExBase(const char* re, int cflags) {
if (re) {
Compile(re, cflags);
}
}
-
+
TRegExBase::TRegExBase(const TString& re, int cflags) {
Compile(re, cflags);
}
@@ -211,8 +211,8 @@ TRegExBase::~TRegExBase() {
void TRegExBase::Compile(const TString& re, int cflags) {
Impl = new TRegExBaseImpl(re, cflags);
}
-
-int TRegExBase::Exec(const char* str, regmatch_t pmatch[], int eflags, int nmatches) const {
+
+int TRegExBase::Exec(const char* str, regmatch_t pmatch[], int eflags, int nmatches) const {
if (!Impl)
ythrow yexception() << "!Regular expression is not compiled";
return Impl->Exec(str, pmatch, eflags, nmatches);
@@ -230,22 +230,22 @@ TString TRegExBase::GetRegExpr() const {
return Impl->RegExpr;
}
-TRegExMatch::TRegExMatch(const char* re, int cflags)
- : TRegExBase(re, cflags)
-{
-}
+TRegExMatch::TRegExMatch(const char* re, int cflags)
+ : TRegExBase(re, cflags)
+{
+}
TRegExMatch::TRegExMatch(const TString& re, int cflags)
: TRegExBase(re, cflags)
{
}
-bool TRegExMatch::Match(const char* str) const {
+bool TRegExMatch::Match(const char* str) const {
return Exec(str, nullptr, 0, 0) == 0;
}
-TRegExSubst::TRegExSubst(const char* re, int cflags)
- : TRegExBase(re, cflags)
+TRegExSubst::TRegExSubst(const char* re, int cflags)
+ : TRegExBase(re, cflags)
, Replacement(nullptr)
{
memset(Brfs, 0, sizeof(TBackReferences) * NMATCHES);
@@ -256,7 +256,7 @@ TString TRegExSubst::Replace(const char* str, int eflags) {
if (BrfsCount) {
if (Exec(str, PMatch, eflags) == 0) {
int i;
- for (i = 0; i < BrfsCount; 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)
s += TString(str, PMatch[Brfs[i].Refer].rm_so, int(PMatch[Brfs[i].Refer].rm_eo - PMatch[Brfs[i].Refer].rm_so));
@@ -280,15 +280,15 @@ TString TRegExSubst::Replace(const char* str, int eflags) {
// {beg = 22, end = 25, Refer = -1} => "ccc"
// {beg = 0, end = 0, Refer = 0}
//***
-int TRegExSubst::ParseReplacement(const char* repl) {
+int TRegExSubst::ParseReplacement(const char* repl) {
Replacement = repl;
if (!Replacement || *Replacement == 0)
return 0;
- char* pos = (char*)Replacement;
+ char* pos = (char*)Replacement;
char* pos1 = nullptr;
char* pos2 = nullptr;
int i = 0;
- while (pos && *pos && i < NMATCHES) {
+ while (pos && *pos && i < NMATCHES) {
pos1 = strchr(pos, '$');
Brfs[i].Refer = -1;
pos2 = pos1;
@@ -296,11 +296,11 @@ int TRegExSubst::ParseReplacement(const char* repl) {
pos2 = pos1 + 1;
while (IsAsciiDigit(*pos2))
pos2++;
- if (pos2 > pos1 + 1) {
+ if (pos2 > pos1 + 1) {
Brfs[i].Refer = atol(TString(Replacement, pos1 + 1 - Replacement, pos2 - (pos1 + 1)).data());
} else {
pos1++;
- if (*pos2 == '$')
+ if (*pos2 == '$')
pos2++;
Brfs[i].Refer = -1;
}