A fix for Scintilla's case insensitive sort routine
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@12051 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -26,13 +26,23 @@ static inline char MakeUpperCase(char ch) {
|
|||||||
return static_cast<char>(ch - 'a' + 'A');
|
return static_cast<char>(ch - 'a' + 'A');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline bool IsLetter(char ch) {
|
||||||
|
return ((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z'));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
int CompareCaseInsensitive(const char *a, const char *b) {
|
int CompareCaseInsensitive(const char *a, const char *b) {
|
||||||
while (*a && *b) {
|
while (*a && *b) {
|
||||||
if (*a != *b) {
|
if (*a != *b) {
|
||||||
char upperA = MakeUpperCase(*a);
|
if (IsLetter(*a) && IsLetter(*b)) {
|
||||||
char upperB = MakeUpperCase(*b);
|
char upperA = MakeUpperCase(*a);
|
||||||
if (upperA != upperB)
|
char upperB = MakeUpperCase(*b);
|
||||||
return upperA - upperB;
|
if (upperA != upperB)
|
||||||
|
return upperA - upperB;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return *a - *b;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
a++;
|
a++;
|
||||||
b++;
|
b++;
|
||||||
@@ -44,10 +54,15 @@ int CompareCaseInsensitive(const char *a, const char *b) {
|
|||||||
int CompareNCaseInsensitive(const char *a, const char *b, int len) {
|
int CompareNCaseInsensitive(const char *a, const char *b, int len) {
|
||||||
while (*a && *b && len) {
|
while (*a && *b && len) {
|
||||||
if (*a != *b) {
|
if (*a != *b) {
|
||||||
char upperA = MakeUpperCase(*a);
|
if (IsLetter(*a) && IsLetter(*b)) {
|
||||||
char upperB = MakeUpperCase(*b);
|
char upperA = MakeUpperCase(*a);
|
||||||
if (upperA != upperB)
|
char upperB = MakeUpperCase(*b);
|
||||||
return upperA - upperB;
|
if (upperA != upperB)
|
||||||
|
return upperA - upperB;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return *a - *b;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
a++;
|
a++;
|
||||||
b++;
|
b++;
|
||||||
@@ -94,8 +109,8 @@ void PropSet::Set(const char *key, const char *val, int lenKey, int lenVal) {
|
|||||||
lenVal = strlen(val);
|
lenVal = strlen(val);
|
||||||
unsigned int hash = HashString(key, lenKey);
|
unsigned int hash = HashString(key, lenKey);
|
||||||
for (Property *p = props[hash % hashRoots]; p; p = p->next) {
|
for (Property *p = props[hash % hashRoots]; p; p = p->next) {
|
||||||
if ((hash == p->hash) &&
|
if ((hash == p->hash) &&
|
||||||
((strlen(p->key) == static_cast<unsigned int>(lenKey)) &&
|
((strlen(p->key) == static_cast<unsigned int>(lenKey)) &&
|
||||||
(0 == strncmp(p->key, key, lenKey)))) {
|
(0 == strncmp(p->key, key, lenKey)))) {
|
||||||
// Replace current value
|
// Replace current value
|
||||||
delete [](p->val);
|
delete [](p->val);
|
||||||
@@ -660,13 +675,13 @@ char *WordList::GetNearestWords(
|
|||||||
if (!cond) {
|
if (!cond) {
|
||||||
// Find first match
|
// Find first match
|
||||||
while ((pivot > start) &&
|
while ((pivot > start) &&
|
||||||
(0 == CompareNCaseInsensitive(wordStart,
|
(0 == CompareNCaseInsensitive(wordStart,
|
||||||
wordsNoCase[pivot-1], searchLen))) {
|
wordsNoCase[pivot-1], searchLen))) {
|
||||||
--pivot;
|
--pivot;
|
||||||
}
|
}
|
||||||
// Grab each match
|
// Grab each match
|
||||||
while ((pivot <= end) &&
|
while ((pivot <= end) &&
|
||||||
(0 == CompareNCaseInsensitive(wordStart,
|
(0 == CompareNCaseInsensitive(wordStart,
|
||||||
wordsNoCase[pivot], searchLen))) {
|
wordsNoCase[pivot], searchLen))) {
|
||||||
wordlen = LengthWord(wordsNoCase[pivot], otherSeparator) + 1;
|
wordlen = LengthWord(wordsNoCase[pivot], otherSeparator) + 1;
|
||||||
wordsNear.append(wordsNoCase[pivot], wordlen, ' ');
|
wordsNear.append(wordsNoCase[pivot], wordlen, ' ');
|
||||||
@@ -686,14 +701,14 @@ char *WordList::GetNearestWords(
|
|||||||
if (!cond) {
|
if (!cond) {
|
||||||
// Find first match
|
// Find first match
|
||||||
while ((pivot > start) &&
|
while ((pivot > start) &&
|
||||||
(0 == strncmp(wordStart,
|
(0 == strncmp(wordStart,
|
||||||
words[pivot-1], searchLen))) {
|
words[pivot-1], searchLen))) {
|
||||||
--pivot;
|
--pivot;
|
||||||
}
|
}
|
||||||
// Grab each match
|
// Grab each match
|
||||||
while ((pivot <= end) &&
|
while ((pivot <= end) &&
|
||||||
(0 == strncmp(wordStart,
|
(0 == strncmp(wordStart,
|
||||||
words[pivot], searchLen))) {
|
words[pivot], searchLen))) {
|
||||||
wordlen = LengthWord(words[pivot], otherSeparator) + 1;
|
wordlen = LengthWord(words[pivot], otherSeparator) + 1;
|
||||||
wordsNear.append(words[pivot], wordlen, ' ');
|
wordsNear.append(words[pivot], wordlen, ' ');
|
||||||
++pivot;
|
++pivot;
|
||||||
|
@@ -26,13 +26,23 @@ static inline char MakeUpperCase(char ch) {
|
|||||||
return static_cast<char>(ch - 'a' + 'A');
|
return static_cast<char>(ch - 'a' + 'A');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline bool IsLetter(char ch) {
|
||||||
|
return ((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z'));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
int CompareCaseInsensitive(const char *a, const char *b) {
|
int CompareCaseInsensitive(const char *a, const char *b) {
|
||||||
while (*a && *b) {
|
while (*a && *b) {
|
||||||
if (*a != *b) {
|
if (*a != *b) {
|
||||||
char upperA = MakeUpperCase(*a);
|
if (IsLetter(*a) && IsLetter(*b)) {
|
||||||
char upperB = MakeUpperCase(*b);
|
char upperA = MakeUpperCase(*a);
|
||||||
if (upperA != upperB)
|
char upperB = MakeUpperCase(*b);
|
||||||
return upperA - upperB;
|
if (upperA != upperB)
|
||||||
|
return upperA - upperB;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return *a - *b;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
a++;
|
a++;
|
||||||
b++;
|
b++;
|
||||||
@@ -44,10 +54,15 @@ int CompareCaseInsensitive(const char *a, const char *b) {
|
|||||||
int CompareNCaseInsensitive(const char *a, const char *b, int len) {
|
int CompareNCaseInsensitive(const char *a, const char *b, int len) {
|
||||||
while (*a && *b && len) {
|
while (*a && *b && len) {
|
||||||
if (*a != *b) {
|
if (*a != *b) {
|
||||||
char upperA = MakeUpperCase(*a);
|
if (IsLetter(*a) && IsLetter(*b)) {
|
||||||
char upperB = MakeUpperCase(*b);
|
char upperA = MakeUpperCase(*a);
|
||||||
if (upperA != upperB)
|
char upperB = MakeUpperCase(*b);
|
||||||
return upperA - upperB;
|
if (upperA != upperB)
|
||||||
|
return upperA - upperB;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return *a - *b;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
a++;
|
a++;
|
||||||
b++;
|
b++;
|
||||||
@@ -94,8 +109,8 @@ void PropSet::Set(const char *key, const char *val, int lenKey, int lenVal) {
|
|||||||
lenVal = strlen(val);
|
lenVal = strlen(val);
|
||||||
unsigned int hash = HashString(key, lenKey);
|
unsigned int hash = HashString(key, lenKey);
|
||||||
for (Property *p = props[hash % hashRoots]; p; p = p->next) {
|
for (Property *p = props[hash % hashRoots]; p; p = p->next) {
|
||||||
if ((hash == p->hash) &&
|
if ((hash == p->hash) &&
|
||||||
((strlen(p->key) == static_cast<unsigned int>(lenKey)) &&
|
((strlen(p->key) == static_cast<unsigned int>(lenKey)) &&
|
||||||
(0 == strncmp(p->key, key, lenKey)))) {
|
(0 == strncmp(p->key, key, lenKey)))) {
|
||||||
// Replace current value
|
// Replace current value
|
||||||
delete [](p->val);
|
delete [](p->val);
|
||||||
@@ -660,13 +675,13 @@ char *WordList::GetNearestWords(
|
|||||||
if (!cond) {
|
if (!cond) {
|
||||||
// Find first match
|
// Find first match
|
||||||
while ((pivot > start) &&
|
while ((pivot > start) &&
|
||||||
(0 == CompareNCaseInsensitive(wordStart,
|
(0 == CompareNCaseInsensitive(wordStart,
|
||||||
wordsNoCase[pivot-1], searchLen))) {
|
wordsNoCase[pivot-1], searchLen))) {
|
||||||
--pivot;
|
--pivot;
|
||||||
}
|
}
|
||||||
// Grab each match
|
// Grab each match
|
||||||
while ((pivot <= end) &&
|
while ((pivot <= end) &&
|
||||||
(0 == CompareNCaseInsensitive(wordStart,
|
(0 == CompareNCaseInsensitive(wordStart,
|
||||||
wordsNoCase[pivot], searchLen))) {
|
wordsNoCase[pivot], searchLen))) {
|
||||||
wordlen = LengthWord(wordsNoCase[pivot], otherSeparator) + 1;
|
wordlen = LengthWord(wordsNoCase[pivot], otherSeparator) + 1;
|
||||||
wordsNear.append(wordsNoCase[pivot], wordlen, ' ');
|
wordsNear.append(wordsNoCase[pivot], wordlen, ' ');
|
||||||
@@ -686,14 +701,14 @@ char *WordList::GetNearestWords(
|
|||||||
if (!cond) {
|
if (!cond) {
|
||||||
// Find first match
|
// Find first match
|
||||||
while ((pivot > start) &&
|
while ((pivot > start) &&
|
||||||
(0 == strncmp(wordStart,
|
(0 == strncmp(wordStart,
|
||||||
words[pivot-1], searchLen))) {
|
words[pivot-1], searchLen))) {
|
||||||
--pivot;
|
--pivot;
|
||||||
}
|
}
|
||||||
// Grab each match
|
// Grab each match
|
||||||
while ((pivot <= end) &&
|
while ((pivot <= end) &&
|
||||||
(0 == strncmp(wordStart,
|
(0 == strncmp(wordStart,
|
||||||
words[pivot], searchLen))) {
|
words[pivot], searchLen))) {
|
||||||
wordlen = LengthWord(words[pivot], otherSeparator) + 1;
|
wordlen = LengthWord(words[pivot], otherSeparator) + 1;
|
||||||
wordsNear.append(words[pivot], wordlen, ' ');
|
wordsNear.append(words[pivot], wordlen, ' ');
|
||||||
++pivot;
|
++pivot;
|
||||||
|
Reference in New Issue
Block a user