mirror of
https://github.com/gnustep/libs-base.git
synced 2025-06-01 09:02:01 +00:00
(-compare:options:range:): Simple implementation; not complete.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@411 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
83da0938b4
commit
1ece8fe556
1 changed files with 39 additions and 2 deletions
|
@ -368,8 +368,45 @@
|
||||||
options: (unsigned int)mask
|
options: (unsigned int)mask
|
||||||
range: (NSRange)aRange
|
range: (NSRange)aRange
|
||||||
{
|
{
|
||||||
[self notImplemented:_cmd];
|
/* xxx ignores NSAnchoredSearch in mask. Fix this. */
|
||||||
return 0;
|
/* xxx only handles C-string encoding */
|
||||||
|
|
||||||
|
int i, start, end, increment;
|
||||||
|
const char *s1 = [self _cStringContents];
|
||||||
|
const char *s2 = [aString _cStringContents];
|
||||||
|
|
||||||
|
if (mask & NSBackwardsSearch)
|
||||||
|
{
|
||||||
|
start = aRange.location + aRange.length;
|
||||||
|
end = aRange.location;
|
||||||
|
increment = -1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
start = aRange.location;
|
||||||
|
end = aRange.location + aRange.length;
|
||||||
|
increment = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mask & NSCaseInsensitiveSearch)
|
||||||
|
{
|
||||||
|
for (i = start; i < end; i += increment)
|
||||||
|
{
|
||||||
|
int c1 = tolower(s1[i]);
|
||||||
|
int c2 = tolower(s2[i]);
|
||||||
|
if (c1 < c2) return NSOrderedAscending;
|
||||||
|
if (c1 > c2) return NSOrderedDescending;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
for (i = start; i < end; i += increment)
|
||||||
|
{
|
||||||
|
if (s1[i] < s2[i]) return NSOrderedAscending;
|
||||||
|
if (s1[i] > s2[i]) return NSOrderedDescending;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return NSOrderedSame;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (BOOL) hasPrefix: (NSString*)aString
|
- (BOOL) hasPrefix: (NSString*)aString
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue