diff options
| author | nyamatongwe <devnull@localhost> | 2001-08-02 13:32:53 +0000 | 
|---|---|---|
| committer | nyamatongwe <devnull@localhost> | 2001-08-02 13:32:53 +0000 | 
| commit | 54cc8addc03070dc4cbeb341698a7f86d273058d (patch) | |
| tree | 08d572e7770c6b1ae6990e3b8109f67d91f928c8 /src/PropSet.cxx | |
| parent | ca904cd869505fe6ca3d1420ff64eabdc694890e (diff) | |
| download | scintilla-mirror-54cc8addc03070dc4cbeb341698a7f86d273058d.tar.gz | |
Simplified GetNearestWords and ensured returned list of words is in sorted
order.
Diffstat (limited to 'src/PropSet.cxx')
| -rw-r--r-- | src/PropSet.cxx | 90 | 
1 files changed, 39 insertions, 51 deletions
| diff --git a/src/PropSet.cxx b/src/PropSet.cxx index 5287fb36b..701b2a82c 100644 --- a/src/PropSet.cxx +++ b/src/PropSet.cxx @@ -646,8 +646,6 @@ char *WordList::GetNearestWords(  	int end = len - 1; // upper bound of the api array block to search  	int pivot; // index of api array element just being compared  	int cond; // comparison result (in the sense of strcmp() result) -	int oldpivot; // pivot storage to be able to browse the api array upwards and then downwards -	const char *word; // api array element just being compared  	if (0 == words)  		return NULL; @@ -656,66 +654,56 @@ char *WordList::GetNearestWords(  		SortWordList(words, wordsNoCase, len);  	}  	if (ignoreCase) { -		while (start <= end) { // binary searching loop -			pivot = (start + end) >> 1; -			word = wordsNoCase[pivot]; -			cond = CompareNCaseInsensitive(wordStart, word, searchLen); +		while (start <= end) { // Binary searching loop +			pivot = (start + end) / 2; +			cond = CompareNCaseInsensitive(wordStart, wordsNoCase[pivot], searchLen);  			if (!cond) { -				oldpivot = pivot; -				do { // browse sequentially the rest after the hit -					wordlen = LengthWord(word, otherSeparator) + 1; -					wordsNear.append(word, wordlen, ' '); -					if (++pivot > end) -						break; -					word = wordsNoCase[pivot]; -				} while (!CompareNCaseInsensitive(wordStart, word, searchLen)); - -				pivot = oldpivot; -				for (;;) { // browse sequentially the rest before the hit -					if (--pivot < start) -						break; -					word = wordsNoCase[pivot]; -					if (CompareNCaseInsensitive(wordStart, word, searchLen)) -						break; -					wordlen = LengthWord(word, otherSeparator) + 1; -					wordsNear.append(word, wordlen, ' '); +				// Find first match +				while ((pivot > start) && +					(0 == CompareNCaseInsensitive(wordStart,  +						wordsNoCase[pivot-1], searchLen))) { +					--pivot; +				} +				// Grab each match +				while ((pivot <= end) && +					(0 == CompareNCaseInsensitive(wordStart,  +						wordsNoCase[pivot], searchLen))) { +					wordlen = LengthWord(wordsNoCase[pivot], otherSeparator) + 1; +					wordsNear.append(wordsNoCase[pivot], wordlen, ' '); +					++pivot;  				}  				return wordsNear.detach(); -			} else if (cond < 0) +			} else if (cond < 0) {  				end = pivot - 1; -			else if (cond > 0) +			} else if (cond > 0) {  				start = pivot + 1; +			}  		} -	} else {	// preserve the letter case -		while (start <= end) { // binary searching loop -			pivot = (start + end) >> 1; -			word = words[pivot]; -			cond = strncmp(wordStart, word, searchLen); +	} else {	// Preserve the letter case +		while (start <= end) { // Binary searching loop +			pivot = (start + end) / 2; +			cond = strncmp(wordStart, words[pivot], searchLen);  			if (!cond) { -				oldpivot = pivot; -				do { // browse sequentially the rest after the hit -					wordlen = LengthWord(word, otherSeparator) + 1; -					wordsNear.append(word, wordlen, ' '); -					if (++pivot > end) -						break; -					word = words[pivot]; -				} while (!strncmp(wordStart, word, searchLen)); - -				pivot = oldpivot; -				for (;;) { // browse sequentially the rest before the hit -					if (--pivot < start) -						break; -					word = words[pivot]; -					if (strncmp(wordStart, word, searchLen)) -						break; -					wordlen = LengthWord(word, otherSeparator) + 1; -					wordsNear.append(word, wordlen, ' '); +				// Find first match +				while ((pivot > start) && +					(0 == strncmp(wordStart,  +						words[pivot-1], searchLen))) {  +					--pivot; +				} +				// Grab each match +				while ((pivot <= end) && +					(0 == strncmp(wordStart,  +						words[pivot], searchLen))) {  +					wordlen = LengthWord(words[pivot], otherSeparator) + 1; +					wordsNear.append(words[pivot], wordlen, ' '); +					++pivot;  				}  				return wordsNear.detach(); -			} else if (cond < 0) +			} else if (cond < 0) {  				end = pivot - 1; -			else if (cond > 0) +			} else if (cond > 0) {  				start = pivot + 1; +			}  		}  	}  	return NULL; | 
