mirror of
https://github.com/gnustep/libs-base.git
synced 2025-04-22 16:33:29 +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
3fc29289f2
commit
d37f8fb30c
2 changed files with 175 additions and 29 deletions
|
@ -1,3 +1,9 @@
|
|||
2015-10-31 Richard Frith-Macdonald <rfm@gnu.org>
|
||||
|
||||
* Source/NSString.m: Fix for fastpath code for literal string
|
||||
comparison which was ignoring the case insensititve option.
|
||||
Problems spotted by Fred, triggered by a Testplant change.
|
||||
|
||||
2015-10-21 Richard Frith-Macdonald <rfm@gnu.org>
|
||||
|
||||
* Source/NSBundle.m: remove declaration of unused methods.
|
||||
|
|
|
@ -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…
Reference in a new issue