diff options
| author | nyamatongwe <unknown> | 2011-08-03 11:20:46 +1000 |
|---|---|---|
| committer | nyamatongwe <unknown> | 2011-08-03 11:20:46 +1000 |
| commit | 1595153b9cc09514e7f16719694e999c1fd341e0 (patch) | |
| tree | b9eab1cddb49fa078025755af158bd9aec43d07e /lexlib/WordList.cxx | |
| parent | d3c506ee2553d7f1da5907f4d5f9589d26b175a9 (diff) | |
| parent | 61d58f8d3052da83e0e5d8e80d78f5ff0accd8fb (diff) | |
| download | scintilla-mirror-1595153b9cc09514e7f16719694e999c1fd341e0.tar.gz | |
Merged with mainline.
Diffstat (limited to 'lexlib/WordList.cxx')
| -rw-r--r-- | lexlib/WordList.cxx | 28 |
1 files changed, 21 insertions, 7 deletions
diff --git a/lexlib/WordList.cxx b/lexlib/WordList.cxx index cda35ece7..9c2c9653b 100644 --- a/lexlib/WordList.cxx +++ b/lexlib/WordList.cxx @@ -11,6 +11,8 @@ #include <stdio.h> #include <stdarg.h> +#include <algorithm> + #include "WordList.h" #ifdef SCI_NAMESPACE @@ -86,22 +88,34 @@ void WordList::Clear() { len = 0; } -extern "C" int cmpString(const void *a1, const void *a2) { - // Can't work out the correct incantation to use modern casts here - return strcmp(*(char **)(a1), *(char **)(a2)); +#ifdef _MSC_VER + +static bool cmpWords(const char *a, const char *b) { + return strcmp(a, b) == -1; +} + +#else + +static int cmpWords(const void *a, const void *b) { + return strcmp(*static_cast<const char * const *>(a), *static_cast<const char * const *>(b)); } static void SortWordList(char **words, unsigned int len) { - qsort(reinterpret_cast<void *>(words), len, sizeof(*words), - cmpString); + qsort(reinterpret_cast<void *>(words), len, sizeof(*words), cmpWords); } +#endif + void WordList::Set(const char *s) { Clear(); list = new char[strlen(s) + 1]; strcpy(list, s); words = ArrayFromWordList(list, &len, onlyLineEnds); +#ifdef _MSC_VER + std::sort(words, words + len, cmpWords); +#else SortWordList(words, len); +#endif for (unsigned int k = 0; k < (sizeof(starts) / sizeof(starts[0])); k++) starts[k] = -1; for (int l = len - 1; l >= 0; l--) { @@ -121,7 +135,7 @@ bool WordList::InList(const char *s) const { unsigned char firstChar = s[0]; int j = starts[firstChar]; if (j >= 0) { - while ((unsigned char)words[j][0] == firstChar) { + while (static_cast<unsigned char>(words[j][0]) == firstChar) { if (s[1] == words[j][1]) { const char *a = words[j] + 1; const char *b = s + 1; @@ -163,7 +177,7 @@ bool WordList::InListAbbreviated(const char *s, const char marker) const { unsigned char firstChar = s[0]; int j = starts[firstChar]; if (j >= 0) { - while (words[j][0] == firstChar) { + while (static_cast<unsigned char>(words[j][0]) == firstChar) { bool isSubword = false; int start = 1; if (words[j][1] == marker) { |
