mirror of
https://github.com/gnustep/libs-base.git
synced 2025-05-31 16:50:58 +00:00
Whitespace trimming optimisations.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@11332 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
a77ecf9d81
commit
d9f3e799b7
5 changed files with 168 additions and 127 deletions
|
@ -1,3 +1,11 @@
|
||||||
|
2001-11-07 Richard Frith-Macdonald <rfm@gnu.org>
|
||||||
|
|
||||||
|
* Headers/Foundation/NSString.h: removed stringByTrimming...Whitespace
|
||||||
|
methods as they just duplicate the stringByTrimming...Spaces
|
||||||
|
* Source/NSString.m: ditto
|
||||||
|
Optimised the space trimming methods - avoid using character sets and
|
||||||
|
creating unnecessary intermediary objects.
|
||||||
|
|
||||||
2001-11-07 Richard Frith-Macdonald <rfm@gnu.org>
|
2001-11-07 Richard Frith-Macdonald <rfm@gnu.org>
|
||||||
|
|
||||||
* Source/NSUserDefaults.m: force defaults data to be read/write
|
* Source/NSUserDefaults.m: force defaults data to be read/write
|
||||||
|
|
|
@ -369,10 +369,6 @@ enum {
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@interface NSString(GSTrimming)
|
@interface NSString(GSTrimming)
|
||||||
- (NSString*) stringByTrimmingLeadWhiteSpaces;
|
|
||||||
- (NSString*) stringByTrimmingTailWhiteSpaces;
|
|
||||||
- (NSString*) stringByTrimmingWhiteSpaces;
|
|
||||||
|
|
||||||
- (NSString*) stringByTrimmingLeadSpaces;
|
- (NSString*) stringByTrimmingLeadSpaces;
|
||||||
- (NSString*) stringByTrimmingTailSpaces;
|
- (NSString*) stringByTrimmingTailSpaces;
|
||||||
- (NSString*) stringByTrimmingSpaces;
|
- (NSString*) stringByTrimmingSpaces;
|
||||||
|
|
|
@ -78,7 +78,7 @@
|
||||||
|
|
||||||
@implementation NSMutableBitmapCharSet
|
@implementation NSMutableBitmapCharSet
|
||||||
|
|
||||||
- init
|
- (id) init
|
||||||
{
|
{
|
||||||
return [self initWithBitmap: NULL];
|
return [self initWithBitmap: NULL];
|
||||||
}
|
}
|
||||||
|
@ -129,7 +129,9 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = aRange.location; i < NSMaxRange(aRange); i++)
|
for (i = aRange.location; i < NSMaxRange(aRange); i++)
|
||||||
SETBIT(_data[i/8], i % 8);
|
{
|
||||||
|
SETBIT(_data[i/8], i % 8);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) addCharactersInString: (NSString*)aString
|
- (void) addCharactersInString: (NSString*)aString
|
||||||
|
@ -168,7 +170,9 @@
|
||||||
|
|
||||||
other_bytes = [[otherSet bitmapRepresentation] bytes];
|
other_bytes = [[otherSet bitmapRepresentation] bytes];
|
||||||
for (i = 0; i < BITMAP_SIZE; i++)
|
for (i = 0; i < BITMAP_SIZE; i++)
|
||||||
_data[i] = (_data[i] | other_bytes[i]);
|
{
|
||||||
|
_data[i] = (_data[i] | other_bytes[i]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) formIntersectionWithCharacterSet: (NSCharacterSet *)otherSet
|
- (void) formIntersectionWithCharacterSet: (NSCharacterSet *)otherSet
|
||||||
|
@ -178,7 +182,9 @@
|
||||||
|
|
||||||
other_bytes = [[otherSet bitmapRepresentation] bytes];
|
other_bytes = [[otherSet bitmapRepresentation] bytes];
|
||||||
for (i = 0; i < BITMAP_SIZE; i++)
|
for (i = 0; i < BITMAP_SIZE; i++)
|
||||||
_data[i] = (_data[i] & other_bytes[i]);
|
{
|
||||||
|
_data[i] = (_data[i] & other_bytes[i]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) removeCharactersInRange: (NSRange)aRange
|
- (void) removeCharactersInRange: (NSRange)aRange
|
||||||
|
@ -193,7 +199,9 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = aRange.location; i < NSMaxRange(aRange); i++)
|
for (i = aRange.location; i < NSMaxRange(aRange); i++)
|
||||||
|
{
|
||||||
CLRBIT(_data[i/8], i % 8);
|
CLRBIT(_data[i/8], i % 8);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) removeCharactersInString: (NSString*)aString
|
- (void) removeCharactersInString: (NSString*)aString
|
||||||
|
@ -231,7 +239,9 @@
|
||||||
unsigned i;
|
unsigned i;
|
||||||
|
|
||||||
for (i = 0; i < BITMAP_SIZE; i++)
|
for (i = 0; i < BITMAP_SIZE; i++)
|
||||||
_data[i] = ~_data[i];
|
{
|
||||||
|
_data[i] = ~_data[i];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
|
@ -46,22 +46,25 @@ static NSLock* cache_lock = nil;
|
||||||
|
|
||||||
if (one_time == NO)
|
if (one_time == NO)
|
||||||
{
|
{
|
||||||
int i;
|
unsigned i;
|
||||||
|
|
||||||
for (i = 0; i < MAX_STANDARD_SETS; i++)
|
for (i = 0; i < MAX_STANDARD_SETS; i++)
|
||||||
cache_set[i] = 0;
|
{
|
||||||
|
cache_set[i] = 0;
|
||||||
|
}
|
||||||
one_time = YES;
|
one_time = YES;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Provide a default object for allocation */
|
/* Provide a default object for allocation */
|
||||||
+ allocWithZone: (NSZone *)zone
|
+ (id) allocWithZone: (NSZone*)zone
|
||||||
{
|
{
|
||||||
return NSAllocateObject([NSBitmapCharSet self], 0, zone);
|
return NSAllocateObject([NSBitmapCharSet self], 0, zone);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Creating standard character sets
|
// Creating standard character sets
|
||||||
|
|
||||||
+ (NSCharacterSet *) _bitmapForSet: (NSString *)setname number: (int)number
|
+ (NSCharacterSet*) _bitmapForSet: (NSString*)setname number: (int)number
|
||||||
{
|
{
|
||||||
NSCharacterSet *set;
|
NSCharacterSet *set;
|
||||||
NSArray *paths;
|
NSArray *paths;
|
||||||
|
@ -109,9 +112,11 @@ static NSLock* cache_lock = nil;
|
||||||
/* NOT REACHED */
|
/* NOT REACHED */
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
/* Else cache the set */
|
{
|
||||||
cache_set[number] = RETAIN(set);
|
/* Else cache the set */
|
||||||
|
cache_set[number] = RETAIN(set);
|
||||||
|
|
||||||
|
}
|
||||||
NS_HANDLER
|
NS_HANDLER
|
||||||
[cache_lock unlock];
|
[cache_lock unlock];
|
||||||
[localException raise];
|
[localException raise];
|
||||||
|
@ -126,82 +131,83 @@ static NSLock* cache_lock = nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
+ (NSCharacterSet *)alphanumericCharacterSet
|
+ (NSCharacterSet*) alphanumericCharacterSet
|
||||||
{
|
{
|
||||||
return [self _bitmapForSet: @"alphanumericCharSet" number: 0];
|
return [self _bitmapForSet: @"alphanumericCharSet" number: 0];
|
||||||
}
|
}
|
||||||
|
|
||||||
+ (NSCharacterSet *)controlCharacterSet
|
+ (NSCharacterSet*) controlCharacterSet
|
||||||
{
|
{
|
||||||
return [self _bitmapForSet: @"controlCharSet" number: 1];
|
return [self _bitmapForSet: @"controlCharSet" number: 1];
|
||||||
}
|
}
|
||||||
|
|
||||||
+ (NSCharacterSet *)decimalDigitCharacterSet
|
+ (NSCharacterSet*) decimalDigitCharacterSet
|
||||||
{
|
{
|
||||||
return [self _bitmapForSet: @"decimalDigitCharSet" number: 2];
|
return [self _bitmapForSet: @"decimalDigitCharSet" number: 2];
|
||||||
}
|
}
|
||||||
|
|
||||||
+ (NSCharacterSet *)decomposableCharacterSet
|
+ (NSCharacterSet*) decomposableCharacterSet
|
||||||
{
|
{
|
||||||
return [self _bitmapForSet: @"decomposableCharSet" number: 3];
|
return [self _bitmapForSet: @"decomposableCharSet" number: 3];
|
||||||
}
|
}
|
||||||
|
|
||||||
+ (NSCharacterSet *)illegalCharacterSet
|
+ (NSCharacterSet*) illegalCharacterSet
|
||||||
{
|
{
|
||||||
return [self _bitmapForSet: @"illegalCharSet" number: 4];
|
return [self _bitmapForSet: @"illegalCharSet" number: 4];
|
||||||
}
|
}
|
||||||
|
|
||||||
+ (NSCharacterSet *)letterCharacterSet
|
+ (NSCharacterSet*) letterCharacterSet
|
||||||
{
|
{
|
||||||
return [self _bitmapForSet: @"letterCharSet" number: 5];
|
return [self _bitmapForSet: @"letterCharSet" number: 5];
|
||||||
}
|
}
|
||||||
|
|
||||||
+ (NSCharacterSet *)lowercaseLetterCharacterSet
|
+ (NSCharacterSet*) lowercaseLetterCharacterSet
|
||||||
{
|
{
|
||||||
return [self _bitmapForSet: @"lowercaseLetterCharSet" number: 6];
|
return [self _bitmapForSet: @"lowercaseLetterCharSet" number: 6];
|
||||||
}
|
}
|
||||||
|
|
||||||
+ (NSCharacterSet *)nonBaseCharacterSet
|
+ (NSCharacterSet*) nonBaseCharacterSet
|
||||||
{
|
{
|
||||||
return [self _bitmapForSet: @"nonBaseCharSet" number: 7];
|
return [self _bitmapForSet: @"nonBaseCharSet" number: 7];
|
||||||
}
|
}
|
||||||
|
|
||||||
+ (NSCharacterSet *)punctuationCharacterSet;
|
+ (NSCharacterSet*) punctuationCharacterSet;
|
||||||
{
|
{
|
||||||
return [self _bitmapForSet: @"punctuationCharSet" number: 8];
|
return [self _bitmapForSet: @"punctuationCharSet" number: 8];
|
||||||
}
|
}
|
||||||
|
|
||||||
+ (NSCharacterSet *)symbolAndOperatorCharacterSet;
|
+ (NSCharacterSet*) symbolAndOperatorCharacterSet;
|
||||||
{
|
{
|
||||||
return [self _bitmapForSet: @"symbolAndOperatorCharSet" number: 9];
|
return [self _bitmapForSet: @"symbolAndOperatorCharSet" number: 9];
|
||||||
}
|
}
|
||||||
|
|
||||||
+ (NSCharacterSet *)uppercaseLetterCharacterSet
|
+ (NSCharacterSet*) uppercaseLetterCharacterSet
|
||||||
{
|
{
|
||||||
return [self _bitmapForSet: @"uppercaseLetterCharSet" number: 10];
|
return [self _bitmapForSet: @"uppercaseLetterCharSet" number: 10];
|
||||||
}
|
}
|
||||||
|
|
||||||
+ (NSCharacterSet *)whitespaceAndNewlineCharacterSet
|
+ (NSCharacterSet*) whitespaceAndNewlineCharacterSet
|
||||||
{
|
{
|
||||||
return [self _bitmapForSet: @"whitespaceAndNlCharSet" number: 11];
|
return [self _bitmapForSet: @"whitespaceAndNlCharSet" number: 11];
|
||||||
}
|
}
|
||||||
|
|
||||||
+ (NSCharacterSet *)whitespaceCharacterSet
|
+ (NSCharacterSet*) whitespaceCharacterSet
|
||||||
{
|
{
|
||||||
return [self _bitmapForSet: @"whitespaceCharSet" number: 12];
|
return [self _bitmapForSet: @"whitespaceCharSet" number: 12];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Creating custom character sets
|
// Creating custom character sets
|
||||||
|
|
||||||
+ (NSCharacterSet *)characterSetWithBitmapRepresentation: (NSData *)data
|
+ (NSCharacterSet*) characterSetWithBitmapRepresentation: (NSData*)data
|
||||||
{
|
{
|
||||||
return AUTORELEASE([[NSBitmapCharSet alloc] initWithBitmap: data]);
|
return AUTORELEASE([[NSBitmapCharSet alloc] initWithBitmap: data]);
|
||||||
}
|
}
|
||||||
|
|
||||||
+ (NSCharacterSet *)characterSetWithCharactersInString: (NSString *)aString
|
+ (NSCharacterSet*) characterSetWithCharactersInString: (NSString*)aString
|
||||||
{
|
{
|
||||||
int i, length;
|
unsigned i;
|
||||||
char *bytes;
|
unsigned length;
|
||||||
|
unsigned char *bytes;
|
||||||
NSMutableData *bitmap = [NSMutableData dataWithLength: BITMAP_SIZE];
|
NSMutableData *bitmap = [NSMutableData dataWithLength: BITMAP_SIZE];
|
||||||
|
|
||||||
if (!aString)
|
if (!aString)
|
||||||
|
@ -213,19 +219,20 @@ static NSLock* cache_lock = nil;
|
||||||
|
|
||||||
length = [aString length];
|
length = [aString length];
|
||||||
bytes = [bitmap mutableBytes];
|
bytes = [bitmap mutableBytes];
|
||||||
for (i=0; i < length; i++)
|
for (i = 0; i < length; i++)
|
||||||
{
|
{
|
||||||
unichar letter = [aString characterAtIndex: i];
|
unichar letter = [aString characterAtIndex: i];
|
||||||
|
|
||||||
SETBIT(bytes[letter/8], letter % 8);
|
SETBIT(bytes[letter/8], letter % 8);
|
||||||
}
|
}
|
||||||
|
|
||||||
return [self characterSetWithBitmapRepresentation: bitmap];
|
return [self characterSetWithBitmapRepresentation: bitmap];
|
||||||
}
|
}
|
||||||
|
|
||||||
+ (NSCharacterSet *)characterSetWithRange: (NSRange)aRange
|
+ (NSCharacterSet*)characterSetWithRange: (NSRange)aRange
|
||||||
{
|
{
|
||||||
int i;
|
unsigned i;
|
||||||
char *bytes;
|
unsigned char *bytes;
|
||||||
NSMutableData *bitmap = [NSMutableData dataWithLength: BITMAP_SIZE];
|
NSMutableData *bitmap = [NSMutableData dataWithLength: BITMAP_SIZE];
|
||||||
|
|
||||||
if (NSMaxRange(aRange) > UNICODE_SIZE)
|
if (NSMaxRange(aRange) > UNICODE_SIZE)
|
||||||
|
@ -235,14 +242,15 @@ static NSLock* cache_lock = nil;
|
||||||
/* NOT REACHED */
|
/* NOT REACHED */
|
||||||
}
|
}
|
||||||
|
|
||||||
bytes = (char *)[bitmap mutableBytes];
|
bytes = (unsigned char*)[bitmap mutableBytes];
|
||||||
for (i=aRange.location; i < NSMaxRange(aRange); i++)
|
for (i = aRange.location; i < NSMaxRange(aRange); i++)
|
||||||
|
{
|
||||||
SETBIT(bytes[i/8], i % 8);
|
SETBIT(bytes[i/8], i % 8);
|
||||||
|
}
|
||||||
return [self characterSetWithBitmapRepresentation: bitmap];
|
return [self characterSetWithBitmapRepresentation: bitmap];
|
||||||
}
|
}
|
||||||
|
|
||||||
+ (NSCharacterSet *)characterSetWithContentsOfFile: (NSString *)aFile
|
+ (NSCharacterSet*) characterSetWithContentsOfFile: (NSString*)aFile
|
||||||
{
|
{
|
||||||
if ([@"bitmap" isEqual: [aFile pathExtension]])
|
if ([@"bitmap" isEqual: [aFile pathExtension]])
|
||||||
{
|
{
|
||||||
|
@ -253,13 +261,13 @@ static NSLock* cache_lock = nil;
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSData *)bitmapRepresentation
|
- (NSData*) bitmapRepresentation
|
||||||
{
|
{
|
||||||
[self subclassResponsibility: _cmd];
|
[self subclassResponsibility: _cmd];
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (BOOL)characterIsMember: (unichar)aCharacter
|
- (BOOL) characterIsMember: (unichar)aCharacter
|
||||||
{
|
{
|
||||||
[self subclassResponsibility: _cmd];
|
[self subclassResponsibility: _cmd];
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -282,35 +290,41 @@ static NSLock* cache_lock = nil;
|
||||||
return YES;
|
return YES;
|
||||||
if ([anObject isKindOfClass: [NSCharacterSet class]])
|
if ([anObject isKindOfClass: [NSCharacterSet class]])
|
||||||
{
|
{
|
||||||
int i;
|
unsigned i;
|
||||||
|
|
||||||
for (i = 0; i <= 0xffff; i++)
|
for (i = 0; i <= 0xffff; i++)
|
||||||
if ([self characterIsMember: (unichar)i] !=
|
{
|
||||||
[anObject characterIsMember: (unichar)i])
|
if ([self characterIsMember: (unichar)i]
|
||||||
return NO;
|
!= [anObject characterIsMember: (unichar)i])
|
||||||
|
{
|
||||||
|
return NO;
|
||||||
|
}
|
||||||
|
}
|
||||||
return YES;
|
return YES;
|
||||||
}
|
}
|
||||||
return NO;
|
return NO;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSCharacterSet *)invertedSet
|
- (NSCharacterSet*) invertedSet
|
||||||
{
|
{
|
||||||
int i, length;
|
unsigned i;
|
||||||
char *bytes;
|
unsigned length;
|
||||||
NSMutableData *bitmap;
|
unsigned char *bytes;
|
||||||
|
NSMutableData *bitmap;
|
||||||
|
|
||||||
bitmap = AUTORELEASE([[self bitmapRepresentation] mutableCopy]);
|
bitmap = AUTORELEASE([[self bitmapRepresentation] mutableCopy]);
|
||||||
length = [bitmap length];
|
length = [bitmap length];
|
||||||
bytes = [bitmap mutableBytes];
|
bytes = [bitmap mutableBytes];
|
||||||
for (i=0; i < length; i++)
|
for (i = 0; i < length; i++)
|
||||||
|
{
|
||||||
bytes[i] = ~bytes[i];
|
bytes[i] = ~bytes[i];
|
||||||
|
}
|
||||||
return [[self class] characterSetWithBitmapRepresentation: bitmap];
|
return [[self class] characterSetWithBitmapRepresentation: bitmap];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// NSCopying, NSMutableCopying
|
// NSCopying, NSMutableCopying
|
||||||
- (id) copyWithZone: (NSZone *)zone
|
- (id) copyWithZone: (NSZone*)zone
|
||||||
{
|
{
|
||||||
if (NSShouldRetainWithZone(self, zone))
|
if (NSShouldRetainWithZone(self, zone))
|
||||||
return RETAIN(self);
|
return RETAIN(self);
|
||||||
|
@ -318,7 +332,7 @@ static NSLock* cache_lock = nil;
|
||||||
return NSCopyObject (self, 0, zone);
|
return NSCopyObject (self, 0, zone);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (id)mutableCopyWithZone: (NSZone *)zone
|
- (id) mutableCopyWithZone: (NSZone*)zone
|
||||||
{
|
{
|
||||||
NSData *bitmap;
|
NSData *bitmap;
|
||||||
bitmap = [self bitmapRepresentation];
|
bitmap = [self bitmapRepresentation];
|
||||||
|
@ -330,62 +344,62 @@ static NSLock* cache_lock = nil;
|
||||||
@implementation NSMutableCharacterSet
|
@implementation NSMutableCharacterSet
|
||||||
|
|
||||||
/* Provide a default object for allocation */
|
/* Provide a default object for allocation */
|
||||||
+ allocWithZone: (NSZone *)zone
|
+ (id) allocWithZone: (NSZone*)zone
|
||||||
{
|
{
|
||||||
return NSAllocateObject([NSMutableBitmapCharSet self], 0, zone);
|
return NSAllocateObject([NSMutableBitmapCharSet self], 0, zone);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Override this from NSCharacterSet to create the correct class */
|
/* Override this from NSCharacterSet to create the correct class */
|
||||||
+ (NSCharacterSet *)characterSetWithBitmapRepresentation: (NSData *)data
|
+ (NSCharacterSet*) characterSetWithBitmapRepresentation: (NSData*)data
|
||||||
{
|
{
|
||||||
return AUTORELEASE([[NSMutableBitmapCharSet alloc] initWithBitmap: data]);
|
return AUTORELEASE([[NSMutableBitmapCharSet alloc] initWithBitmap: data]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Mutable subclasses must implement ALL of these methods. */
|
/* Mutable subclasses must implement ALL of these methods. */
|
||||||
- (void)addCharactersInRange: (NSRange)aRange
|
- (void) addCharactersInRange: (NSRange)aRange
|
||||||
{
|
{
|
||||||
[self subclassResponsibility: _cmd];
|
[self subclassResponsibility: _cmd];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)addCharactersInString: (NSString *)aString
|
- (void) addCharactersInString: (NSString*)aString
|
||||||
{
|
{
|
||||||
[self subclassResponsibility: _cmd];
|
[self subclassResponsibility: _cmd];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)formUnionWithCharacterSet: (NSCharacterSet *)otherSet
|
- (void) formUnionWithCharacterSet: (NSCharacterSet*)otherSet
|
||||||
{
|
{
|
||||||
[self subclassResponsibility: _cmd];
|
[self subclassResponsibility: _cmd];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)formIntersectionWithCharacterSet: (NSCharacterSet *)otherSet
|
- (void) formIntersectionWithCharacterSet: (NSCharacterSet*)otherSet
|
||||||
{
|
{
|
||||||
[self subclassResponsibility: _cmd];
|
[self subclassResponsibility: _cmd];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)removeCharactersInRange: (NSRange)aRange
|
- (void) removeCharactersInRange: (NSRange)aRange
|
||||||
{
|
{
|
||||||
[self subclassResponsibility: _cmd];
|
[self subclassResponsibility: _cmd];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)removeCharactersInString: (NSString *)aString
|
- (void) removeCharactersInString: (NSString*)aString
|
||||||
{
|
{
|
||||||
[self subclassResponsibility: _cmd];
|
[self subclassResponsibility: _cmd];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)invert
|
- (void) invert
|
||||||
{
|
{
|
||||||
[self subclassResponsibility: _cmd];
|
[self subclassResponsibility: _cmd];
|
||||||
}
|
}
|
||||||
|
|
||||||
// NSCopying, NSMutableCopying
|
// NSCopying, NSMutableCopying
|
||||||
- (id)copyWithZone: (NSZone *)zone
|
- (id) copyWithZone: (NSZone*)zone
|
||||||
{
|
{
|
||||||
NSData *bitmap;
|
NSData *bitmap;
|
||||||
bitmap = [self bitmapRepresentation];
|
bitmap = [self bitmapRepresentation];
|
||||||
return [[NSBitmapCharSet allocWithZone: zone] initWithBitmap: bitmap];
|
return [[NSBitmapCharSet allocWithZone: zone] initWithBitmap: bitmap];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (id)mutableCopyWithZone: (NSZone *)zone
|
- (id) mutableCopyWithZone: (NSZone*)zone
|
||||||
{
|
{
|
||||||
return [super mutableCopyWithZone: zone];
|
return [super mutableCopyWithZone: zone];
|
||||||
}
|
}
|
||||||
|
|
|
@ -3604,72 +3604,81 @@ handle_printf_atsign (FILE *stream,
|
||||||
|
|
||||||
@implementation NSString (GSTrimming)
|
@implementation NSString (GSTrimming)
|
||||||
|
|
||||||
- (NSString*) stringByTrimmingLeadWhiteSpaces
|
|
||||||
{
|
|
||||||
NSCharacterSet *nonSPSet;
|
|
||||||
NSRange nonSPCharRange;
|
|
||||||
|
|
||||||
nonSPSet = [[NSCharacterSet whitespaceAndNewlineCharacterSet] invertedSet];
|
|
||||||
nonSPCharRange = [self rangeOfCharacterFromSet: nonSPSet];
|
|
||||||
|
|
||||||
if (nonSPCharRange.length > 0)
|
|
||||||
return [self substringFromIndex: nonSPCharRange.location];
|
|
||||||
else
|
|
||||||
return @"";
|
|
||||||
}
|
|
||||||
|
|
||||||
- (NSString*) stringByTrimmingTailWhiteSpaces
|
|
||||||
{
|
|
||||||
NSCharacterSet *nonSPSet;
|
|
||||||
NSRange nonSPCharRange;
|
|
||||||
|
|
||||||
nonSPSet= [[NSCharacterSet whitespaceAndNewlineCharacterSet] invertedSet];
|
|
||||||
nonSPCharRange = [self rangeOfCharacterFromSet: nonSPSet
|
|
||||||
options: NSBackwardsSearch];
|
|
||||||
if (nonSPCharRange.length > 0)
|
|
||||||
return [self substringToIndex: nonSPCharRange.location+1];
|
|
||||||
else
|
|
||||||
return @"";
|
|
||||||
}
|
|
||||||
|
|
||||||
- (NSString*) stringByTrimmingWhiteSpaces
|
|
||||||
{
|
|
||||||
return [[self stringByTrimmingLeadWhiteSpaces]
|
|
||||||
stringByTrimmingTailWhiteSpaces];
|
|
||||||
}
|
|
||||||
|
|
||||||
- (NSString*) stringByTrimmingLeadSpaces
|
- (NSString*) stringByTrimmingLeadSpaces
|
||||||
{
|
{
|
||||||
NSMutableString *tmp = [self mutableCopy];
|
unsigned length = [self length];
|
||||||
NSString *str;
|
|
||||||
|
|
||||||
[tmp trimLeadSpaces];
|
if (length > 0)
|
||||||
str = AUTORELEASE([tmp copy]);
|
{
|
||||||
RELEASE(tmp);
|
unsigned location = 0;
|
||||||
return str;
|
unichar (*caiImp)(NSString*, SEL, unsigned);
|
||||||
|
|
||||||
|
caiImp = (unichar (*)())[self methodForSelector: caiSel];
|
||||||
|
while (location < length && isspace((*caiImp)(self, caiSel, location)))
|
||||||
|
{
|
||||||
|
location++;
|
||||||
|
}
|
||||||
|
if (location > 0)
|
||||||
|
{
|
||||||
|
return [self substringFromIndex: location];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSString*) stringByTrimmingTailSpaces
|
- (NSString*) stringByTrimmingTailSpaces
|
||||||
{
|
{
|
||||||
NSMutableString *tmp = [self mutableCopy];
|
unsigned length = [self length];
|
||||||
NSString *str;
|
|
||||||
|
|
||||||
[tmp trimTailSpaces];
|
if (length > 0)
|
||||||
str = AUTORELEASE([tmp copy]);
|
{
|
||||||
RELEASE(tmp);
|
unsigned location = length;
|
||||||
return str;
|
unichar (*caiImp)(NSString*, SEL, unsigned);
|
||||||
|
|
||||||
|
caiImp = (unichar (*)())[self methodForSelector: caiSel];
|
||||||
|
while (location > 0)
|
||||||
|
{
|
||||||
|
if (!isspace((*caiImp)(self, caiSel, --location)))
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (location < length-1)
|
||||||
|
{
|
||||||
|
return [self substringToIndex: location+1];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSString*) stringByTrimmingSpaces
|
- (NSString*) stringByTrimmingSpaces
|
||||||
{
|
{
|
||||||
NSMutableString *tmp = [self mutableCopy];
|
unsigned length = [self length];
|
||||||
NSString *str;
|
|
||||||
|
|
||||||
[tmp trimLeadSpaces];
|
if (length > 0)
|
||||||
[tmp trimTailSpaces];
|
{
|
||||||
str = AUTORELEASE([tmp copy]);
|
unsigned start = 0;
|
||||||
RELEASE(tmp);
|
unsigned end = length;
|
||||||
return str;
|
unichar (*caiImp)(NSString*, SEL, unsigned);
|
||||||
|
|
||||||
|
caiImp = (unichar (*)())[self methodForSelector: caiSel];
|
||||||
|
while (start < length && isspace((*caiImp)(self, caiSel, start)))
|
||||||
|
{
|
||||||
|
start++;
|
||||||
|
}
|
||||||
|
while (end > start)
|
||||||
|
{
|
||||||
|
if (!isspace((*caiImp)(self, caiSel, --end)))
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (start > 0 || end < length-1)
|
||||||
|
{
|
||||||
|
return [self substringFromRange: NSMakeRange(start, end + 1 - start)];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
@ -3678,18 +3687,22 @@ handle_printf_atsign (FILE *stream,
|
||||||
|
|
||||||
- (void) trimLeadSpaces
|
- (void) trimLeadSpaces
|
||||||
{
|
{
|
||||||
unsigned location = 0;
|
|
||||||
unsigned length = [self length];
|
unsigned length = [self length];
|
||||||
unichar (*caiImp)(NSString*, SEL, unsigned);
|
|
||||||
|
|
||||||
caiImp = (unichar (*)())[self methodForSelector: caiSel];
|
if (length > 0)
|
||||||
while (location < length && isspace((*caiImp)(self, caiSel, location)))
|
|
||||||
{
|
{
|
||||||
location++;
|
unsigned location = 0;
|
||||||
}
|
unichar (*caiImp)(NSString*, SEL, unsigned);
|
||||||
if (location > 0)
|
|
||||||
{
|
caiImp = (unichar (*)())[self methodForSelector: caiSel];
|
||||||
[self deleteCharactersInRange: NSMakeRange(0,location)];
|
while (location < length && isspace((*caiImp)(self, caiSel, location)))
|
||||||
|
{
|
||||||
|
location++;
|
||||||
|
}
|
||||||
|
if (location > 0)
|
||||||
|
{
|
||||||
|
[self deleteCharactersInRange: NSMakeRange(0,location)];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue