mirror of
https://github.com/gnustep/libs-base.git
synced 2025-05-31 00:30:53 +00:00
all methods): Implemented.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@593 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
ee92d8fe84
commit
52d9a70db8
1 changed files with 153 additions and 63 deletions
|
@ -21,77 +21,131 @@
|
||||||
Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <Foundation/NSCharacterSet.h>
|
#include <Foundation/NSBitmapCharSet.h>
|
||||||
|
#include <Foundation/NSException.h>
|
||||||
|
#include <Foundation/NSBundle.h>
|
||||||
|
#include <Foundation/NSData.h>
|
||||||
|
|
||||||
|
/* FIXME: Where should bitmaps go? Maybe should be defined with configure */
|
||||||
|
#ifndef BITMAP_PATH
|
||||||
|
#define BITMAP_PATH @"/usr/local/share/objects"
|
||||||
|
#endif
|
||||||
|
|
||||||
@implementation NSCharacterSet
|
@implementation NSCharacterSet
|
||||||
|
|
||||||
|
/* Provide a default object for allocation */
|
||||||
|
+ allocWithZone:(NSZone *)zone
|
||||||
|
{
|
||||||
|
return NSAllocateObject([NSBitmapCharSet self], 0, zone);
|
||||||
|
}
|
||||||
|
|
||||||
// Creating standard character sets
|
// Creating standard character sets
|
||||||
|
|
||||||
|
+ (NSData *)_bitmapForSet:(NSString *)setname
|
||||||
|
{
|
||||||
|
NSString *path;
|
||||||
|
|
||||||
|
path = [NSBundle pathForResource:setname
|
||||||
|
ofType:@".dat"
|
||||||
|
inDirectory:BITMAP_PATH
|
||||||
|
withVersion:0];
|
||||||
|
/* This is for testing purposes */
|
||||||
|
if (path == nil || [path length] == 0)
|
||||||
|
{
|
||||||
|
path = [NSBundle pathForResource:setname
|
||||||
|
ofType:@".dat"
|
||||||
|
inDirectory:@"../share"
|
||||||
|
withVersion:0];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (path == nil || [path length] == 0)
|
||||||
|
{
|
||||||
|
[NSException raise:NSGenericException
|
||||||
|
format:@"Could not find bitmap file %s", [setname cString]];
|
||||||
|
/* NOT REACHED */
|
||||||
|
}
|
||||||
|
|
||||||
|
return [NSData dataWithContentsOfFile:path];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
+ (NSCharacterSet *)alphanumericCharacterSet
|
+ (NSCharacterSet *)alphanumericCharacterSet
|
||||||
{
|
{
|
||||||
[self notImplemented:_cmd];
|
NSData *data = [self _bitmapForSet:@"alphanumCharSet"];
|
||||||
return 0;
|
|
||||||
|
return [self characterSetWithBitmapRepresentation:data];
|
||||||
}
|
}
|
||||||
|
|
||||||
+ (NSCharacterSet *)controlCharacterSet
|
+ (NSCharacterSet *)controlCharacterSet
|
||||||
{
|
{
|
||||||
[self notImplemented:_cmd];
|
NSData *data = [self _bitmapForSet:@"controlCharSet"];
|
||||||
return 0;
|
|
||||||
|
return [self characterSetWithBitmapRepresentation:data];
|
||||||
}
|
}
|
||||||
|
|
||||||
+ (NSCharacterSet *)decimalDigitCharacterSet
|
+ (NSCharacterSet *)decimalDigitCharacterSet
|
||||||
{
|
{
|
||||||
[self notImplemented:_cmd];
|
NSData *data = [self _bitmapForSet:@"decimalCharSet"];
|
||||||
return 0;
|
|
||||||
|
return [self characterSetWithBitmapRepresentation:data];
|
||||||
}
|
}
|
||||||
|
|
||||||
+ (NSCharacterSet *)decomposableCharacterSet
|
+ (NSCharacterSet *)decomposableCharacterSet
|
||||||
{
|
{
|
||||||
[self notImplemented:_cmd];
|
NSData *data = [self _bitmapForSet:@"decomposableCharSet"];
|
||||||
return 0;
|
|
||||||
|
fprintf(stderr, "Warning: Decomposable set not yet fully specified\n");
|
||||||
|
return [self characterSetWithBitmapRepresentation:data];
|
||||||
}
|
}
|
||||||
|
|
||||||
+ (NSCharacterSet *)illegalCharacterSet
|
+ (NSCharacterSet *)illegalCharacterSet
|
||||||
{
|
{
|
||||||
[self notImplemented:_cmd];
|
NSData *data = [self _bitmapForSet:@"illegalCharSet"];
|
||||||
return 0;
|
|
||||||
|
fprintf(stderr, "Warning: Illegal set not yet fully specified\n");
|
||||||
|
return [self characterSetWithBitmapRepresentation:data];
|
||||||
}
|
}
|
||||||
|
|
||||||
+ (NSCharacterSet *)letterCharacterSet
|
+ (NSCharacterSet *)letterCharacterSet
|
||||||
{
|
{
|
||||||
[self notImplemented:_cmd];
|
NSData *data = [self _bitmapForSet:@"lettercharCharSet"];
|
||||||
return 0;
|
|
||||||
|
return [self characterSetWithBitmapRepresentation:data];
|
||||||
}
|
}
|
||||||
|
|
||||||
+ (NSCharacterSet *)lowercaseLetterCharacterSet
|
+ (NSCharacterSet *)lowercaseLetterCharacterSet
|
||||||
{
|
{
|
||||||
[self notImplemented:_cmd];
|
NSData *data = [self _bitmapForSet:@"lowercaseCharSet"];
|
||||||
return 0;
|
|
||||||
|
return [self characterSetWithBitmapRepresentation:data];
|
||||||
}
|
}
|
||||||
|
|
||||||
+ (NSCharacterSet *)nonBaseCharacterSet
|
+ (NSCharacterSet *)nonBaseCharacterSet
|
||||||
{
|
{
|
||||||
[self notImplemented:_cmd];
|
NSData *data = [self _bitmapForSet:@"nonbaseCharSet"];
|
||||||
return 0;
|
|
||||||
|
return [self characterSetWithBitmapRepresentation:data];
|
||||||
}
|
}
|
||||||
|
|
||||||
+ (NSCharacterSet *)uppercaseLetterCharacterSet
|
+ (NSCharacterSet *)uppercaseLetterCharacterSet
|
||||||
{
|
{
|
||||||
[self notImplemented:_cmd];
|
NSData *data = [self _bitmapForSet:@"uppercaseCharSet"];
|
||||||
return 0;
|
|
||||||
|
return [self characterSetWithBitmapRepresentation:data];
|
||||||
}
|
}
|
||||||
|
|
||||||
+ (NSCharacterSet *)whitespaceAndNewlineCharacterSet
|
+ (NSCharacterSet *)whitespaceAndNewlineCharacterSet
|
||||||
{
|
{
|
||||||
[self notImplemented:_cmd];
|
NSData *data = [self _bitmapForSet:@"whitespaceandnlCharSet"];
|
||||||
return 0;
|
|
||||||
|
return [self characterSetWithBitmapRepresentation:data];
|
||||||
}
|
}
|
||||||
|
|
||||||
+ (NSCharacterSet *)whitespaceCharacterSet
|
+ (NSCharacterSet *)whitespaceCharacterSet
|
||||||
{
|
{
|
||||||
[self notImplemented:_cmd];
|
NSData *data = [self _bitmapForSet:@"whitespaceCharSet"];
|
||||||
return 0;
|
|
||||||
|
return [self characterSetWithBitmapRepresentation:data];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -99,123 +153,159 @@
|
||||||
|
|
||||||
+ (NSCharacterSet *)characterSetWithBitmapRepresentation:(NSData *)data
|
+ (NSCharacterSet *)characterSetWithBitmapRepresentation:(NSData *)data
|
||||||
{
|
{
|
||||||
[self notImplemented:_cmd];
|
return [[[NSBitmapCharSet alloc] initWithBitmap:data] autorelease];
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
+ (NSCharacterSet *)characterSetWithCharactersInString:(NSString *)aString
|
+ (NSCharacterSet *)characterSetWithCharactersInString:(NSString *)aString
|
||||||
{
|
{
|
||||||
[self notImplemented:_cmd];
|
int i, length;
|
||||||
return 0;
|
char *bytes;
|
||||||
|
NSMutableData *bitmap = [NSMutableData dataWithLength:BITMAP_SIZE];
|
||||||
|
|
||||||
|
if (!aString)
|
||||||
|
{
|
||||||
|
[NSException raise:NSInvalidArgumentException
|
||||||
|
format:@"Creating character set with nil string"];
|
||||||
|
/* NOT REACHED */
|
||||||
|
}
|
||||||
|
|
||||||
|
length = [aString length];
|
||||||
|
bytes = [bitmap mutableBytes];
|
||||||
|
for (i=0; i < length; i++)
|
||||||
|
{
|
||||||
|
unichar letter = [aString characterAtIndex:i];
|
||||||
|
SETBIT(bytes[letter/8], letter % 8);
|
||||||
|
}
|
||||||
|
|
||||||
|
return [self characterSetWithBitmapRepresentation:bitmap];
|
||||||
}
|
}
|
||||||
|
|
||||||
+ (NSCharacterSet *)characterSetWithRange:(NSRange)aRange
|
+ (NSCharacterSet *)characterSetWithRange:(NSRange)aRange
|
||||||
{
|
{
|
||||||
[self notImplemented:_cmd];
|
int i;
|
||||||
return 0;
|
char *bytes;
|
||||||
|
NSMutableData *bitmap = [NSMutableData dataWithLength:BITMAP_SIZE];
|
||||||
|
|
||||||
|
if (NSMaxRange(aRange) > UNICODE_SIZE)
|
||||||
|
{
|
||||||
|
[NSException raise:NSInvalidArgumentException
|
||||||
|
format:@"Specified range exceeds character set"];
|
||||||
|
/* NOT REACHED */
|
||||||
|
}
|
||||||
|
|
||||||
|
bytes = (char *)[bitmap mutableBytes];
|
||||||
|
for (i=aRange.location; i < NSMaxRange(aRange); i++)
|
||||||
|
SETBIT(bytes[i/8], i % 8);
|
||||||
|
|
||||||
|
return [self characterSetWithBitmapRepresentation:bitmap];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Other instance methods - only the first TWO must be implemented by all
|
|
||||||
subclasses. There is an abstract implementation of the inverted set.
|
|
||||||
*/
|
|
||||||
- (NSData *)bitmapRepresentation
|
- (NSData *)bitmapRepresentation
|
||||||
{
|
{
|
||||||
[self notImplemented:_cmd];
|
[self subclassResponsibility:_cmd];
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (BOOL)characterIsMember:(unichar)aCharacter
|
- (BOOL)characterIsMember:(unichar)aCharacter
|
||||||
{
|
{
|
||||||
[self notImplemented:_cmd];
|
[self subclassResponsibility:_cmd];
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSCharacterSet *)invertedSet
|
- (NSCharacterSet *)invertedSet
|
||||||
{
|
{
|
||||||
[self notImplemented:_cmd];
|
int i, length;
|
||||||
return 0;
|
char *bytes;
|
||||||
|
NSMutableData *bitmap = [[self bitmapRepresentation] mutableCopy];
|
||||||
|
|
||||||
|
length = [bitmap length];
|
||||||
|
bytes = [bitmap mutableBytes];
|
||||||
|
for (i=0; i < length; i++)
|
||||||
|
bytes[i] = ~bytes[i];
|
||||||
|
|
||||||
|
return [[self class] characterSetWithBitmapRepresentation:bitmap];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// NSCopying, NSMutableCopying
|
// NSCopying, NSMutableCopying
|
||||||
/* deepening is done by concrete subclasses */
|
|
||||||
- deepen
|
|
||||||
{
|
|
||||||
return self;
|
|
||||||
}
|
|
||||||
|
|
||||||
- (id)copyWithZone:(NSZone *)zone
|
- (id)copyWithZone:(NSZone *)zone
|
||||||
{
|
{
|
||||||
if (NSShouldRetainWithZone(self, zone))
|
if (NSShouldRetainWithZone(self, zone))
|
||||||
return [self retain];
|
return [self retain];
|
||||||
else
|
else
|
||||||
return [[super copyWithZone:zone] deepen];
|
return [super copyWithZone:zone];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (id)mutableCopyWithZone:(NSZone *)zone
|
- (id)mutableCopyWithZone:(NSZone *)zone
|
||||||
{
|
{
|
||||||
NSMutableCharacterSet *copy;
|
NSData *bitmap;
|
||||||
copy = [[NSMutableCharacterSet allocWithZone:zone] init];
|
bitmap = [self bitmapRepresentation];
|
||||||
[copy formUnionWithCharacterSet:self];
|
return [[NSMutableBitmapCharSet allocWithZone:zone] initWithBitmap:bitmap];
|
||||||
return copy;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@implementation NSMutableCharacterSet
|
@implementation NSMutableCharacterSet
|
||||||
|
|
||||||
|
/* Provide a default object for allocation */
|
||||||
|
+ allocWithZone:(NSZone *)zone
|
||||||
|
{
|
||||||
|
return NSAllocateObject([NSMutableBitmapCharSet self], 0, zone);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Override this from NSCharacterSet to create the correct class */
|
||||||
|
+ (NSCharacterSet *)characterSetWithBitmapRepresentation:(NSData *)data
|
||||||
|
{
|
||||||
|
return [[[NSMutableBitmapCharSet alloc] initWithBitmap:data] autorelease];
|
||||||
|
}
|
||||||
|
|
||||||
/* 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 notImplemented:_cmd];
|
[self subclassResponsibility:_cmd];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)addCharactersInString:(NSString *)aString
|
- (void)addCharactersInString:(NSString *)aString
|
||||||
{
|
{
|
||||||
[self notImplemented:_cmd];
|
[self subclassResponsibility:_cmd];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)formUnionWithCharacterSet:(NSCharacterSet *)otherSet
|
- (void)formUnionWithCharacterSet:(NSCharacterSet *)otherSet
|
||||||
{
|
{
|
||||||
[self notImplemented:_cmd];
|
[self subclassResponsibility:_cmd];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)formIntersectionWithCharacterSet:(NSCharacterSet *)otherSet
|
- (void)formIntersectionWithCharacterSet:(NSCharacterSet *)otherSet
|
||||||
{
|
{
|
||||||
[self notImplemented:_cmd];
|
[self subclassResponsibility:_cmd];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)removeCharactersInRange:(NSRange)aRange
|
- (void)removeCharactersInRange:(NSRange)aRange
|
||||||
{
|
{
|
||||||
[self notImplemented:_cmd];
|
[self subclassResponsibility:_cmd];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)removeCharactersInString:(NSString *)aString
|
- (void)removeCharactersInString:(NSString *)aString
|
||||||
{
|
{
|
||||||
[self notImplemented:_cmd];
|
[self subclassResponsibility:_cmd];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)invert
|
- (void)invert
|
||||||
{
|
{
|
||||||
[self notImplemented:_cmd];
|
[self subclassResponsibility:_cmd];
|
||||||
}
|
}
|
||||||
|
|
||||||
// NSCopying, NSMutableCopying
|
// NSCopying, NSMutableCopying
|
||||||
/* deepening is done by concrete subclasses */
|
|
||||||
- deepen
|
|
||||||
{
|
|
||||||
return self;
|
|
||||||
}
|
|
||||||
|
|
||||||
- (id)copyWithZone:(NSZone *)zone
|
- (id)copyWithZone:(NSZone *)zone
|
||||||
{
|
{
|
||||||
return [[super copyWithZone:zone] deepen];
|
NSData *bitmap;
|
||||||
|
bitmap = [self bitmapRepresentation];
|
||||||
|
return [[NSBitmapCharSet allocWithZone:zone] initWithBitmap:bitmap];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (id)mutableCopyWithZone:(NSZone *)zone
|
- (id)mutableCopyWithZone:(NSZone *)zone
|
||||||
{
|
{
|
||||||
return [[super copyWithZone:zone] deepen];
|
return [super mutableCopyWithZone:zone];
|
||||||
}
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue