aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authornyamatongwe <devnull@localhost>2013-05-04 17:45:47 +1000
committernyamatongwe <devnull@localhost>2013-05-04 17:45:47 +1000
commit7c9825172c1391a699a5275b1473e285429e22e8 (patch)
treeebf9b0f0a7a6544cecb8e112f88950fdb7a6cb8e
parentb06956e4248bd4222576d35d8827c65b09fcd9d7 (diff)
downloadscintilla-mirror-7c9825172c1391a699a5275b1473e285429e22e8.tar.gz
Replacing raw pointers and allocations with std::string.
-rw-r--r--src/Document.cxx7
-rw-r--r--src/RESearch.cxx23
-rw-r--r--src/RESearch.h4
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();