aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authornyamatongwe <unknown>2003-09-05 22:31:58 +0000
committernyamatongwe <unknown>2003-09-05 22:31:58 +0000
commit859545982c18e80ab3ec1372c14a64d1529b4fcb (patch)
tree98947fa9696a6a6f35607683711c9ab624dcb0dd
parenta4d533628e2a0a9d8c597b1a7128e2f039d4b19f (diff)
downloadscintilla-mirror-859545982c18e80ab3ec1372c14a64d1529b4fcb.tar.gz
Patch from Marius Gheorghe to support multiple equivalent entries in
WordList.
-rw-r--r--include/PropSet.h2
-rw-r--r--src/PropSet.cxx58
2 files changed, 55 insertions, 5 deletions
diff --git a/include/PropSet.h b/include/PropSet.h
index 20ac5f774..62cd5da3a 100644
--- a/include/PropSet.h
+++ b/include/PropSet.h
@@ -81,7 +81,7 @@ public:
void SetFromAllocated();
bool InList(const char *s);
const char *GetNearestWord(const char *wordStart, int searchLen = -1,
- bool ignoreCase = false, SString wordCharacters="");
+ bool ignoreCase = false, SString wordCharacters="", int wordIndex = -1);
char *GetNearestWords(const char *wordStart, int searchLen=-1,
bool ignoreCase=false, char otherSeparator='\0');
};
diff --git a/src/PropSet.cxx b/src/PropSet.cxx
index 021a65727..658d5046a 100644
--- a/src/PropSet.cxx
+++ b/src/PropSet.cxx
@@ -562,7 +562,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' */) {
+const char *WordList::GetNearestWord(const char *wordStart, int searchLen /*= -1*/, 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
@@ -580,8 +580,33 @@ 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])))
+ 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()
+
+ // Finds first word in a series of equal words
+ int first = pivot;
+ end = pivot - 1;
+ while (start <= end) {
+ pivot = (start + end) >> 1;
+ word = wordsNoCase[pivot];
+ cond = CompareNCaseInsensitive(wordStart, word, searchLen);
+ if (!cond && (!wordCharacters.contains(word[searchLen]))) {
+ // Found another word
+ first = pivot;
+ end = pivot - 1;
+ }
+ 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;
+ }
else if (cond > 0)
start = pivot + 1;
else if (cond <= 0)
@@ -592,8 +617,33 @@ 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])))
- return word; // result must not be freed with free()
+ 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()
+
+ // Finds first word in a series of equal words
+ int first = pivot;
+ end = pivot - 1;
+ while (start <= end) {
+ pivot = (start + end) >> 1;
+ word = words[pivot];
+ cond = strncmp(wordStart, word, searchLen);
+ if (!cond && (!wordCharacters.contains(word[searchLen]))) {
+ // Found another word
+ first = pivot;
+ end = pivot - 1;
+ }
+ else if (cond > 0)
+ start = pivot + 1;
+ else if (cond <= 0)
+ break;
+ }
+
+ // Gets the word at the requested index
+ word = words[first + wordIndex];
+ return word;
+ }
else if (cond > 0)
start = pivot + 1;
else if (cond <= 0)