mirror of
https://github.com/gnustep/libs-base.git
synced 2025-06-01 17:12:03 +00:00
String comparison fixup for case insensitive combined with literal string.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@39109 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
7843086274
commit
ec7d62b183
2 changed files with 175 additions and 29 deletions
|
@ -2349,13 +2349,29 @@ GSICUCollatorOpen(NSStringCompareOptions mask, NSLocale *locale)
|
|||
{
|
||||
searchRange.location = NSMaxRange(searchRange) - 1;
|
||||
}
|
||||
if ([self characterAtIndex: searchRange.location] == u)
|
||||
if ((mask & NSCaseInsensitiveSearch) == NSCaseInsensitiveSearch)
|
||||
{
|
||||
result = searchRange;
|
||||
u = uni_toupper(u);
|
||||
if (uni_toupper([self characterAtIndex: searchRange.location])
|
||||
== u)
|
||||
{
|
||||
result = searchRange;
|
||||
}
|
||||
else
|
||||
{
|
||||
result = NSMakeRange(NSNotFound, 0);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
result = NSMakeRange(NSNotFound, 0);
|
||||
if ([self characterAtIndex: searchRange.location] == u)
|
||||
{
|
||||
result = searchRange;
|
||||
}
|
||||
else
|
||||
{
|
||||
result = NSMakeRange(NSNotFound, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@ -2369,28 +2385,58 @@ GSICUCollatorOpen(NSStringCompareOptions mask, NSLocale *locale)
|
|||
unichar)
|
||||
[self getCharacters: charsSelf range: searchRange];
|
||||
end = searchRange.length;
|
||||
if ((mask & NSBackwardsSearch) == NSBackwardsSearch)
|
||||
if ((mask & NSCaseInsensitiveSearch) == NSCaseInsensitiveSearch)
|
||||
{
|
||||
pos = end;
|
||||
while (pos-- > 0)
|
||||
u = uni_toupper(u);
|
||||
if ((mask & NSBackwardsSearch) == NSBackwardsSearch)
|
||||
{
|
||||
if (charsSelf[pos] == u)
|
||||
pos = end;
|
||||
while (pos-- > 0)
|
||||
{
|
||||
break;
|
||||
if (uni_toupper(charsSelf[pos]) == u)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
pos = 0;
|
||||
while (pos < end)
|
||||
{
|
||||
if (uni_toupper(charsSelf[pos]) == u)
|
||||
{
|
||||
break;
|
||||
}
|
||||
pos++;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
pos = 0;
|
||||
while (pos < end)
|
||||
if ((mask & NSBackwardsSearch) == NSBackwardsSearch)
|
||||
{
|
||||
if (charsSelf[pos] == u)
|
||||
pos = end;
|
||||
while (pos-- > 0)
|
||||
{
|
||||
break;
|
||||
if (charsSelf[pos] == u)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
pos++;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
pos = 0;
|
||||
while (pos < end)
|
||||
{
|
||||
if (charsSelf[pos] == u)
|
||||
{
|
||||
break;
|
||||
}
|
||||
pos++;
|
||||
}
|
||||
}
|
||||
}
|
||||
GS_ENDITEMBUF2()
|
||||
|
||||
|
@ -2410,6 +2456,16 @@ GSICUCollatorOpen(NSStringCompareOptions mask, NSLocale *locale)
|
|||
if ((mask & NSLiteralSearch) == NSLiteralSearch)
|
||||
{
|
||||
NSRange result;
|
||||
BOOL insensitive;
|
||||
|
||||
if ((mask & NSCaseInsensitiveSearch) == NSCaseInsensitiveSearch)
|
||||
{
|
||||
insensitive = YES;
|
||||
}
|
||||
else
|
||||
{
|
||||
insensitive = NO;
|
||||
}
|
||||
|
||||
if (searchRange.length < countOther)
|
||||
{
|
||||
|
@ -2422,6 +2478,17 @@ GSICUCollatorOpen(NSStringCompareOptions mask, NSLocale *locale)
|
|||
GS_BEGINITEMBUF(charsOther, (countOther*sizeof(unichar)), unichar)
|
||||
|
||||
[aString getCharacters: charsOther range: NSMakeRange(0, countOther)];
|
||||
if (YES == insensitive)
|
||||
{
|
||||
NSUInteger index;
|
||||
|
||||
/* Make the substring we are searching for be uppercase.
|
||||
*/
|
||||
for (index = 0; index < countOther; index++)
|
||||
{
|
||||
charsOther[index] = uni_toupper(charsOther[index]);
|
||||
}
|
||||
}
|
||||
if ((mask & NSAnchoredSearch) == NSAnchoredSearch
|
||||
|| searchRange.length == countOther)
|
||||
{
|
||||
|
@ -2438,14 +2505,37 @@ GSICUCollatorOpen(NSStringCompareOptions mask, NSLocale *locale)
|
|||
searchRange.length = countOther;
|
||||
}
|
||||
[self getCharacters: charsSelf range: searchRange];
|
||||
if (memcmp(&charsSelf[0], &charsOther[0],
|
||||
countOther * sizeof(unichar)) == 0)
|
||||
if (YES == insensitive)
|
||||
{
|
||||
result = searchRange;
|
||||
NSUInteger index;
|
||||
|
||||
for (index = 0; index < countOther; index++)
|
||||
{
|
||||
if (uni_toupper(charsSelf[index]) != charsOther[index])
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (index < countOther)
|
||||
{
|
||||
result = NSMakeRange(NSNotFound, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
result = searchRange;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
result = NSMakeRange(NSNotFound, 0);
|
||||
if (memcmp(&charsSelf[0], &charsOther[0],
|
||||
countOther * sizeof(unichar)) == 0)
|
||||
{
|
||||
result = searchRange;
|
||||
}
|
||||
else
|
||||
{
|
||||
result = NSMakeRange(NSNotFound, 0);
|
||||
}
|
||||
}
|
||||
GS_ENDITEMBUF2()
|
||||
}
|
||||
|
@ -2469,28 +2559,78 @@ GSICUCollatorOpen(NSStringCompareOptions mask, NSLocale *locale)
|
|||
unichar)
|
||||
[self getCharacters: charsSelf range: searchRange];
|
||||
|
||||
if (YES == insensitive)
|
||||
{
|
||||
NSUInteger count;
|
||||
NSUInteger index;
|
||||
|
||||
/* Make things uppercase in the string being searched
|
||||
* Start with all but one of the characters in a substring
|
||||
* and we'll uppercase one more character each time we do
|
||||
* a comparison.
|
||||
*/
|
||||
index = pos;
|
||||
for (count = 1; count < countOther; count++)
|
||||
{
|
||||
charsSelf[index] = uni_toupper(charsSelf[index]);
|
||||
index++;
|
||||
}
|
||||
}
|
||||
|
||||
if ((mask & NSBackwardsSearch) == NSBackwardsSearch)
|
||||
{
|
||||
while (pos-- > 0)
|
||||
if (YES == insensitive)
|
||||
{
|
||||
if (memcmp(&charsSelf[pos], charsOther,
|
||||
countOther * sizeof(unichar)) == 0)
|
||||
while (pos-- > 0)
|
||||
{
|
||||
break;
|
||||
charsSelf[pos] = uni_toupper(charsSelf[pos]);
|
||||
if (memcmp(&charsSelf[pos], charsOther,
|
||||
countOther * sizeof(unichar)) == 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
while (pos-- > 0)
|
||||
{
|
||||
if (memcmp(&charsSelf[pos], charsOther,
|
||||
countOther * sizeof(unichar)) == 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
while (pos < end)
|
||||
if (YES == insensitive)
|
||||
{
|
||||
if (memcmp(&charsSelf[pos], charsOther,
|
||||
countOther * sizeof(unichar)) == 0)
|
||||
while (pos < end)
|
||||
{
|
||||
break;
|
||||
}
|
||||
pos++;
|
||||
}
|
||||
charsSelf[pos + countOther - 1]
|
||||
= uni_toupper(charsSelf[pos + countOther - 1]);
|
||||
if (memcmp(&charsSelf[pos], charsOther,
|
||||
countOther * sizeof(unichar)) == 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
pos++;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
while (pos < end)
|
||||
{
|
||||
if (memcmp(&charsSelf[pos], charsOther,
|
||||
countOther * sizeof(unichar)) == 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
pos++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (pos >= end)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue