mirror of
https://github.com/gnustep/libs-base.git
synced 2025-04-23 00:41:02 +00:00
More optimisation
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@4236 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
6172b1b896
commit
7adcc6d423
3 changed files with 273 additions and 250 deletions
|
@ -2,10 +2,10 @@ Mon May 10 8:00:00 1999 Richard Frith-Macdonald <richard@brainstorm.co.uk>
|
|||
|
||||
* Source/NSString.m: ([-rangeOfComposedCharacterSequenceAtIndex:])
|
||||
optimised.
|
||||
* Source/NSGString.m ([-rangeOfComposedCharacterSequenceAtIndex:])
|
||||
implemented.
|
||||
* Source/NSGCString.m ([-rangeOfComposedCharacterSequenceAtIndex:])
|
||||
* Source/NSGString.m: ([-rangeOfComposedCharacterSequenceAtIndex:])
|
||||
implemented.
|
||||
* Source/NSGCString.m: ([-rangeOfComposedCharacterSequenceAtIndex:])
|
||||
* Source/NSGSequence.m: various parts optimised.
|
||||
* Source/include/NSThread.h: add gcontext ivar.
|
||||
|
||||
Fri May 7 15:12:00 1999 Richard Frith-Macdonald <richard@brainstorm.co.uk>
|
||||
|
|
|
@ -1,25 +1,25 @@
|
|||
/* Implementation of composite character sequence class for GNUSTEP
|
||||
Copyright (C) 1997 Free Software Foundation, Inc.
|
||||
|
||||
|
||||
Written by: Stevo Crvenkovski <stevo@btinternet.com>
|
||||
Date: March 1997
|
||||
|
||||
|
||||
This file is part of the GNUstep Base Library.
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Library General Public License for more details.
|
||||
|
||||
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with this library; if not, write to the Free
|
||||
Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
*/
|
||||
|
||||
|
||||
#include <config.h>
|
||||
|
@ -45,9 +45,104 @@
|
|||
#include <base/NSGSequence.h>
|
||||
#include <base//Unicode.h>
|
||||
|
||||
#define MAXDEC 18
|
||||
|
||||
static inline void gs_seq_decompose(unichar **buffer, unsigned *length)
|
||||
{
|
||||
unichar *spoint;
|
||||
unichar *tpoint;
|
||||
unichar *dpoint;
|
||||
unsigned count = *length;
|
||||
|
||||
if (count)
|
||||
{
|
||||
unichar source[count*MAXDEC+1];
|
||||
unichar target[count*MAXDEC+1];
|
||||
unichar *chars = *buffer;
|
||||
BOOL notdone = YES;
|
||||
|
||||
spoint = source;
|
||||
tpoint = target;
|
||||
memcpy(source, chars, 2*count);
|
||||
source[count] = (unichar)(0);
|
||||
|
||||
while (notdone)
|
||||
{
|
||||
notdone = NO;
|
||||
do
|
||||
{
|
||||
if (!(dpoint = uni_is_decomp(*spoint)))
|
||||
*tpoint++ = *spoint;
|
||||
else
|
||||
{
|
||||
while (*dpoint)
|
||||
*tpoint++ = *dpoint++;
|
||||
notdone = YES;
|
||||
}
|
||||
}
|
||||
while (*spoint++);
|
||||
|
||||
*tpoint = (unichar)0; // *** maybe not needed
|
||||
|
||||
memcpy(source, target, 2*(count*MAXDEC+1));
|
||||
|
||||
tpoint = target;
|
||||
spoint = source;
|
||||
}
|
||||
|
||||
count = uslen(source);
|
||||
OBJC_REALLOC(chars, unichar, count+1);
|
||||
memcpy(chars, source, 2*(count+1));
|
||||
chars[count] = (unichar)0;
|
||||
*buffer = chars;
|
||||
*length = count;
|
||||
}
|
||||
}
|
||||
|
||||
static inline void gs_seq_order(unichar *chars, unsigned len)
|
||||
{
|
||||
if (len > 1)
|
||||
{
|
||||
BOOL notdone = YES;
|
||||
|
||||
while (notdone)
|
||||
{
|
||||
unichar *first = chars;
|
||||
unichar *second = first + 1;
|
||||
unsigned count;
|
||||
|
||||
notdone = NO;
|
||||
for (count = 1; count < len; count++)
|
||||
{
|
||||
if (uni_cop(*second))
|
||||
{
|
||||
if (uni_cop(*first) > uni_cop(*second))
|
||||
{
|
||||
unichar tmp = *first;
|
||||
|
||||
*first = *second;
|
||||
*second = tmp;
|
||||
notdone = YES;
|
||||
}
|
||||
else if (uni_cop(*first) == uni_cop(*second))
|
||||
{
|
||||
if (*first > *second)
|
||||
{
|
||||
unichar tmp = *first;
|
||||
|
||||
*first = *second;
|
||||
*second = tmp;
|
||||
notdone = YES;
|
||||
}
|
||||
}
|
||||
}
|
||||
first++;
|
||||
second++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#define FALSE 0
|
||||
#define TRUE 1
|
||||
|
||||
@implementation NSGSequence
|
||||
|
||||
|
@ -63,34 +158,32 @@ static Class seqClass;
|
|||
|
||||
// Creating Temporary Sequences
|
||||
|
||||
+ (NSGSequence*) sequenceWithString: (NSString*) aString
|
||||
+ (NSGSequence*) sequenceWithString: (NSString*) aString
|
||||
range: (NSRange)aRange
|
||||
{
|
||||
return [[[self alloc] initWithString: aString range: aRange]
|
||||
autorelease];
|
||||
return [[[self allocWithZone: NSDefaultMallocZone()]
|
||||
initWithString: aString range: aRange] autorelease];
|
||||
}
|
||||
|
||||
+ (NSGSequence*) sequenceWithSequence: (NSGSequence*) aSequence
|
||||
+ (NSGSequence*) sequenceWithSequence: (NSGSequence*) aSequence
|
||||
|
||||
{
|
||||
return [[[self alloc]
|
||||
initWithSequence: aSequence]
|
||||
autorelease];
|
||||
return [[[self allocWithZone: NSDefaultMallocZone()]
|
||||
initWithSequence: aSequence] autorelease];
|
||||
}
|
||||
|
||||
+ (NSGSequence*) sequenceWithCharacters: (unichar *) characters
|
||||
length: (int) len
|
||||
{
|
||||
return [[[self alloc]
|
||||
initWithCharacters: characters length: len]
|
||||
autorelease];
|
||||
return [[[self allocWithZone: NSDefaultMallocZone()]
|
||||
initWithCharacters: characters length: len] autorelease];
|
||||
}
|
||||
|
||||
+ (NSGSequence*) sequenceWithCharactersNoCopy: (unichar *) characters
|
||||
length: (int) len freeWhenDone: (BOOL) flag
|
||||
{
|
||||
return [[[self alloc]
|
||||
initWithCharactersNoCopy: characters length: len freeWhenDone:flag]
|
||||
return [[[self allocWithZone: NSDefaultMallocZone()]
|
||||
initWithCharactersNoCopy: characters length: len freeWhenDone: flag]
|
||||
autorelease];
|
||||
}
|
||||
|
||||
|
@ -109,7 +202,7 @@ static Class seqClass;
|
|||
// xxx take care of _normalize in all init* methods
|
||||
- (id) init
|
||||
{
|
||||
return [self initWithString:@"" range: NSMakeRange(0,0)];
|
||||
return [self initWithString: @"" range: NSMakeRange(0, 0)];
|
||||
}
|
||||
|
||||
- (id) initWithString: (NSString*)string
|
||||
|
@ -117,24 +210,27 @@ static Class seqClass;
|
|||
{
|
||||
unichar *s;
|
||||
if (aRange.location > [string length])
|
||||
[NSException raise: NSRangeException format:@"Invalid location."];
|
||||
|
||||
[NSException raise: NSRangeException format: @"Invalid location."];
|
||||
if (aRange.length > ([string length] - aRange.location))
|
||||
[NSException raise: NSRangeException format:@"Invalid location+length."];
|
||||
[NSException raise: NSRangeException format: @"Invalid location+length."];
|
||||
|
||||
OBJC_MALLOC(s, unichar, aRange.length+1);
|
||||
[string getCharacters:s range: aRange];
|
||||
[string getCharacters: s range: aRange];
|
||||
s[aRange.length] = (unichar)0;
|
||||
return [self initWithCharactersNoCopy:s length: aRange.length freeWhenDone:YES];
|
||||
return [self initWithCharactersNoCopy: s
|
||||
length: aRange.length
|
||||
freeWhenDone: YES];
|
||||
}
|
||||
|
||||
- (id) initWithSequence: (NSGSequence*) aSequence
|
||||
- (id) initWithSequence: (NSGSequence*) aSequence
|
||||
{
|
||||
unichar *s;
|
||||
int len=[aSequence length];
|
||||
unichar *s;
|
||||
unsigned len = aSequence->_count;
|
||||
|
||||
OBJC_MALLOC(s, unichar, len+1);
|
||||
[aSequence getCharacters:s];
|
||||
memcpy(s, aSequence->_contents_chars, len);
|
||||
s[len] = (unichar)0;
|
||||
return [self initWithCharactersNoCopy:s length:len freeWhenDone:YES];
|
||||
return [self initWithCharactersNoCopy: s length: len freeWhenDone: YES];
|
||||
}
|
||||
|
||||
- (id) initWithCharactersNoCopy: (unichar*)chars
|
||||
|
@ -158,9 +254,9 @@ static Class seqClass;
|
|||
unichar *s;
|
||||
OBJC_MALLOC(s, unichar, length+1);
|
||||
if (chars)
|
||||
memcpy(s, chars,2*length);
|
||||
memcpy(s, chars, 2*length);
|
||||
s[length] = (unichar)0;
|
||||
return [self initWithCharactersNoCopy:s length:length freeWhenDone:YES];
|
||||
return [self initWithCharactersNoCopy: s length: length freeWhenDone: YES];
|
||||
}
|
||||
|
||||
// Getting a Length of Sequence
|
||||
|
@ -174,7 +270,7 @@ static Class seqClass;
|
|||
|
||||
- (unichar) characterAtIndex: (unsigned int)index
|
||||
{
|
||||
if (index >= [self length])
|
||||
if (index >= _count)
|
||||
[NSException raise: NSRangeException
|
||||
format: @"index greater than sequence length"];
|
||||
return _contents_chars[index];
|
||||
|
@ -182,162 +278,66 @@ static Class seqClass;
|
|||
|
||||
- (unichar) baseCharacter
|
||||
{
|
||||
if(![self isNormalized])
|
||||
if (!_normalized)
|
||||
[self normalize];
|
||||
return _contents_chars[0];
|
||||
}
|
||||
|
||||
- (unichar) precomposedCharacter
|
||||
{
|
||||
[self notImplemented:_cmd];
|
||||
[self notImplemented: _cmd];
|
||||
return _contents_chars[0];
|
||||
}
|
||||
|
||||
/* Inefficient. */
|
||||
- (void) getCharacters: (unichar*)buffer
|
||||
{
|
||||
[self getCharacters:buffer range:((NSRange){0,[self length]})];
|
||||
return;
|
||||
memcpy(buffer, _contents_chars, _count*2);
|
||||
}
|
||||
|
||||
/* Inefficient. */
|
||||
- (void) getCharacters: (unichar*)buffer
|
||||
range: (NSRange)aRange
|
||||
{
|
||||
#if 0
|
||||
int i;
|
||||
for (i = 0; i < aRange.length; i++)
|
||||
{
|
||||
buffer[i] = [self characterAtIndex: aRange.location+i];
|
||||
}
|
||||
#else
|
||||
memcpy(buffer, &_contents_chars[aRange.location], aRange.length*2);
|
||||
#endif
|
||||
}
|
||||
|
||||
//for debuging
|
||||
- (NSString*) description
|
||||
{
|
||||
unichar * point;
|
||||
point=_contents_chars;
|
||||
point = _contents_chars;
|
||||
while(*point)
|
||||
printf("%X ",*point++);
|
||||
printf("%X ", *point++);
|
||||
printf("\n");
|
||||
return @"";
|
||||
}
|
||||
|
||||
- (NSGSequence*) decompose
|
||||
{
|
||||
#define MAXDEC 18
|
||||
|
||||
unichar *source;
|
||||
unichar *target;
|
||||
unichar *spoint;
|
||||
unichar *tpoint;
|
||||
unichar *dpoint;
|
||||
BOOL notdone;
|
||||
int len;
|
||||
|
||||
if (_count)
|
||||
{
|
||||
OBJC_MALLOC(source, unichar, _count*MAXDEC+1);
|
||||
OBJC_MALLOC(target, unichar, _count*MAXDEC+1);
|
||||
spoint = source;
|
||||
tpoint = target;
|
||||
memcpy(source, _contents_chars, 2*_count);
|
||||
source[_count]=(unichar)(0);
|
||||
do
|
||||
{
|
||||
notdone=FALSE;
|
||||
do
|
||||
{
|
||||
if(!(dpoint=uni_is_decomp(*spoint)))
|
||||
*tpoint++ = *spoint;
|
||||
else
|
||||
{
|
||||
while(*dpoint)
|
||||
*tpoint++=*dpoint++;
|
||||
notdone=TRUE;
|
||||
}
|
||||
} while(*spoint++);
|
||||
|
||||
*tpoint=(unichar)0; // *** maybe not needed
|
||||
|
||||
memcpy(source, target,2*(_count*MAXDEC+1));
|
||||
|
||||
tpoint = target;
|
||||
spoint = source;
|
||||
|
||||
} while(notdone);
|
||||
len = uslen(source);
|
||||
OBJC_REALLOC(_contents_chars, unichar, len+1);
|
||||
memcpy(_contents_chars,source,2*(len+1));
|
||||
_contents_chars[len] = (unichar)0;
|
||||
_count = len;
|
||||
OBJC_FREE(target);
|
||||
OBJC_FREE(source);
|
||||
return self;
|
||||
}
|
||||
else
|
||||
{
|
||||
return self;
|
||||
}
|
||||
return self;
|
||||
gs_seq_decompose(&_contents_chars, &_count);
|
||||
return self;
|
||||
}
|
||||
|
||||
- (NSGSequence*) order
|
||||
{
|
||||
unichar *first,*second,tmp;
|
||||
int count,len;
|
||||
BOOL notdone;
|
||||
len=[self length];
|
||||
|
||||
if(len>1)
|
||||
do
|
||||
{
|
||||
notdone=NO;
|
||||
first=_contents_chars;
|
||||
second=first+1;
|
||||
for(count=1;count<len;count++)
|
||||
{
|
||||
if(uni_cop(*second))
|
||||
{
|
||||
if(uni_cop(*first)>uni_cop(*second))
|
||||
{
|
||||
tmp= *first;
|
||||
*first= *second;
|
||||
*second=tmp;
|
||||
notdone=YES;
|
||||
}
|
||||
if(uni_cop(*first)==uni_cop(*second))
|
||||
if(*first>*second)
|
||||
{
|
||||
tmp= *first;
|
||||
*first= *second;
|
||||
*second=tmp;
|
||||
notdone=YES;
|
||||
}
|
||||
}
|
||||
first++;
|
||||
second++;
|
||||
}
|
||||
} while(notdone);
|
||||
gs_seq_order(_contents_chars, _count);
|
||||
return self;
|
||||
}
|
||||
|
||||
- (NSGSequence*) normalize
|
||||
{
|
||||
if(![self isNormalized])
|
||||
{
|
||||
[[self decompose] order];
|
||||
_normalized=YES;
|
||||
}
|
||||
if (!_normalized)
|
||||
{
|
||||
gs_seq_decompose(&_contents_chars, &_count);
|
||||
gs_seq_order(_contents_chars, _count);
|
||||
_normalized = YES;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (BOOL) isEqual: (NSGSequence*) aSequence
|
||||
{
|
||||
return [self compare:aSequence]==NSOrderedSame;
|
||||
return [self compare: aSequence] == NSOrderedSame;
|
||||
}
|
||||
|
||||
- (BOOL) isNormalized
|
||||
|
@ -347,10 +347,10 @@ static Class seqClass;
|
|||
|
||||
- (BOOL) isComposite
|
||||
{
|
||||
if(uni_is_decomp(_contents_chars[0]))
|
||||
if (uni_is_decomp(_contents_chars[0]))
|
||||
return YES;
|
||||
else
|
||||
if([self length]<2)
|
||||
if (_count < 2)
|
||||
return NO;
|
||||
else
|
||||
return YES;
|
||||
|
@ -358,72 +358,81 @@ static Class seqClass;
|
|||
|
||||
- (NSGSequence*) maxComposed
|
||||
{
|
||||
[self notImplemented:_cmd];
|
||||
[self notImplemented: _cmd];
|
||||
return self;
|
||||
}
|
||||
|
||||
- (NSGSequence*) lowercase
|
||||
{
|
||||
unichar *s;
|
||||
int count;
|
||||
int len=[self length];
|
||||
OBJC_MALLOC(s, unichar,len +1);
|
||||
for(count=0;count<len;count++)
|
||||
s[count]=uni_tolower(_contents_chars[count]);
|
||||
unichar *s;
|
||||
unsigned count;
|
||||
unsigned len = _count;
|
||||
|
||||
OBJC_MALLOC(s, unichar, len + 1);
|
||||
for (count =0; count < len; count++)
|
||||
s[count] = uni_tolower(_contents_chars[count]);
|
||||
s[len] = (unichar)0;
|
||||
return [seqClass sequenceWithCharactersNoCopy:s length:len freeWhenDone:YES];
|
||||
return [seqClass sequenceWithCharactersNoCopy: s
|
||||
length: len
|
||||
freeWhenDone: YES];
|
||||
}
|
||||
|
||||
- (NSGSequence*) uppercase
|
||||
{
|
||||
unichar *s;
|
||||
int count;
|
||||
int len=[self length];
|
||||
OBJC_MALLOC(s, unichar,len +1);
|
||||
for(count=0;count<len;count++)
|
||||
s[count]=uni_toupper(_contents_chars[count]);
|
||||
unichar *s;
|
||||
unsigned count;
|
||||
unsigned len = _count;
|
||||
|
||||
OBJC_MALLOC(s, unichar, len + 1);
|
||||
for (count = 0; count < len; count++)
|
||||
s[count] = uni_toupper(_contents_chars[count]);
|
||||
s[len] = (unichar)0;
|
||||
return [seqClass sequenceWithCharactersNoCopy:s length:len freeWhenDone:YES];
|
||||
return [seqClass sequenceWithCharactersNoCopy: s
|
||||
length: len
|
||||
freeWhenDone: YES];
|
||||
}
|
||||
|
||||
- (NSGSequence*) titlecase
|
||||
{
|
||||
[self notImplemented:_cmd];
|
||||
[self notImplemented: _cmd];
|
||||
return self;
|
||||
}
|
||||
|
||||
/* Inefficient */
|
||||
- (NSComparisonResult) compare: (NSGSequence*) aSequence
|
||||
{
|
||||
int i,end;
|
||||
unsigned int myLength;
|
||||
unsigned int seqLength;
|
||||
|
||||
if(![self isNormalized])
|
||||
[self normalize];
|
||||
if(![aSequence isNormalized])
|
||||
[aSequence normalize];
|
||||
myLength = [self length];
|
||||
seqLength = [aSequence length];
|
||||
if(myLength < seqLength)
|
||||
end=myLength;
|
||||
unsigned i;
|
||||
unsigned end;
|
||||
unsigned myLength;
|
||||
unsigned seqLength;
|
||||
|
||||
if (!_normalized)
|
||||
{
|
||||
gs_seq_decompose(&_contents_chars, &_count);
|
||||
gs_seq_order(_contents_chars, _count);
|
||||
_normalized = YES;
|
||||
}
|
||||
if (!aSequence->_normalized)
|
||||
{
|
||||
gs_seq_decompose(&aSequence->_contents_chars, &aSequence->_count);
|
||||
gs_seq_order(aSequence->_contents_chars, aSequence->_count);
|
||||
_normalized = YES;
|
||||
}
|
||||
myLength = _count;
|
||||
seqLength = aSequence->_count;
|
||||
if (myLength < seqLength)
|
||||
end = myLength;
|
||||
else
|
||||
end=seqLength;
|
||||
end = seqLength;
|
||||
for (i = 0; i < end; i ++)
|
||||
{
|
||||
#if 0
|
||||
if ([self characterAtIndex:i] < [aSequence characterAtIndex:i]) return NSOrderedAscending;
|
||||
if ([self characterAtIndex:i] > [aSequence characterAtIndex:i]) return NSOrderedDescending;
|
||||
#else
|
||||
if (_contents_chars[i] < aSequence->_contents_chars[i])
|
||||
return NSOrderedAscending;
|
||||
if (_contents_chars[i] > aSequence->_contents_chars[i])
|
||||
return NSOrderedDescending;
|
||||
#endif
|
||||
}
|
||||
if(myLength<seqLength)
|
||||
{
|
||||
if (_contents_chars[i] < aSequence->_contents_chars[i])
|
||||
return NSOrderedAscending;
|
||||
if (_contents_chars[i] > aSequence->_contents_chars[i])
|
||||
return NSOrderedDescending;
|
||||
}
|
||||
if (myLength < seqLength)
|
||||
return NSOrderedAscending;
|
||||
if(myLength>seqLength)
|
||||
if (myLength > seqLength)
|
||||
return NSOrderedDescending;
|
||||
return NSOrderedSame;
|
||||
}
|
||||
|
@ -433,14 +442,14 @@ static Class seqClass;
|
|||
|
||||
- copyWithZone: (NSZone*)zone
|
||||
{
|
||||
return [[[self class] allocWithZone:zone] initWithSequence:self];
|
||||
return [[[self class] allocWithZone: zone] initWithSequence: self];
|
||||
}
|
||||
|
||||
|
||||
// **************** do I need this?
|
||||
- mutableCopyWithZone: (NSZone*)zone
|
||||
{
|
||||
return [[[self class] allocWithZone:zone]
|
||||
return [[[self class] allocWithZone: zone]
|
||||
initWithSequence: self];
|
||||
}
|
||||
|
||||
|
|
|
@ -99,7 +99,10 @@
|
|||
0
|
||||
};
|
||||
|
||||
static Class NSString_class; /* For speed */
|
||||
static Class NSString_class; /* For speed */
|
||||
static Class NSGSequence_class; /* For speed */
|
||||
|
||||
static SEL caiSel = @selector(characterAtIndex:);
|
||||
|
||||
/*
|
||||
* Include property-list parsing code configured for unicode characters.
|
||||
|
@ -250,6 +253,7 @@ handle_printf_atsign (FILE *stream,
|
|||
{
|
||||
_DefaultStringEncoding = GetDefEncoding();
|
||||
NSString_class = self;
|
||||
NSGSequence_class = [NSGSequence class];
|
||||
NSString_concrete_class = [NSGString class];
|
||||
NSString_c_concrete_class = [NSGCString class];
|
||||
NSMutableString_concrete_class = [NSGMutableString class];
|
||||
|
@ -1016,7 +1020,7 @@ handle_printf_atsign (FILE *stream,
|
|||
if (mask & NSAnchoredSearch)
|
||||
myEndIndex = myIndex;
|
||||
|
||||
strFirstCharacterSeq = [NSGSequence sequenceWithString: aString
|
||||
strFirstCharacterSeq = [NSGSequence_class sequenceWithString: aString
|
||||
range: [aString rangeOfComposedCharacterSequenceAtIndex: 0]];
|
||||
|
||||
for (;;)
|
||||
|
@ -1026,7 +1030,7 @@ handle_printf_atsign (FILE *stream,
|
|||
NSRange strRange;
|
||||
unsigned int myCount = 1;
|
||||
unsigned int strCount = 1;
|
||||
id myCharacter = [NSGSequence sequenceWithString: self
|
||||
id myCharacter = [NSGSequence_class sequenceWithString: self
|
||||
range: [self rangeOfComposedCharacterSequenceAtIndex: myIndex]];
|
||||
id strCharacter = strFirstCharacterSeq;
|
||||
for (;;)
|
||||
|
@ -1038,9 +1042,9 @@ handle_printf_atsign (FILE *stream,
|
|||
if (strCount >= strLength)
|
||||
return (NSRange){myIndex, myCount};
|
||||
myRange = [self rangeOfComposedCharacterSequenceAtIndex: myIndex + myCount];
|
||||
myCharacter = [NSGSequence sequenceWithString: self range: myRange];
|
||||
myCharacter = [NSGSequence_class sequenceWithString: self range: myRange];
|
||||
strRange = [aString rangeOfComposedCharacterSequenceAtIndex: strCount];
|
||||
strCharacter = [NSGSequence sequenceWithString: aString range: strRange];
|
||||
strCharacter = [NSGSequence_class sequenceWithString: aString range: strRange];
|
||||
myCount += myRange.length;
|
||||
strCount += strRange.length;
|
||||
} /* for */
|
||||
|
@ -1069,7 +1073,7 @@ handle_printf_atsign (FILE *stream,
|
|||
if (mask & NSAnchoredSearch)
|
||||
myEndIndex = myIndex;
|
||||
|
||||
strFirstCharacterSeq = [NSGSequence sequenceWithString: aString
|
||||
strFirstCharacterSeq = [NSGSequence_class sequenceWithString: aString
|
||||
range: [aString rangeOfComposedCharacterSequenceAtIndex: 0]];
|
||||
|
||||
for (;;)
|
||||
|
@ -1078,7 +1082,7 @@ handle_printf_atsign (FILE *stream,
|
|||
NSRange strRange;
|
||||
unsigned int myCount = 1;
|
||||
unsigned int strCount = 1;
|
||||
id myCharacter = [NSGSequence sequenceWithString: self
|
||||
id myCharacter = [NSGSequence_class sequenceWithString: self
|
||||
range: [self rangeOfComposedCharacterSequenceAtIndex: myIndex]];
|
||||
id strCharacter = strFirstCharacterSeq;
|
||||
for (;;)
|
||||
|
@ -1089,9 +1093,9 @@ handle_printf_atsign (FILE *stream,
|
|||
break;
|
||||
if (strCount >= strLength)
|
||||
return (NSRange){myIndex, myCount};
|
||||
myCharacter = [NSGSequence sequenceWithString: self range: [self rangeOfComposedCharacterSequenceAtIndex: myIndex + myCount]];
|
||||
myCharacter = [NSGSequence_class sequenceWithString: self range: [self rangeOfComposedCharacterSequenceAtIndex: myIndex + myCount]];
|
||||
myRange = [self rangeOfComposedCharacterSequenceAtIndex: myIndex + myCount];
|
||||
strCharacter = [NSGSequence sequenceWithString: aString range: [aString rangeOfComposedCharacterSequenceAtIndex: strCount]];
|
||||
strCharacter = [NSGSequence_class sequenceWithString: aString range: [aString rangeOfComposedCharacterSequenceAtIndex: strCount]];
|
||||
strRange = [aString rangeOfComposedCharacterSequenceAtIndex: strCount];
|
||||
myCount += myRange.length;
|
||||
strCount += strRange.length;
|
||||
|
@ -1123,7 +1127,7 @@ handle_printf_atsign (FILE *stream,
|
|||
if (mask & NSAnchoredSearch)
|
||||
myEndIndex = myIndex;
|
||||
|
||||
strFirstCharacterSeq = [NSGSequence sequenceWithString: aString
|
||||
strFirstCharacterSeq = [NSGSequence_class sequenceWithString: aString
|
||||
range: [aString rangeOfComposedCharacterSequenceAtIndex: 0]];
|
||||
|
||||
for (;;)
|
||||
|
@ -1133,7 +1137,7 @@ handle_printf_atsign (FILE *stream,
|
|||
NSRange mainRange;
|
||||
unsigned int myCount = 1;
|
||||
unsigned int strCount = 1;
|
||||
id myCharacter = [NSGSequence sequenceWithString: self
|
||||
id myCharacter = [NSGSequence_class sequenceWithString: self
|
||||
range: [self rangeOfComposedCharacterSequenceAtIndex: myIndex]];
|
||||
id strCharacter = strFirstCharacterSeq;
|
||||
for (;;)
|
||||
|
@ -1143,9 +1147,9 @@ handle_printf_atsign (FILE *stream,
|
|||
if (strCount >= strLength)
|
||||
return (NSRange){myIndex, myCount};
|
||||
myRange = [self rangeOfComposedCharacterSequenceAtIndex: myIndex + myCount];
|
||||
myCharacter = [NSGSequence sequenceWithString: self range: myRange];
|
||||
myCharacter = [NSGSequence_class sequenceWithString: self range: myRange];
|
||||
strRange = [aString rangeOfComposedCharacterSequenceAtIndex: strCount];
|
||||
strCharacter = [NSGSequence sequenceWithString: aString range: strRange];
|
||||
strCharacter = [NSGSequence_class sequenceWithString: aString range: strRange];
|
||||
myCount += myRange.length;
|
||||
strCount += strRange.length;
|
||||
} /* for */
|
||||
|
@ -1175,7 +1179,7 @@ handle_printf_atsign (FILE *stream,
|
|||
if (mask & NSAnchoredSearch)
|
||||
myEndIndex = myIndex;
|
||||
|
||||
strFirstCharacterSeq = [NSGSequence sequenceWithString: aString
|
||||
strFirstCharacterSeq = [NSGSequence_class sequenceWithString: aString
|
||||
range: [aString rangeOfComposedCharacterSequenceAtIndex: 0]];
|
||||
|
||||
for (;;)
|
||||
|
@ -1184,7 +1188,7 @@ handle_printf_atsign (FILE *stream,
|
|||
NSRange strRange;
|
||||
unsigned int myCount = 1;
|
||||
unsigned int strCount = 1;
|
||||
id myCharacter = [NSGSequence sequenceWithString: self
|
||||
id myCharacter = [NSGSequence_class sequenceWithString: self
|
||||
range: [self rangeOfComposedCharacterSequenceAtIndex: myIndex]];
|
||||
id strCharacter = strFirstCharacterSeq;
|
||||
for (;;)
|
||||
|
@ -1194,9 +1198,9 @@ handle_printf_atsign (FILE *stream,
|
|||
break;
|
||||
if (strCount >= strLength)
|
||||
return (NSRange){myIndex, myCount};
|
||||
myCharacter = [NSGSequence sequenceWithString: self range: [self rangeOfComposedCharacterSequenceAtIndex: myIndex + myCount]];
|
||||
myCharacter = [NSGSequence_class sequenceWithString: self range: [self rangeOfComposedCharacterSequenceAtIndex: myIndex + myCount]];
|
||||
myRange = [self rangeOfComposedCharacterSequenceAtIndex: myIndex + myCount];
|
||||
strCharacter = [NSGSequence sequenceWithString: aString range: [aString rangeOfComposedCharacterSequenceAtIndex: strCount]];
|
||||
strCharacter = [NSGSequence_class sequenceWithString: aString range: [aString rangeOfComposedCharacterSequenceAtIndex: strCount]];
|
||||
strRange = [aString rangeOfComposedCharacterSequenceAtIndex: strCount];
|
||||
myCount += myRange.length;
|
||||
strCount += strRange.length;
|
||||
|
@ -1425,8 +1429,8 @@ else
|
|||
myCount += myRange.length;
|
||||
strRange = [aString rangeOfComposedCharacterSequenceAtIndex: strCount];
|
||||
strCount += strRange.length;
|
||||
mySeq = [NSGSequence sequenceWithString: self range: myRange];
|
||||
strSeq = [NSGSequence sequenceWithString: aString range: strRange];
|
||||
mySeq = [NSGSequence_class sequenceWithString: self range: myRange];
|
||||
strSeq = [NSGSequence_class sequenceWithString: aString range: strRange];
|
||||
if (mask & NSCaseInsensitiveSearch)
|
||||
result = [[mySeq lowercase] compare: [strSeq lowercase]];
|
||||
else
|
||||
|
@ -1473,12 +1477,19 @@ else
|
|||
|
||||
- (BOOL) isEqualToString: (NSString*)aString
|
||||
{
|
||||
id mySeq, strSeq;
|
||||
NSRange myRange, strRange;
|
||||
unsigned int myLength;
|
||||
unsigned int strLength;
|
||||
unsigned int myIndex = 0;
|
||||
unsigned int strIndex = 0;
|
||||
id mySeq;
|
||||
id strSeq;
|
||||
NSRange myRange;
|
||||
NSRange strRange;
|
||||
unsigned myLength;
|
||||
unsigned strLength;
|
||||
unsigned myIndex = 0;
|
||||
unsigned strIndex = 0;
|
||||
static SEL ranSel = @selector(rangeOfComposedCharacterSequenceAtIndex:);
|
||||
unichar (*scImp)(NSString*, SEL, unsigned);
|
||||
unichar (*ocImp)(NSString*, SEL, unsigned);
|
||||
NSRange (*srImp)(NSString*, SEL, unsigned);
|
||||
NSRange (*orImp)(NSString*, SEL, unsigned);
|
||||
|
||||
if ([self hash] != [aString hash])
|
||||
return NO;
|
||||
|
@ -1491,33 +1502,37 @@ else
|
|||
if (!strLength)
|
||||
return NO;
|
||||
|
||||
scImp = (unichar (*)())[self methodForSelector: caiSel];
|
||||
ocImp = (unichar (*)())[aString methodForSelector: caiSel];
|
||||
srImp = (NSRange (*)())[self methodForSelector: ranSel];
|
||||
orImp = (NSRange (*)())[aString methodForSelector: ranSel];
|
||||
|
||||
while ((myIndex < myLength) && (strIndex < strLength))
|
||||
if ([self characterAtIndex: myIndex] ==
|
||||
[aString characterAtIndex: strIndex])
|
||||
{
|
||||
myIndex++;
|
||||
strIndex++;
|
||||
}
|
||||
else
|
||||
{
|
||||
myRange = [self rangeOfComposedCharacterSequenceAtIndex: myIndex];
|
||||
strRange = [aString rangeOfComposedCharacterSequenceAtIndex: strIndex];
|
||||
if ((myRange.length < 2) || (strRange.length < 2))
|
||||
return NO;
|
||||
else
|
||||
if ((*scImp)(self, caiSel, myIndex) == (*ocImp)(aString, caiSel, strIndex))
|
||||
{
|
||||
mySeq = [NSGSequence sequenceWithString: self range: myRange];
|
||||
strSeq = [NSGSequence sequenceWithString: aString range: strRange];
|
||||
if ([mySeq isEqual: strSeq])
|
||||
{
|
||||
myIndex += myRange.length;
|
||||
strIndex += strRange.length;
|
||||
}
|
||||
else
|
||||
return NO;
|
||||
myIndex++;
|
||||
strIndex++;
|
||||
}
|
||||
}
|
||||
if ((myIndex == myLength) && (strIndex == strLength))
|
||||
else
|
||||
{
|
||||
myRange = (*srImp)(self, ranSel, myIndex);
|
||||
strRange = (*orImp)(aString, ranSel, strIndex);
|
||||
if ((myRange.length < 2) || (strRange.length < 2))
|
||||
return NO;
|
||||
else
|
||||
{
|
||||
mySeq = [NSGSequence_class sequenceWithString: self range: myRange];
|
||||
strSeq = [NSGSequence_class sequenceWithString: aString range: strRange];
|
||||
if ([mySeq isEqual: strSeq])
|
||||
{
|
||||
myIndex += myRange.length;
|
||||
strIndex += strRange.length;
|
||||
}
|
||||
else
|
||||
return NO;
|
||||
}
|
||||
}
|
||||
if ((myIndex == myLength) && (strIndex == strLength))
|
||||
return YES;
|
||||
else
|
||||
return NO;
|
||||
|
@ -1707,8 +1722,8 @@ else
|
|||
return [self substringFromRange: NSMakeRange(0, myIndex)];
|
||||
else
|
||||
{
|
||||
mySeq = [NSGSequence sequenceWithString: self range: myRange];
|
||||
strSeq = [NSGSequence sequenceWithString: aString range: strRange];
|
||||
mySeq = [NSGSequence_class sequenceWithString: self range: myRange];
|
||||
strSeq = [NSGSequence_class sequenceWithString: aString range: strRange];
|
||||
if ([[mySeq lowercase] isEqual: [strSeq lowercase]])
|
||||
{
|
||||
myIndex += myRange.length;
|
||||
|
@ -1737,8 +1752,8 @@ else
|
|||
return [self substringFromRange: NSMakeRange(0, myIndex)];
|
||||
else
|
||||
{
|
||||
mySeq = [NSGSequence sequenceWithString: self range: myRange];
|
||||
strSeq = [NSGSequence sequenceWithString: aString range: strRange];
|
||||
mySeq = [NSGSequence_class sequenceWithString: self range: myRange];
|
||||
strSeq = [NSGSequence_class sequenceWithString: aString range: strRange];
|
||||
if ([mySeq isEqual: strSeq])
|
||||
{
|
||||
myIndex += myRange.length;
|
||||
|
@ -2566,7 +2581,6 @@ else
|
|||
if (len > 0)
|
||||
{
|
||||
int count = 0;
|
||||
SEL caiSel = @selector(characterAtIndex: );
|
||||
unichar (*caiImp)() = (unichar (*)())[self methodForSelector: caiSel];
|
||||
|
||||
while (count < len)
|
||||
|
@ -2594,7 +2608,7 @@ else
|
|||
while (count < len)
|
||||
{
|
||||
r = [self rangeOfComposedCharacterSequenceAtIndex: count];
|
||||
seq=[NSGSequence sequenceWithString: self range: r];
|
||||
seq=[NSGSequence_class sequenceWithString: self range: r];
|
||||
[[seq normalize] getCharacters: upoint];
|
||||
upoint += [seq length];
|
||||
count += r.length;
|
||||
|
|
Loading…
Reference in a new issue