Author: rfm
Date: Sat Oct 31 21:17:07 2015
New Revision: 39109
URL: http://svn.gna.org/viewcvs/gnustep?rev=39109&view=rev
Log:
String comparison fixup for case insensitive combined with literal string.
Modified:
libs/base/trunk/ChangeLog
libs/base/trunk/Source/NSString.m
Modified: libs/base/trunk/ChangeLog
URL:
http://svn.gna.org/viewcvs/gnustep/libs/base/trunk/ChangeLog?rev=39109&r1=39108&r2=39109&view=diff
==============================================================================
--- libs/base/trunk/ChangeLog (original)
+++ libs/base/trunk/ChangeLog Sat Oct 31 21:17:07 2015
@@ -1,3 +1,9 @@
+2015-10-31 Richard Frith-Macdonald <[email protected]>
+
+ * 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 <[email protected]>
* Source/NSBundle.m: remove declaration of unused methods.
Modified: libs/base/trunk/Source/NSString.m
URL:
http://svn.gna.org/viewcvs/gnustep/libs/base/trunk/Source/NSString.m?rev=39109&r1=39108&r2=39109&view=diff
==============================================================================
--- libs/base/trunk/Source/NSString.m (original)
+++ libs/base/trunk/Source/NSString.m Sat Oct 31 21:17:07 2015
@@ -2349,13 +2349,29 @@
{
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 @@
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 @@
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 @@
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 @@
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 @@
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)
_______________________________________________
Gnustep-cvs mailing list
[email protected]
https://mail.gna.org/listinfo/gnustep-cvs