]>
git.saurik.com Git - wxWidgets.git/blob - src/stc/scintilla/src/PropSet.cxx
d0a7f8b0f7f1c8ff6b69637e9a7d2aa7466d3b1f
1 // SciTE - Scintilla based Text Editor
3 ** A Java style properties file module.
5 // Copyright 1998-2003 by Neil Hodgson <neilh@scintilla.org>
6 // The License.txt file describes the conditions under which this software may be distributed.
8 // Maintain a dictionary of properties
18 // The comparison and case changing functions here assume ASCII
19 // or extended ASCII such as the normal Windows code page.
21 static inline char MakeUpperCase(char ch
) {
22 if (ch
< 'a' || ch
> 'z')
25 return static_cast<char>(ch
- 'a' + 'A');
28 static inline bool IsLetter(char ch
) {
29 return ((ch
>= 'a' && ch
<= 'z') || (ch
>= 'A' && ch
<= 'Z'));
32 inline bool IsASpace(unsigned int ch
) {
33 return (ch
== ' ') || ((ch
>= 0x09) && (ch
<= 0x0d));
36 int CompareCaseInsensitive(const char *a
, const char *b
) {
39 char upperA
= MakeUpperCase(*a
);
40 char upperB
= MakeUpperCase(*b
);
42 return upperA
- upperB
;
47 // Either *a or *b is nul
51 int CompareNCaseInsensitive(const char *a
, const char *b
, size_t len
) {
52 while (*a
&& *b
&& len
) {
54 char upperA
= MakeUpperCase(*a
);
55 char upperB
= MakeUpperCase(*b
);
57 return upperA
- upperB
;
66 // Either *a or *b is nul
70 bool EqualCaseInsensitive(const char *a
, const char *b
) {
71 return 0 == CompareCaseInsensitive(a
, b
);
74 // Since the CaseInsensitive functions declared in SString
75 // are implemented here, I will for now put the non-inline
76 // implementations of the SString members here as well, so
77 // that I can quickly see what effect this has.
79 SString::SString(int i
) : sizeGrowth(sizeGrowthDefault
) {
81 sprintf(number
, "%0d", i
);
82 s
= StringAllocate(number
);
83 sSize
= sLen
= (s
) ? strlen(s
) : 0;
86 SString::SString(double d
, int precision
) : sizeGrowth(sizeGrowthDefault
) {
88 sprintf(number
, "%.*f", precision
, d
);
89 s
= StringAllocate(number
);
90 sSize
= sLen
= (s
) ? strlen(s
) : 0;
93 bool SString::grow(lenpos_t lenNew
) {
94 while (sizeGrowth
* 6 < lenNew
) {
97 char *sNew
= new char[lenNew
+ sizeGrowth
+ 1];
100 memcpy(sNew
, s
, sLen
);
105 sSize
= lenNew
+ sizeGrowth
;
110 SString
&SString::assign(const char *sOther
, lenpos_t sSize_
) {
113 } else if (sSize_
== measure_length
) {
114 sSize_
= strlen(sOther
);
116 if (sSize
> 0 && sSize_
<= sSize
) { // Does not allocate new buffer if the current is big enough
118 memcpy(s
, sOther
, sSize_
);
124 s
= StringAllocate(sOther
, sSize_
);
126 sSize
= sSize_
; // Allow buffer bigger than real string, thus providing space to grow
135 bool SString::operator==(const SString
&sOther
) const {
136 if ((s
== 0) && (sOther
.s
== 0))
138 if ((s
== 0) || (sOther
.s
== 0))
140 return strcmp(s
, sOther
.s
) == 0;
143 bool SString::operator==(const char *sOther
) const {
144 if ((s
== 0) && (sOther
== 0))
146 if ((s
== 0) || (sOther
== 0))
148 return strcmp(s
, sOther
) == 0;
151 SString
SString::substr(lenpos_t subPos
, lenpos_t subLen
) const {
152 if (subPos
>= sLen
) {
153 return SString(); // return a null string if start index is out of bounds
155 if ((subLen
== measure_length
) || (subPos
+ subLen
> sLen
)) {
156 subLen
= sLen
- subPos
; // can't substr past end of source string
158 return SString(s
, subPos
, subPos
+ subLen
);
161 SString
&SString::lowercase(lenpos_t subPos
, lenpos_t subLen
) {
162 if ((subLen
== measure_length
) || (subPos
+ subLen
> sLen
)) {
163 subLen
= sLen
- subPos
; // don't apply past end of string
165 for (lenpos_t i
= subPos
; i
< subPos
+ subLen
; i
++) {
166 if (s
[i
] < 'A' || s
[i
] > 'Z')
169 s
[i
] = static_cast<char>(s
[i
] - 'A' + 'a');
174 SString
&SString::uppercase(lenpos_t subPos
, lenpos_t subLen
) {
175 if ((subLen
== measure_length
) || (subPos
+ subLen
> sLen
)) {
176 subLen
= sLen
- subPos
; // don't apply past end of string
178 for (lenpos_t i
= subPos
; i
< subPos
+ subLen
; i
++) {
179 if (s
[i
] < 'a' || s
[i
] > 'z')
182 s
[i
] = static_cast<char>(s
[i
] - 'a' + 'A');
187 SString
&SString::append(const char *sOther
, lenpos_t sLenOther
, char sep
) {
191 if (sLenOther
== measure_length
) {
192 sLenOther
= strlen(sOther
);
195 if (sLen
&& sep
) { // Only add a separator if not empty
198 lenpos_t lenNew
= sLen
+ sLenOther
+ lenSep
;
199 // Conservative about growing the buffer: don't do it, unless really needed
200 if ((lenNew
< sSize
) || (grow(lenNew
))) {
205 memcpy(&s
[sLen
], sOther
, sLenOther
);
212 SString
&SString::insert(lenpos_t pos
, const char *sOther
, lenpos_t sLenOther
) {
213 if (!sOther
|| pos
> sLen
) {
216 if (sLenOther
== measure_length
) {
217 sLenOther
= strlen(sOther
);
219 lenpos_t lenNew
= sLen
+ sLenOther
;
220 // Conservative about growing the buffer: don't do it, unless really needed
221 if ((lenNew
< sSize
) || grow(lenNew
)) {
222 lenpos_t moveChars
= sLen
- pos
+ 1;
223 for (lenpos_t i
= moveChars
; i
> 0; i
--) {
224 s
[pos
+ sLenOther
+ i
- 1] = s
[pos
+ i
- 1];
226 memcpy(s
+ pos
, sOther
, sLenOther
);
233 * Remove @a len characters from the @a pos position, included.
234 * Characters at pos + len and beyond replace characters at pos.
235 * If @a len is 0, or greater than the length of the string
236 * starting at @a pos, the string is just truncated at @a pos.
238 void SString::remove(lenpos_t pos
, lenpos_t len
) {
242 if (len
< 1 || pos
+ len
>= sLen
) {
246 for (lenpos_t i
= pos
; i
< sLen
- len
+ 1; i
++) {
253 bool SString::startswith(const char *prefix
) {
254 lenpos_t lenPrefix
= strlen(prefix
);
255 if (lenPrefix
> sLen
) {
258 return strncmp(s
, prefix
, lenPrefix
) == 0;
261 bool SString::endswith(const char *suffix
) {
262 lenpos_t lenSuffix
= strlen(suffix
);
263 if (lenSuffix
> sLen
) {
266 return strncmp(s
+ sLen
- lenSuffix
, suffix
, lenSuffix
) == 0;
269 int SString::search(const char *sFind
, lenpos_t start
) const {
271 const char *sFound
= strstr(s
+ start
, sFind
);
279 int SString::substitute(char chFind
, char chReplace
) {
283 t
= strchr(t
, chFind
);
293 int SString::substitute(const char *sFind
, const char *sReplace
) {
295 lenpos_t lenFind
= strlen(sFind
);
296 lenpos_t lenReplace
= strlen(sReplace
);
297 int posFound
= search(sFind
);
298 while (posFound
>= 0) {
299 remove(posFound
, lenFind
);
300 insert(posFound
, sReplace
, lenReplace
);
301 posFound
= search(sFind
, posFound
+ lenReplace
);
307 char *SContainer::StringAllocate(lenpos_t len
) {
308 if (len
!= measure_length
) {
309 return new char[len
+ 1];
315 char *SContainer::StringAllocate(const char *s
, lenpos_t len
) {
319 if (len
== measure_length
) {
322 char *sNew
= new char[len
+ 1];
324 memcpy(sNew
, s
, len
);
330 // End SString functions
334 for (int root
= 0; root
< hashRoots
; root
++)
338 PropSet::~PropSet() {
343 void PropSet::Set(const char *key
, const char *val
, int lenKey
, int lenVal
) {
344 if (!*key
) // Empty keys are not supported
347 lenKey
= static_cast<int>(strlen(key
));
349 lenVal
= static_cast<int>(strlen(val
));
350 unsigned int hash
= HashString(key
, lenKey
);
351 for (Property
*p
= props
[hash
% hashRoots
]; p
; p
= p
->next
) {
352 if ((hash
== p
->hash
) &&
353 ((strlen(p
->key
) == static_cast<unsigned int>(lenKey
)) &&
354 (0 == strncmp(p
->key
, key
, lenKey
)))) {
355 // Replace current value
357 p
->val
= StringDup(val
, lenVal
);
362 Property
*pNew
= new Property
;
365 pNew
->key
= StringDup(key
, lenKey
);
366 pNew
->val
= StringDup(val
, lenVal
);
367 pNew
->next
= props
[hash
% hashRoots
];
368 props
[hash
% hashRoots
] = pNew
;
372 void PropSet::Set(const char *keyVal
) {
373 while (IsASpace(*keyVal
))
375 const char *endVal
= keyVal
;
376 while (*endVal
&& (*endVal
!= '\n'))
378 const char *eqAt
= strchr(keyVal
, '=');
380 Set(keyVal
, eqAt
+ 1, eqAt
-keyVal
, endVal
- eqAt
- 1);
381 } else if (*keyVal
) { // No '=' so assume '=1'
382 Set(keyVal
, "1", endVal
-keyVal
, 1);
386 void PropSet::SetMultiple(const char *s
) {
387 const char *eol
= strchr(s
, '\n');
391 eol
= strchr(s
, '\n');
396 SString
PropSet::Get(const char *key
) {
397 unsigned int hash
= HashString(key
, strlen(key
));
398 for (Property
*p
= props
[hash
% hashRoots
]; p
; p
= p
->next
) {
399 if ((hash
== p
->hash
) && (0 == strcmp(p
->key
, key
))) {
404 // Failed here, so try in base property set
405 return superPS
->Get(key
);
411 bool PropSet::IncludesVar(const char *value
, const char *key
) {
412 const char *var
= strstr(value
, "$(");
414 if (isprefix(var
+ 2, key
) && (var
[2 + strlen(key
)] == ')')) {
415 // Found $(key) which would lead to an infinite loop so exit
418 var
= strstr(var
+ 2, ")");
420 var
= strstr(var
+ 1, "$(");
425 SString
PropSet::GetExpanded(const char *key
) {
426 SString val
= Get(key
);
427 if (IncludesVar(val
.c_str(), key
))
429 return Expand(val
.c_str());
432 SString
PropSet::Expand(const char *withVars
, int maxExpands
) {
433 char *base
= StringDup(withVars
);
434 char *cpvar
= strstr(base
, "$(");
435 while (cpvar
&& (maxExpands
> 0)) {
436 char *cpendvar
= strchr(cpvar
, ')');
439 int lenvar
= cpendvar
- cpvar
- 2; // Subtract the $()
440 char *var
= StringDup(cpvar
+ 2, lenvar
);
441 SString val
= Get(var
);
442 if (IncludesVar(val
.c_str(), var
))
444 size_t newlenbase
= strlen(base
) + val
.length() - lenvar
;
445 char *newbase
= new char[newlenbase
];
446 strncpy(newbase
, base
, cpvar
- base
);
447 strcpy(newbase
+ (cpvar
- base
), val
.c_str());
448 strcpy(newbase
+ (cpvar
- base
) + val
.length(), cpendvar
+ 1);
452 cpvar
= strstr(base
, "$(");
460 int PropSet::GetInt(const char *key
, int defaultValue
) {
461 SString val
= GetExpanded(key
);
467 bool isprefix(const char *target
, const char *prefix
) {
468 while (*target
&& *prefix
) {
469 if (*target
!= *prefix
)
480 static bool IsSuffixCaseInsensitive(const char *target
, const char *suffix
) {
481 size_t lentarget
= strlen(target
);
482 size_t lensuffix
= strlen(suffix
);
483 if (lensuffix
> lentarget
)
485 for (int i
= static_cast<int>(lensuffix
) - 1; i
>= 0; i
--) {
486 if (MakeUpperCase(target
[i
+ lentarget
- lensuffix
]) !=
487 MakeUpperCase(suffix
[i
]))
493 SString
PropSet::GetWild(const char *keybase
, const char *filename
) {
494 for (int root
= 0; root
< hashRoots
; root
++) {
495 for (Property
*p
= props
[root
]; p
; p
= p
->next
) {
496 if (isprefix(p
->key
, keybase
)) {
497 char * orgkeyfile
= p
->key
+ strlen(keybase
);
498 char *keyfile
= NULL
;
500 if (strstr(orgkeyfile
, "$(") == orgkeyfile
) {
501 char *cpendvar
= strchr(orgkeyfile
, ')');
504 SString s
= GetExpanded(orgkeyfile
+ 2);
506 keyfile
= StringDup(s
.c_str());
509 char *keyptr
= keyfile
;
512 keyfile
= orgkeyfile
;
515 char *del
= strchr(keyfile
, ';');
517 del
= keyfile
+ strlen(keyfile
);
520 if (*keyfile
== '*') {
521 if (IsSuffixCaseInsensitive(filename
, keyfile
+ 1)) {
526 } else if (0 == strcmp(keyfile
, filename
)) {
538 if (0 == strcmp(p
->key
, keybase
)) {
545 // Failed here, so try in base property set
546 return superPS
->GetWild(keybase
, filename
);
552 // GetNewExpand does not use Expand as it has to use GetWild with the filename for each
553 // variable reference found.
554 SString
PropSet::GetNewExpand(const char *keybase
, const char *filename
) {
555 char *base
= StringDup(GetWild(keybase
, filename
).c_str());
556 char *cpvar
= strstr(base
, "$(");
557 int maxExpands
= 1000; // Avoid infinite expansion of recursive definitions
558 while (cpvar
&& (maxExpands
> 0)) {
559 char *cpendvar
= strchr(cpvar
, ')');
561 int lenvar
= cpendvar
- cpvar
- 2; // Subtract the $()
562 char *var
= StringDup(cpvar
+ 2, lenvar
);
563 SString val
= GetWild(var
, filename
);
564 size_t newlenbase
= strlen(base
) + val
.length() - lenvar
;
565 char *newbase
= new char[newlenbase
];
566 strncpy(newbase
, base
, cpvar
- base
);
567 strcpy(newbase
+ (cpvar
- base
), val
.c_str());
568 strcpy(newbase
+ (cpvar
- base
) + val
.length(), cpendvar
+ 1);
573 cpvar
= strstr(base
, "$(");
581 void PropSet::Clear() {
582 for (int root
= 0; root
< hashRoots
; root
++) {
583 Property
*p
= props
[root
];
585 Property
*pNext
= p
->next
;
598 char *PropSet::ToString() {
600 for (int r
= 0; r
< hashRoots
; r
++) {
601 for (Property
*p
= props
[r
]; p
; p
= p
->next
) {
602 len
+= strlen(p
->key
) + 1;
603 len
+= strlen(p
->val
) + 1;
607 len
= 1; // Return as empty string
608 char *ret
= new char [len
];
611 for (int root
= 0; root
< hashRoots
; root
++) {
612 for (Property
*p
= props
[root
]; p
; p
= p
->next
) {
627 * Initiate enumeration.
629 bool PropSet::GetFirst(char **key
, char **val
) {
630 for (int i
= 0; i
< hashRoots
; i
++) {
631 for (Property
*p
= props
[i
]; p
; p
= p
->next
) {
635 enumnext
= p
->next
; // GetNext will begin here ...
636 enumhash
= i
; // ... in this block
645 * Continue enumeration.
647 bool PropSet::GetNext(char ** key
, char ** val
) {
648 bool firstloop
= true;
650 // search begins where we left it : in enumhash block
651 for (int i
= enumhash
; i
< hashRoots
; i
++) {
653 enumnext
= props
[i
]; // Begin with first property in block
654 // else : begin where we left
657 for (Property
*p
= enumnext
; p
; p
= p
->next
) {
661 enumnext
= p
->next
; // for GetNext
671 * Creates an array that points into each word in the string and puts \0 terminators
674 static char **ArrayFromWordList(char *wordlist
, int *len
, bool onlyLineEnds
= false) {
677 // For rapid determination of whether a character is a separator, build
679 bool wordSeparator
[256];
680 for (int i
=0;i
<256; i
++) {
681 wordSeparator
[i
] = false;
683 wordSeparator
['\r'] = true;
684 wordSeparator
['\n'] = true;
686 wordSeparator
[' '] = true;
687 wordSeparator
['\t'] = true;
689 for (int j
= 0; wordlist
[j
]; j
++) {
690 int curr
= static_cast<unsigned char>(wordlist
[j
]);
691 if (!wordSeparator
[curr
] && wordSeparator
[prev
])
695 char **keywords
= new char *[words
+ 1];
699 size_t slen
= strlen(wordlist
);
700 for (size_t k
= 0; k
< slen
; k
++) {
701 if (!wordSeparator
[static_cast<unsigned char>(wordlist
[k
])]) {
703 keywords
[words
] = &wordlist
[k
];
711 keywords
[words
] = &wordlist
[slen
];
719 void WordList::Clear() {
723 delete []wordsNoCase
;
732 void WordList::Set(const char *s
) {
735 words
= ArrayFromWordList(list
, &len
, onlyLineEnds
);
736 wordsNoCase
= new char * [len
+ 1];
737 memcpy(wordsNoCase
, words
, (len
+ 1) * sizeof (*words
));
740 char *WordList::Allocate(int size
) {
741 list
= new char[size
+ 1];
746 void WordList::SetFromAllocated() {
748 words
= ArrayFromWordList(list
, &len
, onlyLineEnds
);
749 wordsNoCase
= new char * [len
+ 1];
750 memcpy(wordsNoCase
, words
, (len
+ 1) * sizeof (*words
));
753 int cmpString(const void *a1
, const void *a2
) {
754 // Can't work out the correct incantation to use modern casts here
755 return strcmp(*(char**)(a1
), *(char**)(a2
));
758 int cmpStringNoCase(const void *a1
, const void *a2
) {
759 // Can't work out the correct incantation to use modern casts here
760 return CompareCaseInsensitive(*(char**)(a1
), *(char**)(a2
));
763 static void SortWordList(char **words
, char **wordsNoCase
, unsigned int len
) {
764 qsort(reinterpret_cast<void*>(words
), len
, sizeof(*words
),
766 qsort(reinterpret_cast<void*>(wordsNoCase
), len
, sizeof(*wordsNoCase
),
770 bool WordList::InList(const char *s
) {
775 SortWordList(words
, wordsNoCase
, len
);
776 for (unsigned int k
= 0; k
< (sizeof(starts
) / sizeof(starts
[0])); k
++)
778 for (int l
= len
- 1; l
>= 0; l
--) {
779 unsigned char indexChar
= words
[l
][0];
780 starts
[indexChar
] = l
;
783 unsigned char firstChar
= s
[0];
784 int j
= starts
[firstChar
];
786 while (words
[j
][0] == firstChar
) {
787 if (s
[1] == words
[j
][1]) {
788 const char *a
= words
[j
] + 1;
789 const char *b
= s
+ 1;
790 while (*a
&& *a
== *b
) {
802 while (words
[j
][0] == '^') {
803 const char *a
= words
[j
] + 1;
805 while (*a
&& *a
== *b
) {
818 * Returns an element (complete) of the wordlist array which has
819 * the same beginning as the passed string.
820 * The length of the word to compare is passed too.
821 * Letter case can be ignored or preserved (default).
823 const char *WordList::GetNearestWord(const char *wordStart
, int searchLen
/*= -1*/, bool ignoreCase
/*= false*/, SString wordCharacters
/*='/0' */, int wordIndex
/*= -1 */) {
824 int start
= 0; // lower bound of the api array block to search
825 int end
= len
- 1; // upper bound of the api array block to search
826 int pivot
; // index of api array element just being compared
827 int cond
; // comparison result (in the sense of strcmp() result)
828 const char *word
; // api array element just being compared
834 SortWordList(words
, wordsNoCase
, len
);
837 while (start
<= end
) { // binary searching loop
838 pivot
= (start
+ end
) >> 1;
839 word
= wordsNoCase
[pivot
];
840 cond
= CompareNCaseInsensitive(wordStart
, word
, searchLen
);
841 if (!cond
&& (!wordCharacters
.contains(word
[searchLen
]))) {
842 // Found a word in a binary fashion. Now checks if a specific index was requested
844 return word
; // result must not be freed with free()
846 // Finds first word in a series of equal words
849 while (start
<= end
) {
850 pivot
= (start
+ end
) >> 1;
851 word
= wordsNoCase
[pivot
];
852 cond
= CompareNCaseInsensitive(wordStart
, word
, searchLen
);
853 if (!cond
&& (!wordCharacters
.contains(word
[searchLen
]))) {
854 // Found another word
864 // Gets the word at the requested index
865 word
= wordsNoCase
[first
+ wordIndex
];
873 } else { // preserve the letter case
874 while (start
<= end
) { // binary searching loop
875 pivot
= (start
+ end
) >> 1;
877 cond
= strncmp(wordStart
, word
, searchLen
);
878 if (!cond
&& (!wordCharacters
.contains(word
[searchLen
]))) {
879 // Found a word in a binary fashion. Now checks if a specific index was requested
881 return word
; // result must not be freed with free()
883 // Finds first word in a series of equal words
886 while (start
<= end
) {
887 pivot
= (start
+ end
) >> 1;
889 cond
= strncmp(wordStart
, word
, searchLen
);
890 if (!cond
&& (!wordCharacters
.contains(word
[searchLen
]))) {
891 // Found another word
901 // Gets the word at the requested index
902 word
= words
[first
+ wordIndex
];
915 * Find the length of a 'word' which is actually an identifier in a string
916 * which looks like "identifier(..." or "identifier:" or "identifier" and where
917 * there may be extra spaces after the identifier that should not be
918 * counted in the length.
920 static unsigned int LengthWord(const char *word
, char otherSeparator
) {
921 // Find a '(', or ':'. If that fails go to the end of the string.
922 const char *endWord
= strchr(word
, '(');
924 endWord
= strchr(word
, ':');
925 if (!endWord
&& otherSeparator
)
926 endWord
= strchr(word
, otherSeparator
);
928 endWord
= word
+ strlen(word
);
929 // Last case always succeeds so endWord != 0
931 // Drop any space characters.
932 if (endWord
> word
) {
933 endWord
--; // Back from the '(', ':', or '\0'
934 // Move backwards over any spaces
935 while ((endWord
> word
) && (IsASpace(*endWord
))) {
939 return endWord
- word
;
943 * Returns elements (first words of them) of the wordlist array which have
944 * the same beginning as the passed string.
945 * The length of the word to compare is passed too.
946 * Letter case can be ignored or preserved (default).
947 * If there are more words meeting the condition they are returned all of
948 * them in the ascending order separated with spaces.
950 * NOTE: returned buffer has to be freed with delete[].
952 char *WordList::GetNearestWords(
953 const char *wordStart
,
954 int searchLen
/*= -1*/,
955 bool ignoreCase
/*= false*/,
956 char otherSeparator
/*= '\0'*/,
957 bool exactLen
/*=false*/) {
958 unsigned int wordlen
; // length of the word part (before the '(' brace) of the api array element
960 wordsNear
.setsizegrowth(1000);
961 int start
= 0; // lower bound of the api array block to search
962 int end
= len
- 1; // upper bound of the api array block to search
963 int pivot
; // index of api array element just being compared
964 int cond
; // comparison result (in the sense of strcmp() result)
970 SortWordList(words
, wordsNoCase
, len
);
973 while (start
<= end
) { // Binary searching loop
974 pivot
= (start
+ end
) / 2;
975 cond
= CompareNCaseInsensitive(wordStart
, wordsNoCase
[pivot
], searchLen
);
978 while ((pivot
> start
) &&
979 (0 == CompareNCaseInsensitive(wordStart
,
980 wordsNoCase
[pivot
-1], searchLen
))) {
984 while ((pivot
<= end
) &&
985 (0 == CompareNCaseInsensitive(wordStart
,
986 wordsNoCase
[pivot
], searchLen
))) {
987 wordlen
= LengthWord(wordsNoCase
[pivot
], otherSeparator
) + 1;
988 if (exactLen
&& wordlen
!= LengthWord(wordStart
, otherSeparator
) + 1)
990 wordsNear
.append(wordsNoCase
[pivot
], wordlen
, ' ');
993 return wordsNear
.detach();
994 } else if (cond
< 0) {
996 } else if (cond
> 0) {
1000 } else { // Preserve the letter case
1001 while (start
<= end
) { // Binary searching loop
1002 pivot
= (start
+ end
) / 2;
1003 cond
= strncmp(wordStart
, words
[pivot
], searchLen
);
1006 while ((pivot
> start
) &&
1007 (0 == strncmp(wordStart
,
1008 words
[pivot
-1], searchLen
))) {
1012 while ((pivot
<= end
) &&
1013 (0 == strncmp(wordStart
,
1014 words
[pivot
], searchLen
))) {
1015 wordlen
= LengthWord(words
[pivot
], otherSeparator
) + 1;
1016 if (exactLen
&& wordlen
!= LengthWord(wordStart
, otherSeparator
) + 1)
1018 wordsNear
.append(words
[pivot
], wordlen
, ' ');
1021 return wordsNear
.detach();
1022 } else if (cond
< 0) {
1024 } else if (cond
> 0) {