diff options
author | nyamatongwe <unknown> | 2004-09-19 03:49:44 +0000 |
---|---|---|
committer | nyamatongwe <unknown> | 2004-09-19 03:49:44 +0000 |
commit | baf65874491fb3c51c6ff1b29bae6f5c61d1e88c (patch) | |
tree | 8a7f801501cd58b2ef0fbde9f8b068d57858fb4d | |
parent | d6fb2b9fb83826e29d0ef4af9abd0a26e64247cd (diff) | |
download | scintilla-mirror-baf65874491fb3c51c6ff1b29bae6f5c61d1e88c.tar.gz |
Patch to autocompletion from Jakub Vrana to handle cases where
word characters are greater than the start of parameters character.
-rw-r--r-- | include/PropSet.h | 4 | ||||
-rw-r--r-- | src/PropSet.cxx | 102 |
2 files changed, 50 insertions, 56 deletions
diff --git a/include/PropSet.h b/include/PropSet.h index 69f4c4b78..32aea8a0c 100644 --- a/include/PropSet.h +++ b/include/PropSet.h @@ -87,9 +87,9 @@ public: char *Allocate(int size); void SetFromAllocated(); bool InList(const char *s); - const char *GetNearestWord(const char *wordStart, int searchLen = -1, + const char *GetNearestWord(const char *wordStart, int searchLen, bool ignoreCase = false, SString wordCharacters="", int wordIndex = -1); - char *GetNearestWords(const char *wordStart, int searchLen=-1, + char *GetNearestWords(const char *wordStart, int searchLen, bool ignoreCase=false, char otherSeparator='\0', bool exactLen=false); }; diff --git a/src/PropSet.cxx b/src/PropSet.cxx index 3711c03c8..1e9920d79 100644 --- a/src/PropSet.cxx +++ b/src/PropSet.cxx @@ -883,7 +883,7 @@ bool WordList::InList(const char *s) { * The length of the word to compare is passed too. * Letter case can be ignored or preserved (default). */ -const char *WordList::GetNearestWord(const char *wordStart, int searchLen /*= -1*/, bool ignoreCase /*= false*/, SString wordCharacters /*='/0' */, int wordIndex /*= -1 */) { +const char *WordList::GetNearestWord(const char *wordStart, int searchLen, bool ignoreCase /*= false*/, SString wordCharacters /*='/0' */, int wordIndex /*= -1 */) { int start = 0; // lower bound of the api array block to search int end = len - 1; // upper bound of the api array block to search int pivot; // index of api array element just being compared @@ -901,36 +901,32 @@ const char *WordList::GetNearestWord(const char *wordStart, int searchLen /*= -1 pivot = (start + end) >> 1; word = wordsNoCase[pivot]; cond = CompareNCaseInsensitive(wordStart, word, searchLen); - if (!cond && (!wordCharacters.contains(word[searchLen]))) { - // Found a word in a binary fashion. Now checks if a specific index was requested - if (wordIndex < 0) - return word; // result must not be freed with free() - + if (!cond) { + // find first word + start = pivot; + while (start > 0 && !CompareNCaseInsensitive(wordStart, wordsNoCase[start-1], searchLen)) { + start--; + } + // find last word + end = pivot; + while (end < len-1 && !CompareNCaseInsensitive(wordStart, wordsNoCase[end+1], searchLen)) { + end++; + } + // Finds first word in a series of equal words - int first = pivot; - end = pivot - 1; - while (start <= end) { - pivot = (start + end) >> 1; + for (pivot = start; pivot <= end; pivot++) { word = wordsNoCase[pivot]; - cond = CompareNCaseInsensitive(wordStart, word, searchLen); - if (!cond && (!wordCharacters.contains(word[searchLen]))) { - // Found another word - first = pivot; - end = pivot - 1; + if (!wordCharacters.contains(word[searchLen])) { + if (wordIndex <= 0) // Checks if a specific index was requested + return word; // result must not be freed with free() + wordIndex--; } - else if (cond > 0) - start = pivot + 1; - else if (cond <= 0) - break; } - - // Gets the word at the requested index - word = wordsNoCase[first + wordIndex]; - return word; + return NULL; } else if (cond > 0) start = pivot + 1; - else if (cond <= 0) + else if (cond < 0) end = pivot - 1; } } else { // preserve the letter case @@ -938,36 +934,34 @@ const char *WordList::GetNearestWord(const char *wordStart, int searchLen /*= -1 pivot = (start + end) >> 1; word = words[pivot]; cond = strncmp(wordStart, word, searchLen); - if (!cond && (!wordCharacters.contains(word[searchLen]))) { - // Found a word in a binary fashion. Now checks if a specific index was requested - if (wordIndex < 0) - return word; // result must not be freed with free() - + if (!cond) { + // find first word + start = pivot; + while (start > 0 && !strncmp(wordStart, words[start-1], searchLen)) { + start--; + } + // find last word + end = pivot; + while (end < len-1 && !strncmp(wordStart, words[end+1], searchLen)) { + end++; + } + // Finds first word in a series of equal words - int first = pivot; - end = pivot - 1; - while (start <= end) { - pivot = (start + end) >> 1; + pivot = start; + while (pivot <= end) { word = words[pivot]; - cond = strncmp(wordStart, word, searchLen); - if (!cond && (!wordCharacters.contains(word[searchLen]))) { - // Found another word - first = pivot; - end = pivot - 1; + if (!wordCharacters.contains(word[searchLen])) { + if (wordIndex <= 0) // Checks if a specific index was requested + return word; // result must not be freed with free() + wordIndex--; } - else if (cond > 0) - start = pivot + 1; - else if (cond <= 0) - break; + pivot++; } - - // Gets the word at the requested index - word = words[first + wordIndex]; - return word; + return NULL; } else if (cond > 0) start = pivot + 1; - else if (cond <= 0) + else if (cond < 0) end = pivot - 1; } } @@ -1012,7 +1006,7 @@ static unsigned int LengthWord(const char *word, char otherSeparator) { */ char *WordList::GetNearestWords( const char *wordStart, - int searchLen /*= -1*/, + int searchLen, bool ignoreCase /*= false*/, char otherSeparator /*= '\0'*/, bool exactLen /*=false*/) { @@ -1046,10 +1040,10 @@ char *WordList::GetNearestWords( (0 == CompareNCaseInsensitive(wordStart, wordsNoCase[pivot], searchLen))) { wordlen = LengthWord(wordsNoCase[pivot], otherSeparator) + 1; - if (exactLen && wordlen != LengthWord(wordStart, otherSeparator) + 1) - break; - wordsNear.append(wordsNoCase[pivot], wordlen, ' '); ++pivot; + if (exactLen && wordlen != LengthWord(wordStart, otherSeparator) + 1) + continue; + wordsNear.append(wordsNoCase[pivot-1], wordlen, ' '); } return wordsNear.detach(); } else if (cond < 0) { @@ -1074,10 +1068,10 @@ char *WordList::GetNearestWords( (0 == strncmp(wordStart, words[pivot], searchLen))) { wordlen = LengthWord(words[pivot], otherSeparator) + 1; - if (exactLen && wordlen != LengthWord(wordStart, otherSeparator) + 1) - break; - wordsNear.append(words[pivot], wordlen, ' '); ++pivot; + if (exactLen && wordlen != LengthWord(wordStart, otherSeparator) + 1) + continue; + wordsNear.append(words[pivot-1], wordlen, ' '); } return wordsNear.detach(); } else if (cond < 0) { |