diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/Document.cxx | 7 | ||||
-rw-r--r-- | src/RESearch.cxx | 23 | ||||
-rw-r--r-- | src/RESearch.h | 4 |
3 files changed, 14 insertions, 20 deletions
diff --git a/src/Document.cxx b/src/Document.cxx index d5a677499..c290c9226 100644 --- a/src/Document.cxx +++ b/src/Document.cxx @@ -2227,15 +2227,14 @@ long BuiltinRegex::FindText(Document *doc, int minPos, int maxPos, const char *s const char *BuiltinRegex::SubstituteByPosition(Document *doc, const char *text, int *length) { substituted.clear(); DocumentIndexer di(doc, doc->Length()); - if (!search.GrabMatches(di)) - return 0; + search.GrabMatches(di); for (int j = 0; j < *length; j++) { if (text[j] == '\\') { if (text[j + 1] >= '0' && text[j + 1] <= '9') { unsigned int patNum = text[j + 1] - '0'; unsigned int len = search.eopat[patNum] - search.bopat[patNum]; - if (search.pat[patNum]) // Will be null if try for a match that did not occur - substituted.append(search.pat[patNum], len); + if (!search.pat[patNum].empty()) // Will be null if try for a match that did not occur + substituted.append(search.pat[patNum].c_str(), len); j++; } else { j++; diff --git a/src/RESearch.cxx b/src/RESearch.cxx index bef24e57b..efa23eb84 100644 --- a/src/RESearch.cxx +++ b/src/RESearch.cxx @@ -202,6 +202,8 @@ #include <stdlib.h> +#include <string> + #include "CharClassify.h" #include "RESearch.h" @@ -265,36 +267,29 @@ void RESearch::Init() { sta = NOP; /* status of lastpat */ bol = 0; for (int i = 0; i < MAXTAG; i++) - pat[i] = 0; + pat[i].clear(); for (int j = 0; j < BITBLK; j++) bittab[j] = 0; } void RESearch::Clear() { for (int i = 0; i < MAXTAG; i++) { - delete []pat[i]; - pat[i] = 0; + pat[i].clear(); bopat[i] = NOTFOUND; eopat[i] = NOTFOUND; } } -bool RESearch::GrabMatches(CharacterIndexer &ci) { - bool success = true; +void RESearch::GrabMatches(CharacterIndexer &ci) { for (unsigned int i = 0; i < MAXTAG; i++) { if ((bopat[i] != NOTFOUND) && (eopat[i] != NOTFOUND)) { unsigned int len = eopat[i] - bopat[i]; - pat[i] = new char[len + 1]; - if (pat[i]) { - for (unsigned int j = 0; j < len; j++) - pat[i][j] = ci.CharAt(bopat[i] + j); - pat[i][len] = '\0'; - } else { - success = false; - } + pat[i] = std::string(len+1, '\0'); + for (unsigned int j = 0; j < len; j++) + pat[i][j] = ci.CharAt(bopat[i] + j); + pat[i][len] = '\0'; } } - return success; } void RESearch::ChSet(unsigned char c) { diff --git a/src/RESearch.h b/src/RESearch.h index 5e1d34168..1f30ffb6d 100644 --- a/src/RESearch.h +++ b/src/RESearch.h @@ -33,7 +33,7 @@ class RESearch { public: RESearch(CharClassify *charClassTable); ~RESearch(); - bool GrabMatches(CharacterIndexer &ci); + void GrabMatches(CharacterIndexer &ci); const char *Compile(const char *pattern, int length, bool caseSensitive, bool posix); int Execute(CharacterIndexer &ci, int lp, int endp); @@ -43,7 +43,7 @@ public: int bopat[MAXTAG]; int eopat[MAXTAG]; - char *pat[MAXTAG]; + std::string pat[MAXTAG]; private: void Init(); |