Fix buffer error in find message. Add binary, octal, decimal escape sequences for extended search
git-svn-id: svn://svn.tuxfamily.org/svnroot/notepadplus/repository@180 f5eea248-9336-0410-98b8-ebc06183d4e3
This commit is contained in:
parent
a1b8647714
commit
92d4080546
@ -24,13 +24,17 @@
|
||||
|
||||
int Searching::convertExtendedToString(const char * query, char * result, int length) { //query may equal to result, since it always gets smaller
|
||||
int i = 0, j = 0;
|
||||
int charLeft = length;
|
||||
bool isGood = true;
|
||||
char token;
|
||||
char current;
|
||||
while(i < length) { //because the backslash escape quences always reduce the size of the string, no overflow checks have to be made for target, assuming parameters are correct
|
||||
if (query[i] == '\\') { //possible escape sequence
|
||||
current = query[i];
|
||||
charLeft--;
|
||||
if (current == '\\' && charLeft) { //possible escape sequence
|
||||
i++;
|
||||
token = query[i];
|
||||
switch(token) {
|
||||
charLeft--;
|
||||
current = query[i];
|
||||
switch(current) {
|
||||
case 'r':
|
||||
result[j] = '\r';
|
||||
break;
|
||||
@ -46,10 +50,34 @@ int Searching::convertExtendedToString(const char * query, char * result, int le
|
||||
case '\\':
|
||||
result[j] = '\\';
|
||||
break;
|
||||
case 'b':
|
||||
case 'd':
|
||||
case 'o':
|
||||
case 'x': {
|
||||
int size = 0, base = 0;
|
||||
if (current == 'b') { //11111111
|
||||
size = 8, base = 2;
|
||||
} else if (current == '0') { //377
|
||||
size = 3, base = 8;
|
||||
} else if (current == 'd') { //255
|
||||
size = 3, base = 10;
|
||||
} else if (current == 'x') { //0xFF
|
||||
size = 2, base = 16;
|
||||
}
|
||||
if (charLeft >= size) {
|
||||
int res = 0;
|
||||
if (Searching::readBase(query+(i+1), &res, base, size)) {
|
||||
result[j] = (char)res;
|
||||
i+=size;
|
||||
break;
|
||||
}
|
||||
}
|
||||
//not enough chars to make parameter, use default method as fallback
|
||||
}
|
||||
default: { //unknown sequence, treat as regular text
|
||||
result[j] = '\\';
|
||||
j++;
|
||||
result[j] = token;
|
||||
result[j] = current;
|
||||
isGood = false;
|
||||
break;
|
||||
}
|
||||
@ -64,6 +92,25 @@ int Searching::convertExtendedToString(const char * query, char * result, int le
|
||||
return j;
|
||||
}
|
||||
|
||||
bool Searching::readBase(const char * string, int * value, int base, int size) {
|
||||
int i = 0, temp = 0;
|
||||
*value = 0;
|
||||
char max = '0' + base - 1;
|
||||
char current;
|
||||
while(i < size) {
|
||||
current = string[i];
|
||||
if (current >= '0' && current <= max) {
|
||||
temp *= base;
|
||||
temp += (current - '0');
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
*value = temp;
|
||||
return true;
|
||||
}
|
||||
|
||||
int Searching::buildSearchFlags(FindOption * option) {
|
||||
int flags = (option->_isWholeWord ? SCFIND_WHOLEWORD : 0) |
|
||||
(option->_isMatchCase ? SCFIND_MATCHCASE : 0) |
|
||||
@ -790,9 +837,10 @@ bool FindReplaceDlg::processFindNext(const char *txt2find, FindOption *options)
|
||||
|
||||
if (!pOptions->_isIncremental) { //incremental search doesnt trigger messages
|
||||
const char stringMaxSize = 64;
|
||||
char message[30 + stringMaxSize + 5]; //message, string, dots
|
||||
strcpy(message, "Can't find the text:\r\n");
|
||||
char message[30 + stringMaxSize + 4]; //message, string, dots
|
||||
strcpy(message, "Can't find the text:\r\n\"");
|
||||
strncat(message, pText, stringMaxSize);
|
||||
strcat(message, "\"");
|
||||
if (strlen(pText) > stringMaxSize) {
|
||||
strcat(message, "...");
|
||||
}
|
||||
|
@ -76,6 +76,8 @@ public:
|
||||
static int convertExtendedToString(const char * query, char * result, int length);
|
||||
static TargetRange t;
|
||||
static int buildSearchFlags(FindOption * option);
|
||||
private:
|
||||
static bool readBase(const char * string, int * value, int base, int size);
|
||||
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user