aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authornyamatongwe <devnull@localhost>2013-05-01 16:57:09 +1000
committernyamatongwe <devnull@localhost>2013-05-01 16:57:09 +1000
commitb1051ba9ece39aae86bed19c3c4b965ab5e86058 (patch)
tree7f61c9c9b711cfb2595ef586016b27a6b6b76758 /src
parentc43e2b6ff04039bf1564d56ae5065127fa52ee25 (diff)
downloadscintilla-mirror-b1051ba9ece39aae86bed19c3c4b965ab5e86058.tar.gz
Replacing raw pointer and allocation with std::string.
Diffstat (limited to 'src')
-rw-r--r--src/Document.cxx63
1 files changed, 16 insertions, 47 deletions
diff --git a/src/Document.cxx b/src/Document.cxx
index 10df07663..80f306c1a 100644
--- a/src/Document.cxx
+++ b/src/Document.cxx
@@ -2068,10 +2068,9 @@ int Document::BraceMatch(int position, int /*maxReStyle*/) {
*/
class BuiltinRegex : public RegexSearchBase {
public:
- BuiltinRegex(CharClassify *charClassTable) : search(charClassTable), substituted(NULL) {}
+ BuiltinRegex(CharClassify *charClassTable) : search(charClassTable) {}
virtual ~BuiltinRegex() {
- delete substituted;
}
virtual long FindText(Document *doc, int minPos, int maxPos, const char *s,
@@ -2082,7 +2081,7 @@ public:
private:
RESearch search;
- char *substituted;
+ std::string substituted;
};
// Define a way for the Regular Expression code to access the document
@@ -2204,86 +2203,56 @@ long BuiltinRegex::FindText(Document *doc, int minPos, int maxPos, const char *s
}
const char *BuiltinRegex::SubstituteByPosition(Document *doc, const char *text, int *length) {
- delete []substituted;
- substituted = 0;
+ substituted.clear();
DocumentIndexer di(doc, doc->Length());
if (!search.GrabMatches(di))
return 0;
- unsigned int lenResult = 0;
- for (int i = 0; i < *length; i++) {
- if (text[i] == '\\') {
- if (text[i + 1] >= '0' && text[i + 1] <= '9') {
- unsigned int patNum = text[i + 1] - '0';
- lenResult += search.eopat[patNum] - search.bopat[patNum];
- i++;
- } else {
- switch (text[i + 1]) {
- case 'a':
- case 'b':
- case 'f':
- case 'n':
- case 'r':
- case 't':
- case 'v':
- case '\\':
- i++;
- }
- lenResult++;
- }
- } else {
- lenResult++;
- }
- }
- substituted = new char[lenResult + 1];
- char *o = substituted;
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
- memcpy(o, search.pat[patNum], len);
- o += len;
+ substituted.append(search.pat[patNum], len);
j++;
} else {
j++;
switch (text[j]) {
case 'a':
- *o++ = '\a';
+ substituted.push_back('\a');
break;
case 'b':
- *o++ = '\b';
+ substituted.push_back('\b');
break;
case 'f':
- *o++ = '\f';
+ substituted.push_back('\f');
break;
case 'n':
- *o++ = '\n';
+ substituted.push_back('\n');
break;
case 'r':
- *o++ = '\r';
+ substituted.push_back('\r');
break;
case 't':
- *o++ = '\t';
+ substituted.push_back('\t');
break;
case 'v':
- *o++ = '\v';
+ substituted.push_back('\v');
break;
case '\\':
- *o++ = '\\';
+ substituted.push_back('\\');
break;
default:
- *o++ = '\\';
+ substituted.push_back('\\');
j--;
}
}
} else {
- *o++ = text[j];
+ substituted.push_back(text[j]);
}
}
- *o = '\0';
- *length = lenResult;
- return substituted;
+ *length = static_cast<int>(substituted.length());
+ return substituted.c_str();
}
#ifndef SCI_OWNREGEX