aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authornyamatongwe <devnull@localhost>2001-02-06 01:01:40 +0000
committernyamatongwe <devnull@localhost>2001-02-06 01:01:40 +0000
commitc4a930a94d853bcf4e6eb5dc16c7335d4ef9bde7 (patch)
tree2c71cbade9643079714fac4fd5ca60b222bb3ee4
parent58a0a3c3400d034ff1f549671edd315bad1da618 (diff)
downloadscintilla-mirror-c4a930a94d853bcf4e6eb5dc16c7335d4ef9bde7.tar.gz
Removed macro substitution of case insensitive string comparison functions
and declared new functions CompareCaseInsensitive and CompareNCaseInsensitive implemented in Scintilla.
-rw-r--r--include/SString.h8
-rw-r--r--src/PropSet.cxx80
2 files changed, 53 insertions, 35 deletions
diff --git a/include/SString.h b/include/SString.h
index 29fed5fee..df9c88c83 100644
--- a/include/SString.h
+++ b/include/SString.h
@@ -7,13 +7,11 @@
#ifndef SSTRING_H
#define SSTRING_H
+// These functions are implemented because each platform calls them something different
+int CompareCaseInsensitive(const char *a, const char *b);
+int CompareNCaseInsensitive(const char *a, const char *b, int len);
bool EqualCaseInsensitive(const char *a, const char *b);
-#if PLAT_WIN
-#define strcasecmp stricmp
-#define strncasecmp strnicmp
-#endif
-
// Define another string class.
// While it would be 'better' to use std::string, that doubles the executable size.
// An SString may contain embedded nul characters.
diff --git a/src/PropSet.cxx b/src/PropSet.cxx
index fa26d3133..a29a4f6bb 100644
--- a/src/PropSet.cxx
+++ b/src/PropSet.cxx
@@ -14,34 +14,54 @@
#include "PropSet.h"
-bool EqualCaseInsensitive(const char *a, const char *b) {
-#if PLAT_GTK
-# ifdef G_OS_WIN32
- return 0 == stricmp(a, b);
-# else
- return 0 == strcasecmp(a, b);
-# endif
-#elif PLAT_WIN
- return 0 == stricmp(a, b);
-#elif PLAT_WX
- return 0 == wxStricmp(a, b);
-#endif
+// The comparison and case changing functions here assume ASCII
+// or extended ASCII such as the normal Windows code page.
+
+inline char MakeUpperCase(char ch) {
+ if (ch < 'a' || ch > 'z')
+ return ch;
+ else
+ return ch - 'a' + 'A';
+}
+
+int CompareCaseInsensitive(const char *a, const char *b) {
+ while (*a && *b) {
+ if (*a != *b) {
+ char upperA = MakeUpperCase(*a);
+ char upperB = MakeUpperCase(*b);
+ if (upperA != upperB)
+ return upperA - upperB;
+ }
+ a++;
+ b++;
+ }
+ // Either *a or *b is nul
+ return *a - *b;
}
-bool EqualNCaseInsensitive(const char *a, const char *b, int len) {
-#if PLAT_GTK
-# ifdef G_OS_WIN32
- return 0 == strnicmp(a, b, len);
-# else
- return 0 == strncasecmp(a, b, len);
-# endif
-#elif PLAT_WIN
- return 0 == strnicmp(a, b, len);
-#elif PLAT_WX
- return 0 == wxStrnicmp(a, b, len);
-#endif
+int CompareNCaseInsensitive(const char *a, const char *b, int len) {
+ while (*a && *b && len) {
+ if (*a != *b) {
+ char upperA = MakeUpperCase(*a);
+ char upperB = MakeUpperCase(*b);
+ if (upperA != upperB)
+ return upperA - upperB;
+ }
+ a++;
+ b++;
+ len--;
+ }
+ if (len == 0)
+ return 0;
+ else
+ // Either *a or *b is nul
+ return *a - *b;
}
-
+
+bool EqualCaseInsensitive(const char *a, const char *b) {
+ return 0 == CompareCaseInsensitive(a, b);
+}
+
inline unsigned int HashString(const char *s) {
unsigned int ret = 0;
while (*s) {
@@ -378,7 +398,7 @@ int cmpString(const void *a1, const void *a2) {
int cmpStringNoCase(const void *a1, const void *a2) {
// Can't work out the correct incantation to use modern casts here
- return EqualCaseInsensitive(*(char**)(a1), *(char**)(a2));
+ return CompareCaseInsensitive(*(char**)(a1), *(char**)(a2));
}
static void SortWordList(char **words, char **wordsNoCase, unsigned int len) {
@@ -443,7 +463,7 @@ const char *WordList::GetNearestWord(const char *wordStart, int searchLen /*= -1
while (start <= end) { // binary searching loop
pivot = (start + end) >> 1;
word = wordsNoCase[pivot];
- cond = EqualNCaseInsensitive(wordStart, word, searchLen);
+ cond = CompareNCaseInsensitive(wordStart, word, searchLen);
if (!cond && nonFuncChar(word[searchLen])) // maybe there should be a "non-word character" test here?
return word; // result must not be freed with free()
else if (cond >= 0)
@@ -503,7 +523,7 @@ char *WordList::GetNearestWords(const char *wordStart, int searchLen /*= -1*/, b
while (start <= end) { // binary searching loop
pivot = (start + end) >> 1;
word = wordsNoCase[pivot];
- cond = EqualNCaseInsensitive(wordStart, word, searchLen);
+ cond = CompareNCaseInsensitive(wordStart, word, searchLen);
if (!cond) {
oldpivot = pivot;
do { // browse sequentially the rest after the hit
@@ -538,14 +558,14 @@ char *WordList::GetNearestWords(const char *wordStart, int searchLen /*= -1*/, b
if (++pivot > end)
break;
word = wordsNoCase[pivot];
- } while (!EqualNCaseInsensitive(wordStart, word, searchLen));
+ } while (!CompareNCaseInsensitive(wordStart, word, searchLen));
pivot = oldpivot;
for (;;) { // browse sequentially the rest before the hit
if (--pivot < start)
break;
word = wordsNoCase[pivot];
- if (EqualNCaseInsensitive(wordStart, word, searchLen))
+ if (CompareNCaseInsensitive(wordStart, word, searchLen))
break;
brace = strchr(word, '(');
if (brace)