Fixed: searching a string for @"" with CPString rangeOfString returned results other than CPNotFound.

This commit is contained in:
Alexander Ljungberg
2011-04-10 20:38:51 -04:00
parent 2166fc1d51
commit a33dd51d8e
2 changed files with 15 additions and 1 deletions
+5 -1
View File
@@ -361,10 +361,14 @@ var CPStringRegexSpecialCharacters = [
@param aMask the options to use in the search
@param aRange the range of the receiver in which to search for
@return the range of characters in the receiver. If the string was not found,
the \c length of the range will be 0.
or if it was @"", the range will be {CPNotFound, 0}.
*/
- (CPRange)rangeOfString:(CPString)aString options:(int)aMask range:(CPrange)aRange
{
// Searching for @"" always returns CPNotFound.
if (!aString)
return CPMakeRange(CPNotFound, 0);
var string = (aRange == nil) ? self : [self substringWithRange:aRange],
location = CPNotFound;
+10
View File
@@ -388,6 +388,16 @@
[self assert:8 equals:unAnchoredSuffixRange.location message:"backwards search for LAG"];
[self assert:CPNotFound equals:anchoredSuffixRange.location message:"anchored backwards search for LAG"];
anchoredSuffixRange = [endsTest rangeOfString:@"AGE" options:(CPAnchoredSearch | CPCaseInsensitiveSearch | CPBackwardsSearch)];
[self assert:9 equals:anchoredSuffixRange.location message:"anchored backwards search for AGE"];
anchoredSuffixRange = [endsTest rangeOfString:endsTest options:(CPAnchoredSearch | CPCaseInsensitiveSearch | CPBackwardsSearch)];
[self assert:0 equals:anchoredSuffixRange.location message:"anchored backwards search for whole string (location)"];
[self assert:endsTest.length equals:anchoredSuffixRange.length message:"anchored backwards search for whole string (length)"];
anchoredSuffixRange = [endsTest rangeOfString:@"" options:(CPAnchoredSearch | CPCaseInsensitiveSearch | CPBackwardsSearch)];
[self assert:CPNotFound equals:anchoredSuffixRange.location message:"anchored backwards search for nothing"];
}
@end