2001-12-17 14:31:42 +00:00
|
|
|
|
/** NSCharacterSet - Character set holder
|
1998-11-10 20:16:33 +00:00
|
|
|
|
Copyright (C) 1995, 1996, 1997, 1998 Free Software Foundation, Inc.
|
1995-05-05 21:03:04 +00:00
|
|
|
|
|
|
|
|
|
Written by: Adam Fedor <fedor@boulder.colorado.edu>
|
|
|
|
|
Date: Apr 1995
|
|
|
|
|
|
1996-05-12 00:56:10 +00:00
|
|
|
|
This file is part of the GNUstep Base Library.
|
1995-05-05 21:03:04 +00:00
|
|
|
|
|
|
|
|
|
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.
|
2005-02-22 11:22:44 +00:00
|
|
|
|
|
1995-05-05 21:03:04 +00:00
|
|
|
|
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
|
2006-04-01 06:53:24 +00:00
|
|
|
|
Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
|
|
|
|
Boston, MA 02111 USA.
|
2001-12-18 16:54:15 +00:00
|
|
|
|
|
|
|
|
|
<title>NSCharacterSet class reference</title>
|
|
|
|
|
$Date$ $Revision$
|
1995-05-05 21:03:04 +00:00
|
|
|
|
*/
|
|
|
|
|
|
2003-06-07 01:24:41 +00:00
|
|
|
|
#include "config.h"
|
2004-02-08 09:42:38 +00:00
|
|
|
|
#include "GNUstepBase/GSLock.h"
|
2003-06-07 01:24:41 +00:00
|
|
|
|
#include "Foundation/NSArray.h"
|
2005-02-27 10:46:19 +00:00
|
|
|
|
#include "Foundation/NSCoder.h"
|
2003-06-07 01:24:41 +00:00
|
|
|
|
#include "Foundation/NSException.h"
|
|
|
|
|
#include "Foundation/NSData.h"
|
|
|
|
|
#include "Foundation/NSLock.h"
|
|
|
|
|
#include "Foundation/NSDictionary.h"
|
2003-09-30 17:47:35 +00:00
|
|
|
|
#include "Foundation/NSThread.h"
|
|
|
|
|
#include "Foundation/NSNotification.h"
|
2005-03-06 10:39:10 +00:00
|
|
|
|
#include "Foundation/NSCharacterSet.h"
|
2005-03-07 10:47:10 +00:00
|
|
|
|
#include <Foundation/NSData.h>
|
2005-03-06 10:39:10 +00:00
|
|
|
|
#include "Foundation/NSDebug.h"
|
1995-05-05 21:03:04 +00:00
|
|
|
|
|
2005-03-06 09:15:08 +00:00
|
|
|
|
#include "NSCharacterSetData.h"
|
1995-05-05 21:03:04 +00:00
|
|
|
|
|
2005-03-07 10:47:10 +00:00
|
|
|
|
//PENDING: may want to make these less likely to conflict
|
2006-05-12 15:13:12 +00:00
|
|
|
|
#define UNICODE_SIZE 63336
|
|
|
|
|
#define UNICODE_MAX 1114112
|
2005-03-08 11:32:24 +00:00
|
|
|
|
#define BITMAP_SIZE 8192
|
2006-05-12 15:13:12 +00:00
|
|
|
|
#define BITMAP_MAX 139264
|
2005-03-07 10:47:10 +00:00
|
|
|
|
|
|
|
|
|
#ifndef SETBIT
|
|
|
|
|
#define SETBIT(a,i) ((a) |= 1<<(i))
|
|
|
|
|
#define CLRBIT(a,i) ((a) &= ~(1<<(i)))
|
2005-03-09 06:16:32 +00:00
|
|
|
|
#define ISSET(a,i) ((a) & (1<<(i)))
|
2005-03-07 10:47:10 +00:00
|
|
|
|
#endif
|
|
|
|
|
|
2005-03-08 11:32:24 +00:00
|
|
|
|
@class NSDataStatic;
|
2005-07-08 11:48:37 +00:00
|
|
|
|
@interface NSDataStatic : NSObject // Help the compiler
|
|
|
|
|
@end
|
2005-03-08 11:32:24 +00:00
|
|
|
|
|
2005-03-07 10:47:10 +00:00
|
|
|
|
@interface NSBitmapCharSet : NSCharacterSet
|
|
|
|
|
{
|
2005-03-08 11:32:24 +00:00
|
|
|
|
const unsigned char *_data;
|
|
|
|
|
unsigned _length;
|
|
|
|
|
NSData *_obj;
|
|
|
|
|
unsigned _known;
|
|
|
|
|
unsigned _present;
|
2005-03-07 10:47:10 +00:00
|
|
|
|
}
|
|
|
|
|
- (id) initWithBitmap: (NSData*)bitmap;
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
|
|
@interface NSMutableBitmapCharSet : NSMutableCharacterSet
|
|
|
|
|
{
|
2005-03-08 11:32:24 +00:00
|
|
|
|
unsigned char *_data;
|
|
|
|
|
unsigned _length;
|
|
|
|
|
NSMutableData *_obj;
|
|
|
|
|
unsigned _known;
|
|
|
|
|
unsigned _present;
|
2005-03-07 10:47:10 +00:00
|
|
|
|
}
|
|
|
|
|
- (id) initWithBitmap: (NSData*)bitmap;
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
|
|
@implementation NSBitmapCharSet
|
|
|
|
|
|
2005-03-08 11:32:24 +00:00
|
|
|
|
- (NSData*) bitmapRepresentation
|
2005-03-07 10:47:10 +00:00
|
|
|
|
{
|
2006-05-12 15:13:12 +00:00
|
|
|
|
unsigned i = 17;
|
2005-03-08 11:32:24 +00:00
|
|
|
|
|
|
|
|
|
while (i > 0 && [self hasMemberInPlane: i-1] == NO)
|
2005-03-07 10:47:10 +00:00
|
|
|
|
{
|
2005-03-08 11:32:24 +00:00
|
|
|
|
i--;
|
2005-03-07 10:47:10 +00:00
|
|
|
|
}
|
2005-03-08 11:32:24 +00:00
|
|
|
|
i *= BITMAP_SIZE;
|
|
|
|
|
if (i < _length)
|
|
|
|
|
{
|
|
|
|
|
return [NSData dataWithBytes: _data length: i];
|
|
|
|
|
}
|
|
|
|
|
return _obj;
|
2005-03-07 10:47:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (BOOL) characterIsMember: (unichar)aCharacter
|
|
|
|
|
{
|
2005-03-08 11:32:24 +00:00
|
|
|
|
unsigned byte = aCharacter/8;
|
|
|
|
|
|
|
|
|
|
if (byte < _length && ISSET(_data[byte], aCharacter % 8))
|
|
|
|
|
{
|
|
|
|
|
return YES;
|
|
|
|
|
}
|
|
|
|
|
return NO;
|
2005-03-07 10:47:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (Class) classForCoder
|
|
|
|
|
{
|
|
|
|
|
return [self class];
|
|
|
|
|
}
|
|
|
|
|
|
2005-03-08 11:32:24 +00:00
|
|
|
|
- (void) dealloc
|
|
|
|
|
{
|
|
|
|
|
DESTROY(_obj);
|
|
|
|
|
[super dealloc];
|
|
|
|
|
}
|
|
|
|
|
|
2005-03-07 10:47:10 +00:00
|
|
|
|
- (void) encodeWithCoder: (NSCoder*)aCoder
|
|
|
|
|
{
|
|
|
|
|
[aCoder encodeObject: [self bitmapRepresentation]];
|
|
|
|
|
}
|
|
|
|
|
|
2005-03-08 11:32:24 +00:00
|
|
|
|
- (BOOL) hasMemberInPlane: (uint8_t)aPlane
|
2005-03-07 10:47:10 +00:00
|
|
|
|
{
|
2005-03-08 11:32:24 +00:00
|
|
|
|
unsigned bit;
|
2005-03-07 10:47:10 +00:00
|
|
|
|
|
2006-05-12 15:13:12 +00:00
|
|
|
|
if (aPlane > 16)
|
2005-03-08 11:32:24 +00:00
|
|
|
|
{
|
|
|
|
|
return NO;
|
|
|
|
|
}
|
|
|
|
|
bit = (1 << aPlane);
|
|
|
|
|
if (_known & bit)
|
|
|
|
|
{
|
|
|
|
|
if (_present & bit)
|
|
|
|
|
{
|
|
|
|
|
return YES;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return NO;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (aPlane * BITMAP_SIZE < _length)
|
|
|
|
|
{
|
|
|
|
|
unsigned i = BITMAP_SIZE * aPlane;
|
|
|
|
|
unsigned e = BITMAP_SIZE * (aPlane + 1);
|
2005-03-07 10:47:10 +00:00
|
|
|
|
|
2005-03-08 11:32:24 +00:00
|
|
|
|
while (i < e)
|
|
|
|
|
{
|
|
|
|
|
if (_data[i] != 0)
|
|
|
|
|
{
|
|
|
|
|
_present |= bit;
|
|
|
|
|
_known |= bit;
|
|
|
|
|
return YES;
|
|
|
|
|
}
|
|
|
|
|
i++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
_present &= ~bit;
|
|
|
|
|
_known |= bit;
|
|
|
|
|
return NO;
|
|
|
|
|
}
|
2005-03-07 10:47:10 +00:00
|
|
|
|
|
|
|
|
|
- (id) init
|
|
|
|
|
{
|
2005-03-08 11:32:24 +00:00
|
|
|
|
return [self initWithBitmap: nil];
|
2005-03-07 10:47:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (id) initWithBitmap: (NSData*)bitmap
|
|
|
|
|
{
|
2005-03-08 11:32:24 +00:00
|
|
|
|
unsigned length = [bitmap length];
|
2005-03-07 10:47:10 +00:00
|
|
|
|
|
2005-03-08 11:32:24 +00:00
|
|
|
|
if ((length % BITMAP_SIZE) != 0 || length > BITMAP_MAX)
|
|
|
|
|
{
|
|
|
|
|
NSLog(@"attempt to initialize character set with invalid bitmap");
|
|
|
|
|
[self dealloc];
|
|
|
|
|
return nil;
|
|
|
|
|
}
|
|
|
|
|
if (bitmap == nil)
|
|
|
|
|
{
|
|
|
|
|
bitmap = [NSData data];
|
|
|
|
|
}
|
|
|
|
|
ASSIGNCOPY(_obj, bitmap);
|
|
|
|
|
_length = length;
|
|
|
|
|
_data = [_obj bytes];
|
|
|
|
|
return self;
|
2005-03-07 10:47:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (id) initWithCoder: (NSCoder*)aCoder
|
|
|
|
|
{
|
2005-03-08 11:32:24 +00:00
|
|
|
|
NSData *rep;
|
2005-03-07 10:47:10 +00:00
|
|
|
|
|
|
|
|
|
rep = [aCoder decodeObject];
|
|
|
|
|
self = [self initWithBitmap: rep];
|
|
|
|
|
return self;
|
|
|
|
|
}
|
|
|
|
|
|
2005-03-08 11:32:24 +00:00
|
|
|
|
- (BOOL) longCharacterIsMember: (UTF32Char)aCharacter
|
2005-03-07 10:47:10 +00:00
|
|
|
|
{
|
2005-03-08 11:32:24 +00:00
|
|
|
|
unsigned byte = aCharacter/8;
|
|
|
|
|
|
2006-05-12 15:13:12 +00:00
|
|
|
|
if (aCharacter >= UNICODE_MAX)
|
|
|
|
|
{
|
|
|
|
|
[NSException raise: NSInvalidArgumentException
|
|
|
|
|
format: @"[%@-%@] argument (0x%08x) is too large",
|
|
|
|
|
NSStringFromClass([self class]), NSStringFromSelector(_cmd),
|
|
|
|
|
aCharacter];
|
|
|
|
|
}
|
2005-03-08 11:32:24 +00:00
|
|
|
|
if (byte < _length && ISSET(_data[byte], aCharacter % 8))
|
|
|
|
|
{
|
|
|
|
|
return YES;
|
|
|
|
|
}
|
|
|
|
|
return NO;
|
2005-03-07 10:47:10 +00:00
|
|
|
|
}
|
2005-03-08 11:32:24 +00:00
|
|
|
|
@end
|
2005-03-07 10:47:10 +00:00
|
|
|
|
|
2005-03-08 11:32:24 +00:00
|
|
|
|
@implementation NSMutableBitmapCharSet
|
|
|
|
|
|
|
|
|
|
+ (void) initialize
|
2005-03-07 10:47:10 +00:00
|
|
|
|
{
|
2005-03-08 11:32:24 +00:00
|
|
|
|
if (self == [NSMutableBitmapCharSet class])
|
|
|
|
|
{
|
|
|
|
|
[self setVersion: 1];
|
|
|
|
|
GSObjCAddClassBehavior(self, [NSBitmapCharSet class]);
|
|
|
|
|
}
|
2005-03-07 10:47:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void) addCharactersInRange: (NSRange)aRange
|
|
|
|
|
{
|
|
|
|
|
unsigned i;
|
|
|
|
|
|
2005-03-08 11:32:24 +00:00
|
|
|
|
if (NSMaxRange(aRange) > UNICODE_MAX)
|
2005-03-07 10:47:10 +00:00
|
|
|
|
{
|
|
|
|
|
[NSException raise:NSInvalidArgumentException
|
|
|
|
|
format:@"Specified range exceeds character set"];
|
|
|
|
|
/* NOT REACHED */
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (i = aRange.location; i < NSMaxRange(aRange); i++)
|
|
|
|
|
{
|
2005-03-08 11:32:24 +00:00
|
|
|
|
unsigned byte = i/8;
|
|
|
|
|
|
|
|
|
|
while (byte >= _length)
|
|
|
|
|
{
|
|
|
|
|
[_obj setLength: _length + BITMAP_SIZE];
|
|
|
|
|
_length += BITMAP_SIZE;
|
|
|
|
|
_data = [_obj mutableBytes];
|
|
|
|
|
}
|
|
|
|
|
SETBIT(_data[byte], i % 8);
|
2005-03-07 10:47:10 +00:00
|
|
|
|
}
|
2005-03-08 11:32:24 +00:00
|
|
|
|
_known = 0; // Invalidate cache
|
2005-03-07 10:47:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void) addCharactersInString: (NSString*)aString
|
|
|
|
|
{
|
|
|
|
|
unsigned length;
|
|
|
|
|
|
|
|
|
|
if (!aString)
|
|
|
|
|
{
|
|
|
|
|
[NSException raise:NSInvalidArgumentException
|
|
|
|
|
format:@"Adding characters from nil string"];
|
|
|
|
|
/* NOT REACHED */
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
length = [aString length];
|
|
|
|
|
if (length > 0)
|
|
|
|
|
{
|
|
|
|
|
unsigned i;
|
|
|
|
|
unichar (*get)(id, SEL, unsigned);
|
|
|
|
|
|
|
|
|
|
get = (unichar (*)(id, SEL, unsigned))
|
|
|
|
|
[aString methodForSelector: @selector(characterAtIndex:)];
|
|
|
|
|
for (i = 0; i < length; i++)
|
|
|
|
|
{
|
|
|
|
|
unichar letter;
|
2005-03-08 11:32:24 +00:00
|
|
|
|
unichar second;
|
|
|
|
|
unsigned byte;
|
2005-03-07 10:47:10 +00:00
|
|
|
|
|
|
|
|
|
letter = (*get)(aString, @selector(characterAtIndex:), i);
|
2005-03-08 11:32:24 +00:00
|
|
|
|
// Convert a surrogate pair if necessary
|
|
|
|
|
if (letter >= 0xd800 && letter <= 0xdbff && i < length-1
|
|
|
|
|
&& (second = (*get)(aString, @selector(characterAtIndex:), i+1))
|
|
|
|
|
>= 0xdc00 && second <= 0xdfff)
|
|
|
|
|
{
|
|
|
|
|
i++;
|
|
|
|
|
letter = ((letter - 0xd800) << 10)
|
|
|
|
|
+ (second - 0xdc00) + 0x0010000;
|
|
|
|
|
}
|
|
|
|
|
byte = letter/8;
|
|
|
|
|
while (byte >= _length)
|
|
|
|
|
{
|
|
|
|
|
[_obj setLength: _length + BITMAP_SIZE];
|
|
|
|
|
_length += BITMAP_SIZE;
|
|
|
|
|
_data = [_obj mutableBytes];
|
|
|
|
|
}
|
|
|
|
|
SETBIT(_data[byte], letter % 8);
|
2005-03-07 10:47:10 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2005-03-08 11:32:24 +00:00
|
|
|
|
_known = 0; // Invalidate cache
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (NSData*) bitmapRepresentation
|
|
|
|
|
{
|
2006-05-12 15:13:12 +00:00
|
|
|
|
unsigned i = 17;
|
2005-03-08 11:32:24 +00:00
|
|
|
|
|
|
|
|
|
while (i > 0 && [self hasMemberInPlane: i-1] == NO)
|
|
|
|
|
{
|
|
|
|
|
i--;
|
|
|
|
|
}
|
|
|
|
|
i *= BITMAP_SIZE;
|
|
|
|
|
return [NSData dataWithBytes: _data length: i];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void) formIntersectionWithCharacterSet: (NSCharacterSet *)otherSet
|
|
|
|
|
{
|
|
|
|
|
unsigned i;
|
|
|
|
|
NSData *otherData = [otherSet bitmapRepresentation];
|
|
|
|
|
unsigned other_length = [otherData length];
|
|
|
|
|
const unsigned char *other_bytes = [otherData bytes];
|
|
|
|
|
|
|
|
|
|
if (_length > other_length)
|
|
|
|
|
{
|
|
|
|
|
[_obj setLength: other_length];
|
|
|
|
|
_length = other_length;
|
|
|
|
|
_data = [_obj mutableBytes];
|
|
|
|
|
}
|
|
|
|
|
for (i = 0; i < _length; i++)
|
|
|
|
|
{
|
|
|
|
|
_data[i] = (_data[i] & other_bytes[i]);
|
|
|
|
|
}
|
|
|
|
|
_known = 0; // Invalidate cache
|
2005-03-07 10:47:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void) formUnionWithCharacterSet: (NSCharacterSet*)otherSet
|
|
|
|
|
{
|
2005-03-08 11:32:24 +00:00
|
|
|
|
unsigned i;
|
|
|
|
|
NSData *otherData = [otherSet bitmapRepresentation];
|
|
|
|
|
unsigned other_length = [otherData length];
|
|
|
|
|
const unsigned char *other_bytes = [otherData bytes];
|
2005-03-07 10:47:10 +00:00
|
|
|
|
|
2005-03-08 11:32:24 +00:00
|
|
|
|
if (other_length > _length)
|
|
|
|
|
{
|
|
|
|
|
[_obj setLength: other_length];
|
|
|
|
|
_length = other_length;
|
|
|
|
|
_data = [_obj mutableBytes];
|
|
|
|
|
}
|
2005-03-09 17:05:36 +00:00
|
|
|
|
for (i = 0; i < other_length; i++)
|
2005-03-07 10:47:10 +00:00
|
|
|
|
{
|
|
|
|
|
_data[i] = (_data[i] | other_bytes[i]);
|
|
|
|
|
}
|
2005-03-08 11:32:24 +00:00
|
|
|
|
_known = 0; // Invalidate cache
|
2005-03-07 10:47:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
2005-03-08 11:32:24 +00:00
|
|
|
|
- (id) initWithBitmap: (NSData*)bitmap
|
|
|
|
|
{
|
|
|
|
|
unsigned length = [bitmap length];
|
|
|
|
|
id tmp;
|
|
|
|
|
|
|
|
|
|
if ((length % BITMAP_SIZE) != 0 || length > BITMAP_MAX)
|
|
|
|
|
{
|
|
|
|
|
NSLog(@"attempt to initialize character set with invalid bitmap");
|
|
|
|
|
[self dealloc];
|
|
|
|
|
return nil;
|
|
|
|
|
}
|
|
|
|
|
if (bitmap == nil)
|
|
|
|
|
{
|
|
|
|
|
tmp = [NSMutableData new];
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
tmp = [bitmap mutableCopy];
|
|
|
|
|
}
|
|
|
|
|
DESTROY(_obj);
|
|
|
|
|
_obj = tmp;
|
|
|
|
|
_length = length;
|
|
|
|
|
_data = [_obj mutableBytes];
|
|
|
|
|
_known = 0; // Invalidate cache
|
|
|
|
|
return self;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void) invert
|
2005-03-07 10:47:10 +00:00
|
|
|
|
{
|
|
|
|
|
unsigned i;
|
|
|
|
|
|
2005-03-08 11:32:24 +00:00
|
|
|
|
if (_length < BITMAP_MAX)
|
2005-03-07 10:47:10 +00:00
|
|
|
|
{
|
2005-03-08 11:32:24 +00:00
|
|
|
|
[_obj setLength: BITMAP_MAX];
|
|
|
|
|
_length = BITMAP_MAX;
|
|
|
|
|
_data = [_obj mutableBytes];
|
2005-03-07 10:47:10 +00:00
|
|
|
|
}
|
2005-03-08 11:32:24 +00:00
|
|
|
|
for (i = 0; i < _length; i++)
|
|
|
|
|
{
|
|
|
|
|
_data[i] = ~_data[i];
|
|
|
|
|
}
|
|
|
|
|
_known = 0; // Invalidate cache
|
2005-03-07 10:47:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void) removeCharactersInRange: (NSRange)aRange
|
|
|
|
|
{
|
|
|
|
|
unsigned i;
|
2005-03-08 11:32:24 +00:00
|
|
|
|
unsigned limit = NSMaxRange(aRange);
|
2005-03-07 10:47:10 +00:00
|
|
|
|
|
2005-03-08 11:32:24 +00:00
|
|
|
|
if (NSMaxRange(aRange) > UNICODE_MAX)
|
2005-03-07 10:47:10 +00:00
|
|
|
|
{
|
|
|
|
|
[NSException raise:NSInvalidArgumentException
|
|
|
|
|
format:@"Specified range exceeds character set"];
|
|
|
|
|
/* NOT REACHED */
|
|
|
|
|
}
|
|
|
|
|
|
2005-03-08 11:32:24 +00:00
|
|
|
|
if (limit > _length * 8)
|
|
|
|
|
{
|
|
|
|
|
limit = _length * 8;
|
|
|
|
|
}
|
|
|
|
|
for (i = aRange.location; i < limit; i++)
|
2005-03-07 10:47:10 +00:00
|
|
|
|
{
|
|
|
|
|
CLRBIT(_data[i/8], i % 8);
|
|
|
|
|
}
|
2005-03-08 11:32:24 +00:00
|
|
|
|
_known = 0; // Invalidate cache
|
2005-03-07 10:47:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void) removeCharactersInString: (NSString*)aString
|
|
|
|
|
{
|
|
|
|
|
unsigned length;
|
|
|
|
|
|
|
|
|
|
if (!aString)
|
|
|
|
|
{
|
|
|
|
|
[NSException raise:NSInvalidArgumentException
|
|
|
|
|
format:@"Removing characters from nil string"];
|
|
|
|
|
/* NOT REACHED */
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
length = [aString length];
|
|
|
|
|
if (length > 0)
|
|
|
|
|
{
|
|
|
|
|
unsigned i;
|
|
|
|
|
unichar (*get)(id, SEL, unsigned);
|
|
|
|
|
|
|
|
|
|
get = (unichar (*)(id, SEL, unsigned))
|
|
|
|
|
[aString methodForSelector: @selector(characterAtIndex:)];
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < length; i++)
|
|
|
|
|
{
|
|
|
|
|
unichar letter;
|
2005-03-08 11:32:24 +00:00
|
|
|
|
unichar second;
|
|
|
|
|
unsigned byte;
|
2005-03-07 10:47:10 +00:00
|
|
|
|
|
|
|
|
|
letter = (*get)(aString, @selector(characterAtIndex:), i);
|
2005-03-08 11:32:24 +00:00
|
|
|
|
// Convert a surrogate pair if necessary
|
|
|
|
|
if (letter >= 0xd800 && letter <= 0xdbff && i < length-1
|
|
|
|
|
&& (second = (*get)(aString, @selector(characterAtIndex:), i+1))
|
|
|
|
|
>= 0xdc00 && second <= 0xdfff)
|
|
|
|
|
{
|
|
|
|
|
i++;
|
|
|
|
|
letter = ((letter - 0xd800) << 10)
|
|
|
|
|
+ (second - 0xdc00) + 0x0010000;
|
|
|
|
|
}
|
|
|
|
|
byte = letter/8;
|
|
|
|
|
if (byte < _length)
|
|
|
|
|
{
|
|
|
|
|
CLRBIT(_data[byte], letter % 8);
|
|
|
|
|
}
|
2005-03-07 10:47:10 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2005-03-08 11:32:24 +00:00
|
|
|
|
_known = 0; // Invalidate cache
|
2005-03-07 10:47:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
|
|
|
2005-03-06 10:39:10 +00:00
|
|
|
|
|
1996-09-02 13:53:26 +00:00
|
|
|
|
/* A simple array for caching standard bitmap sets */
|
1999-04-09 15:34:49 +00:00
|
|
|
|
#define MAX_STANDARD_SETS 15
|
2003-12-23 23:19:00 +00:00
|
|
|
|
static NSCharacterSet *cache_set[MAX_STANDARD_SETS];
|
|
|
|
|
static NSLock *cache_lock = nil;
|
|
|
|
|
static Class abstractClass = nil;
|
2005-03-08 11:32:24 +00:00
|
|
|
|
static Class abstractMutableClass = nil;
|
1996-09-02 13:53:26 +00:00
|
|
|
|
|
2005-02-27 10:46:19 +00:00
|
|
|
|
@interface GSStaticCharSet : NSCharacterSet
|
|
|
|
|
{
|
|
|
|
|
const unsigned char *_data;
|
2005-03-08 11:32:24 +00:00
|
|
|
|
unsigned _length;
|
|
|
|
|
NSData *_obj;
|
|
|
|
|
unsigned _known;
|
|
|
|
|
unsigned _present;
|
2005-02-27 10:46:19 +00:00
|
|
|
|
int _index;
|
|
|
|
|
}
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
|
|
@implementation GSStaticCharSet
|
|
|
|
|
|
2005-03-08 11:32:24 +00:00
|
|
|
|
+ (void) initialize
|
2005-02-27 10:46:19 +00:00
|
|
|
|
{
|
2005-03-08 11:32:24 +00:00
|
|
|
|
GSObjCAddClassBehavior(self, [NSBitmapCharSet class]);
|
2005-02-27 10:46:19 +00:00
|
|
|
|
}
|
|
|
|
|
|
2005-03-08 11:32:24 +00:00
|
|
|
|
- (Class) classForCoder
|
2005-02-27 10:46:19 +00:00
|
|
|
|
{
|
2005-03-08 11:32:24 +00:00
|
|
|
|
return [NSCharacterSet class];
|
2005-02-27 10:46:19 +00:00
|
|
|
|
}
|
|
|
|
|
|
2005-03-08 11:32:24 +00:00
|
|
|
|
- (void) encodeWithCoder: (NSCoder*)aCoder
|
2005-02-27 10:46:19 +00:00
|
|
|
|
{
|
2005-03-08 11:32:24 +00:00
|
|
|
|
[aCoder encodeValueOfObjCType: @encode(int) at: &_index];
|
2005-02-27 10:46:19 +00:00
|
|
|
|
}
|
|
|
|
|
|
2005-03-08 11:32:24 +00:00
|
|
|
|
- (id) init
|
2005-02-27 10:46:19 +00:00
|
|
|
|
{
|
2005-03-08 11:32:24 +00:00
|
|
|
|
DESTROY(self);
|
|
|
|
|
return nil;
|
2005-02-27 10:46:19 +00:00
|
|
|
|
}
|
|
|
|
|
|
2005-03-08 11:32:24 +00:00
|
|
|
|
- (id) initWithBitmap: (NSData*)bitmap number: (int)number
|
2005-02-27 10:46:19 +00:00
|
|
|
|
{
|
2005-03-08 11:32:24 +00:00
|
|
|
|
if ((self = [(NSBitmapCharSet*)self initWithBitmap: bitmap]) != nil)
|
|
|
|
|
{
|
|
|
|
|
_index = number;
|
|
|
|
|
}
|
|
|
|
|
return self;
|
2005-02-27 10:46:19 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
1995-05-05 21:03:04 +00:00
|
|
|
|
@implementation NSCharacterSet
|
|
|
|
|
|
1996-09-02 13:53:26 +00:00
|
|
|
|
+ (void) initialize
|
|
|
|
|
{
|
|
|
|
|
static BOOL one_time = NO;
|
|
|
|
|
|
|
|
|
|
if (one_time == NO)
|
|
|
|
|
{
|
2003-12-23 23:19:00 +00:00
|
|
|
|
abstractClass = [NSCharacterSet class];
|
2005-03-08 11:32:24 +00:00
|
|
|
|
abstractMutableClass = [NSMutableCharacterSet class];
|
1996-09-02 13:53:26 +00:00
|
|
|
|
one_time = YES;
|
|
|
|
|
}
|
2004-02-08 09:42:38 +00:00
|
|
|
|
cache_lock = [GSLazyLock new];
|
1996-09-02 13:53:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
2005-02-27 10:46:19 +00:00
|
|
|
|
/**
|
|
|
|
|
* Creat and cache (or retrieve from cache) a characterset
|
|
|
|
|
* using static bitmap data.
|
|
|
|
|
* Return nil if no data is supplied and the cache is empty.
|
|
|
|
|
*/
|
2005-03-08 11:32:24 +00:00
|
|
|
|
+ (NSCharacterSet*) _staticSet: (const unsigned char*)bytes
|
|
|
|
|
length: (unsigned)length
|
|
|
|
|
number: (int)number
|
1995-08-30 21:31:29 +00:00
|
|
|
|
{
|
1996-09-02 13:53:26 +00:00
|
|
|
|
[cache_lock lock];
|
2005-02-27 10:46:19 +00:00
|
|
|
|
if (cache_set[number] == nil && bytes != 0)
|
1997-05-03 17:16:10 +00:00
|
|
|
|
{
|
2005-03-08 11:32:24 +00:00
|
|
|
|
NSData *bitmap;
|
|
|
|
|
|
|
|
|
|
bitmap = [[NSDataStatic alloc] initWithBytesNoCopy: (void*)bytes
|
|
|
|
|
length: length
|
|
|
|
|
freeWhenDone: NO];
|
2005-02-27 10:46:19 +00:00
|
|
|
|
cache_set[number]
|
2005-03-08 11:32:24 +00:00
|
|
|
|
= [[GSStaticCharSet alloc] initWithBitmap: bitmap number: number];
|
|
|
|
|
RELEASE(bitmap);
|
1995-08-30 21:31:29 +00:00
|
|
|
|
}
|
1996-09-02 13:53:26 +00:00
|
|
|
|
[cache_lock unlock];
|
2005-02-27 10:46:19 +00:00
|
|
|
|
return cache_set[number];
|
1995-08-30 21:31:29 +00:00
|
|
|
|
}
|
|
|
|
|
|
2001-11-07 16:24:55 +00:00
|
|
|
|
+ (NSCharacterSet*) alphanumericCharacterSet
|
1995-05-05 21:03:04 +00:00
|
|
|
|
{
|
2005-03-08 11:32:24 +00:00
|
|
|
|
return [self _staticSet: alphanumericCharSet
|
|
|
|
|
length: sizeof(alphanumericCharSet)
|
|
|
|
|
number: 0];
|
1995-05-05 21:03:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
2005-03-06 09:15:08 +00:00
|
|
|
|
+ (NSCharacterSet*) capitalizedLetterCharacterSet
|
|
|
|
|
{
|
2005-03-08 11:32:24 +00:00
|
|
|
|
return [self _staticSet: titlecaseLetterCharSet
|
|
|
|
|
length: sizeof(titlecaseLetterCharSet)
|
|
|
|
|
number: 13];
|
2005-03-06 09:15:08 +00:00
|
|
|
|
}
|
|
|
|
|
|
2001-11-07 16:24:55 +00:00
|
|
|
|
+ (NSCharacterSet*) controlCharacterSet
|
1995-05-05 21:03:04 +00:00
|
|
|
|
{
|
2005-03-08 11:32:24 +00:00
|
|
|
|
return [self _staticSet: controlCharSet
|
|
|
|
|
length: sizeof(controlCharSet)
|
|
|
|
|
number: 1];
|
1995-05-05 21:03:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
2001-11-07 16:24:55 +00:00
|
|
|
|
+ (NSCharacterSet*) decimalDigitCharacterSet
|
1995-05-05 21:03:04 +00:00
|
|
|
|
{
|
2005-03-08 11:32:24 +00:00
|
|
|
|
return [self _staticSet: decimalDigitCharSet
|
|
|
|
|
length: sizeof(decimalDigitCharSet)
|
|
|
|
|
number: 2];
|
1995-05-05 21:03:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
2001-11-07 16:24:55 +00:00
|
|
|
|
+ (NSCharacterSet*) decomposableCharacterSet
|
1995-05-05 21:03:04 +00:00
|
|
|
|
{
|
2005-03-08 11:32:24 +00:00
|
|
|
|
return [self _staticSet: decomposableCharSet
|
|
|
|
|
length: sizeof(decomposableCharSet)
|
|
|
|
|
number: 3];
|
1995-05-05 21:03:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
2001-11-07 16:24:55 +00:00
|
|
|
|
+ (NSCharacterSet*) illegalCharacterSet
|
1995-05-05 21:03:04 +00:00
|
|
|
|
{
|
2005-03-08 11:32:24 +00:00
|
|
|
|
return [self _staticSet: illegalCharSet
|
|
|
|
|
length: sizeof(illegalCharSet)
|
|
|
|
|
number: 4];
|
1995-05-05 21:03:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
2001-11-07 16:24:55 +00:00
|
|
|
|
+ (NSCharacterSet*) letterCharacterSet
|
1995-05-05 21:03:04 +00:00
|
|
|
|
{
|
2005-03-08 11:32:24 +00:00
|
|
|
|
return [self _staticSet: letterCharSet
|
|
|
|
|
length: sizeof(letterCharSet)
|
|
|
|
|
number: 5];
|
1995-05-05 21:03:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
2001-11-07 16:24:55 +00:00
|
|
|
|
+ (NSCharacterSet*) lowercaseLetterCharacterSet
|
1995-05-05 21:03:04 +00:00
|
|
|
|
{
|
2005-03-08 11:32:24 +00:00
|
|
|
|
return [self _staticSet: lowercaseLetterCharSet
|
|
|
|
|
length: sizeof(lowercaseLetterCharSet)
|
|
|
|
|
number: 6];
|
1995-05-05 21:03:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
2001-11-07 16:24:55 +00:00
|
|
|
|
+ (NSCharacterSet*) nonBaseCharacterSet
|
1995-05-05 21:03:04 +00:00
|
|
|
|
{
|
2005-03-08 11:32:24 +00:00
|
|
|
|
return [self _staticSet: nonBaseCharSet
|
|
|
|
|
length: sizeof(nonBaseCharSet)
|
|
|
|
|
number: 7];
|
1995-05-05 21:03:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
2001-12-17 14:31:42 +00:00
|
|
|
|
+ (NSCharacterSet*) punctuationCharacterSet
|
1998-11-16 19:36:51 +00:00
|
|
|
|
{
|
2005-03-08 11:32:24 +00:00
|
|
|
|
return [self _staticSet: punctuationCharSet
|
|
|
|
|
length: sizeof(punctuationCharSet)
|
|
|
|
|
number: 8];
|
1998-11-16 19:36:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
2005-03-06 10:39:10 +00:00
|
|
|
|
+ (NSCharacterSet*) symbolCharacterSet
|
|
|
|
|
{
|
2005-03-08 11:32:24 +00:00
|
|
|
|
return [self _staticSet: symbolAndOperatorCharSet
|
|
|
|
|
length: sizeof(symbolAndOperatorCharSet)
|
|
|
|
|
number: 9];
|
2005-03-06 10:39:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// FIXME ... deprecated ... remove after next release.
|
2001-12-17 14:31:42 +00:00
|
|
|
|
+ (NSCharacterSet*) symbolAndOperatorCharacterSet
|
1999-04-09 15:34:49 +00:00
|
|
|
|
{
|
2005-03-06 10:39:10 +00:00
|
|
|
|
GSOnceMLog(@"symbolAndOperatorCharacterSet is deprecated ... use symbolCharacterSet");
|
2005-03-08 11:32:24 +00:00
|
|
|
|
return [self _staticSet: symbolAndOperatorCharSet
|
|
|
|
|
length: sizeof(symbolAndOperatorCharSet)
|
|
|
|
|
number: 9];
|
1999-04-09 15:34:49 +00:00
|
|
|
|
}
|
|
|
|
|
|
2001-11-07 16:24:55 +00:00
|
|
|
|
+ (NSCharacterSet*) uppercaseLetterCharacterSet
|
1995-05-05 21:03:04 +00:00
|
|
|
|
{
|
2005-03-08 11:32:24 +00:00
|
|
|
|
return [self _staticSet: uppercaseLetterCharSet
|
|
|
|
|
length: sizeof(uppercaseLetterCharSet)
|
|
|
|
|
number: 10];
|
1995-05-05 21:03:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
2001-11-07 16:24:55 +00:00
|
|
|
|
+ (NSCharacterSet*) whitespaceAndNewlineCharacterSet
|
1995-05-05 21:03:04 +00:00
|
|
|
|
{
|
2005-03-08 11:32:24 +00:00
|
|
|
|
return [self _staticSet: whitespaceAndNlCharSet
|
|
|
|
|
length: sizeof(whitespaceAndNlCharSet)
|
|
|
|
|
number: 11];
|
1995-05-05 21:03:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
2001-11-07 16:24:55 +00:00
|
|
|
|
+ (NSCharacterSet*) whitespaceCharacterSet
|
1995-05-05 21:03:04 +00:00
|
|
|
|
{
|
2005-03-08 11:32:24 +00:00
|
|
|
|
return [self _staticSet: whitespaceCharSet
|
|
|
|
|
length: sizeof(whitespaceCharSet)
|
|
|
|
|
number: 12];
|
1995-05-05 21:03:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
2001-11-07 16:24:55 +00:00
|
|
|
|
+ (NSCharacterSet*) characterSetWithBitmapRepresentation: (NSData*)data
|
1995-05-05 21:03:04 +00:00
|
|
|
|
{
|
1999-06-03 10:59:25 +00:00
|
|
|
|
return AUTORELEASE([[NSBitmapCharSet alloc] initWithBitmap: data]);
|
1995-05-05 21:03:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
2001-11-07 16:24:55 +00:00
|
|
|
|
+ (NSCharacterSet*) characterSetWithCharactersInString: (NSString*)aString
|
1995-05-05 21:03:04 +00:00
|
|
|
|
{
|
2005-03-08 11:32:24 +00:00
|
|
|
|
NSMutableCharacterSet *ms;
|
|
|
|
|
NSCharacterSet *cs;
|
2001-11-07 16:24:55 +00:00
|
|
|
|
|
2005-03-08 11:32:24 +00:00
|
|
|
|
ms = [NSMutableCharacterSet new];
|
|
|
|
|
[ms addCharactersInString: aString];
|
|
|
|
|
cs = [ms copy];
|
|
|
|
|
RELEASE(ms);
|
|
|
|
|
return AUTORELEASE(cs);
|
1995-05-05 21:03:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
2005-03-07 10:47:10 +00:00
|
|
|
|
+ (NSCharacterSet*) characterSetWithRange: (NSRange)aRange
|
1995-05-05 21:03:04 +00:00
|
|
|
|
{
|
2005-03-08 11:32:24 +00:00
|
|
|
|
NSMutableCharacterSet *ms;
|
|
|
|
|
NSCharacterSet *cs;
|
1995-08-30 21:31:29 +00:00
|
|
|
|
|
2005-03-08 11:32:24 +00:00
|
|
|
|
ms = [NSMutableCharacterSet new];
|
|
|
|
|
[ms addCharactersInRange: aRange];
|
|
|
|
|
cs = [ms copy];
|
|
|
|
|
RELEASE(ms);
|
|
|
|
|
return AUTORELEASE(cs);
|
1995-05-05 21:03:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
2001-11-07 16:24:55 +00:00
|
|
|
|
+ (NSCharacterSet*) characterSetWithContentsOfFile: (NSString*)aFile
|
1998-11-10 20:16:33 +00:00
|
|
|
|
{
|
|
|
|
|
if ([@"bitmap" isEqual: [aFile pathExtension]])
|
|
|
|
|
{
|
|
|
|
|
NSData *bitmap = [NSData dataWithContentsOfFile: aFile];
|
|
|
|
|
return [self characterSetWithBitmapRepresentation: bitmap];
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
return nil;
|
|
|
|
|
}
|
|
|
|
|
|
2001-11-07 16:24:55 +00:00
|
|
|
|
- (NSData*) bitmapRepresentation
|
1995-05-05 21:03:04 +00:00
|
|
|
|
{
|
2005-03-07 10:47:10 +00:00
|
|
|
|
BOOL (*imp)(id, SEL, unichar);
|
|
|
|
|
NSMutableData *m = [NSMutableData dataWithLength: 8192];
|
|
|
|
|
unsigned char *p = (unsigned char*)[m mutableBytes];
|
|
|
|
|
unsigned i;
|
|
|
|
|
|
|
|
|
|
imp = (BOOL (*)(id,SEL,unichar))
|
|
|
|
|
[self methodForSelector: @selector(characterIsMember:)];
|
|
|
|
|
for (i = 0; i <= 0xffff; i++)
|
|
|
|
|
{
|
|
|
|
|
if (imp(self, @selector(characterIsMember:), i) == YES)
|
|
|
|
|
{
|
|
|
|
|
SETBIT(p[i/8], i % 8);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return m;
|
1995-05-05 21:03:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
2001-11-07 16:24:55 +00:00
|
|
|
|
- (BOOL) characterIsMember: (unichar)aCharacter
|
1995-05-05 21:03:04 +00:00
|
|
|
|
{
|
1999-04-07 11:57:53 +00:00
|
|
|
|
[self subclassResponsibility: _cmd];
|
1995-05-05 21:03:04 +00:00
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2005-03-07 10:47:10 +00:00
|
|
|
|
- (id) copyWithZone: (NSZone*)zone
|
|
|
|
|
{
|
|
|
|
|
if (NSShouldRetainWithZone(self, zone))
|
2005-03-08 11:32:24 +00:00
|
|
|
|
{
|
|
|
|
|
return RETAIN(self);
|
|
|
|
|
}
|
2005-03-07 10:47:10 +00:00
|
|
|
|
else
|
2005-03-08 11:32:24 +00:00
|
|
|
|
{
|
|
|
|
|
id obj;
|
|
|
|
|
|
|
|
|
|
obj = [NSBitmapCharSet allocWithZone: zone];
|
|
|
|
|
obj = [obj initWithBitmap: [self bitmapRepresentation]];
|
|
|
|
|
return obj;
|
|
|
|
|
}
|
2005-03-07 10:47:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
1998-07-29 09:22:18 +00:00
|
|
|
|
- (void) encodeWithCoder: (NSCoder*)aCoder
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2005-03-07 10:47:10 +00:00
|
|
|
|
- (BOOL) hasMemberInPlane: (uint8_t)aPlane
|
|
|
|
|
{
|
|
|
|
|
if (aPlane == 0)
|
|
|
|
|
{
|
|
|
|
|
return YES;
|
|
|
|
|
}
|
|
|
|
|
return NO;
|
|
|
|
|
}
|
|
|
|
|
|
2005-03-08 11:32:24 +00:00
|
|
|
|
- (id) init
|
|
|
|
|
{
|
|
|
|
|
if (GSObjCClass(self) == abstractClass)
|
|
|
|
|
{
|
|
|
|
|
id obj;
|
|
|
|
|
|
|
|
|
|
obj = [NSBitmapCharSet allocWithZone: [self zone]];
|
|
|
|
|
obj = [obj initWithBitmap: nil];
|
|
|
|
|
RELEASE(self);
|
|
|
|
|
self = obj;
|
|
|
|
|
}
|
|
|
|
|
return self;
|
|
|
|
|
}
|
|
|
|
|
|
1998-07-29 09:22:18 +00:00
|
|
|
|
- (id) initWithCoder: (NSCoder*)aCoder
|
|
|
|
|
{
|
2005-02-28 17:18:54 +00:00
|
|
|
|
if ([self class] == abstractClass)
|
2005-02-27 10:46:19 +00:00
|
|
|
|
{
|
|
|
|
|
int index;
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Abstract class returns characterset from cache.
|
|
|
|
|
*/
|
|
|
|
|
DESTROY(self);
|
|
|
|
|
[aCoder decodeValueOfObjCType: @encode(int) at: &index];
|
2005-03-08 11:32:24 +00:00
|
|
|
|
self = RETAIN([abstractClass _staticSet: 0 length: 0 number: index]);
|
2005-02-28 17:18:54 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2005-02-27 10:46:19 +00:00
|
|
|
|
}
|
|
|
|
|
return self;
|
1998-07-29 09:22:18 +00:00
|
|
|
|
}
|
|
|
|
|
|
2005-03-07 10:47:10 +00:00
|
|
|
|
- (NSCharacterSet*) invertedSet
|
|
|
|
|
{
|
|
|
|
|
unsigned i;
|
|
|
|
|
unsigned length;
|
|
|
|
|
unsigned char *bytes;
|
|
|
|
|
NSMutableData *bitmap;
|
|
|
|
|
|
|
|
|
|
bitmap = AUTORELEASE([[self bitmapRepresentation] mutableCopy]);
|
|
|
|
|
length = [bitmap length];
|
|
|
|
|
bytes = [bitmap mutableBytes];
|
|
|
|
|
for (i = 0; i < length; i++)
|
|
|
|
|
{
|
|
|
|
|
bytes[i] = ~bytes[i];
|
|
|
|
|
}
|
|
|
|
|
return [[self class] characterSetWithBitmapRepresentation: bitmap];
|
|
|
|
|
}
|
|
|
|
|
|
1998-07-29 14:46:16 +00:00
|
|
|
|
- (BOOL) isEqual: (id)anObject
|
|
|
|
|
{
|
|
|
|
|
if (anObject == self)
|
|
|
|
|
return YES;
|
2005-02-28 17:18:54 +00:00
|
|
|
|
if ([anObject isKindOfClass: abstractClass])
|
1998-07-29 14:46:16 +00:00
|
|
|
|
{
|
2001-11-07 16:24:55 +00:00
|
|
|
|
unsigned i;
|
2005-03-08 11:32:24 +00:00
|
|
|
|
unsigned p;
|
2005-03-07 10:47:10 +00:00
|
|
|
|
BOOL (*rImp)(id, SEL, unichar);
|
|
|
|
|
BOOL (*oImp)(id, SEL, unichar);
|
|
|
|
|
|
|
|
|
|
rImp = (BOOL (*)(id,SEL,unichar))
|
|
|
|
|
[self methodForSelector: @selector(characterIsMember:)];
|
|
|
|
|
oImp = (BOOL (*)(id,SEL,unichar))
|
|
|
|
|
[anObject methodForSelector: @selector(characterIsMember:)];
|
1998-07-29 14:46:16 +00:00
|
|
|
|
|
2006-05-12 15:13:12 +00:00
|
|
|
|
for (p = 0; p <= 16; p++)
|
2001-11-07 16:24:55 +00:00
|
|
|
|
{
|
2005-03-08 11:32:24 +00:00
|
|
|
|
if ([self hasMemberInPlane: p] == YES)
|
2001-11-07 16:24:55 +00:00
|
|
|
|
{
|
2005-03-08 11:32:24 +00:00
|
|
|
|
if ([anObject hasMemberInPlane: p] == YES)
|
|
|
|
|
{
|
|
|
|
|
for (i = 0; i <= 0xffff; i++)
|
|
|
|
|
{
|
|
|
|
|
if (rImp(self, @selector(characterIsMember:), i)
|
|
|
|
|
!= oImp(anObject, @selector(characterIsMember:), i))
|
|
|
|
|
{
|
|
|
|
|
return NO;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return NO;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if ([anObject hasMemberInPlane: p] == YES)
|
|
|
|
|
{
|
|
|
|
|
return NO;
|
|
|
|
|
}
|
2001-11-07 16:24:55 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
1998-07-29 14:46:16 +00:00
|
|
|
|
return YES;
|
|
|
|
|
}
|
|
|
|
|
return NO;
|
|
|
|
|
}
|
|
|
|
|
|
2005-03-07 10:47:10 +00:00
|
|
|
|
- (BOOL) isSupersetOfSet: (NSCharacterSet*)aSet
|
1995-05-05 21:03:04 +00:00
|
|
|
|
{
|
2005-03-07 10:47:10 +00:00
|
|
|
|
NSMutableCharacterSet *m = [self mutableCopy];
|
|
|
|
|
BOOL superset;
|
1995-05-05 21:03:04 +00:00
|
|
|
|
|
2005-03-07 10:47:10 +00:00
|
|
|
|
[m formUnionWithCharacterSet: aSet];
|
|
|
|
|
superset = [self isEqual: m];
|
|
|
|
|
RELEASE(m);
|
|
|
|
|
return superset;
|
1995-05-05 21:03:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
2005-03-07 10:47:10 +00:00
|
|
|
|
- (BOOL) longCharacterIsMember: (UTF32Char)aCharacter
|
1995-05-05 21:03:04 +00:00
|
|
|
|
{
|
2005-03-07 10:47:10 +00:00
|
|
|
|
int plane = (aCharacter >> 16);
|
|
|
|
|
|
2006-05-12 15:13:12 +00:00
|
|
|
|
if (aCharacter >= UNICODE_MAX)
|
|
|
|
|
{
|
|
|
|
|
[NSException raise: NSInvalidArgumentException
|
|
|
|
|
format: @"[%@-%@] argument (0x%08x) is too large",
|
|
|
|
|
NSStringFromClass([self class]), NSStringFromSelector(_cmd),
|
|
|
|
|
aCharacter];
|
|
|
|
|
}
|
2005-03-07 10:47:10 +00:00
|
|
|
|
if (plane == 0)
|
|
|
|
|
{
|
|
|
|
|
unichar u = (unichar)(aCharacter & 0xffff);
|
|
|
|
|
|
|
|
|
|
return [self characterIsMember: u];
|
|
|
|
|
}
|
1995-05-05 21:03:04 +00:00
|
|
|
|
else
|
2005-03-07 10:47:10 +00:00
|
|
|
|
{
|
|
|
|
|
return NO;
|
|
|
|
|
}
|
1995-05-05 21:03:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
2001-11-07 16:24:55 +00:00
|
|
|
|
- (id) mutableCopyWithZone: (NSZone*)zone
|
1995-05-05 21:03:04 +00:00
|
|
|
|
{
|
1995-08-30 21:31:29 +00:00
|
|
|
|
NSData *bitmap;
|
|
|
|
|
bitmap = [self bitmapRepresentation];
|
1999-04-07 11:57:53 +00:00
|
|
|
|
return [[NSMutableBitmapCharSet allocWithZone: zone] initWithBitmap: bitmap];
|
1995-05-05 21:03:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
|
|
@implementation NSMutableCharacterSet
|
|
|
|
|
|
1995-08-30 21:31:29 +00:00
|
|
|
|
/* Override this from NSCharacterSet to create the correct class */
|
2001-11-07 16:24:55 +00:00
|
|
|
|
+ (NSCharacterSet*) characterSetWithBitmapRepresentation: (NSData*)data
|
1995-08-30 21:31:29 +00:00
|
|
|
|
{
|
1999-06-03 10:59:25 +00:00
|
|
|
|
return AUTORELEASE([[NSMutableBitmapCharSet alloc] initWithBitmap: data]);
|
1995-08-30 21:31:29 +00:00
|
|
|
|
}
|
|
|
|
|
|
2005-02-28 17:18:54 +00:00
|
|
|
|
+ (NSCharacterSet*) alphanumericCharacterSet
|
|
|
|
|
{
|
|
|
|
|
return AUTORELEASE([[abstractClass performSelector: _cmd] mutableCopy]);
|
|
|
|
|
}
|
|
|
|
|
|
2005-03-06 09:15:08 +00:00
|
|
|
|
+ (NSCharacterSet*) capitalizedLetterCharacterSet
|
|
|
|
|
{
|
|
|
|
|
return AUTORELEASE([[abstractClass performSelector: _cmd] mutableCopy]);
|
|
|
|
|
}
|
|
|
|
|
|
2005-02-28 17:18:54 +00:00
|
|
|
|
+ (NSCharacterSet*) controlCharacterSet
|
|
|
|
|
{
|
|
|
|
|
return AUTORELEASE([[abstractClass performSelector: _cmd] mutableCopy]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
+ (NSCharacterSet*) decimalDigitCharacterSet
|
|
|
|
|
{
|
|
|
|
|
return AUTORELEASE([[abstractClass performSelector: _cmd] mutableCopy]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
+ (NSCharacterSet*) decomposableCharacterSet
|
|
|
|
|
{
|
|
|
|
|
return AUTORELEASE([[abstractClass performSelector: _cmd] mutableCopy]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
+ (NSCharacterSet*) illegalCharacterSet
|
|
|
|
|
{
|
|
|
|
|
return AUTORELEASE([[abstractClass performSelector: _cmd] mutableCopy]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
+ (NSCharacterSet*) letterCharacterSet
|
|
|
|
|
{
|
|
|
|
|
return AUTORELEASE([[abstractClass performSelector: _cmd] mutableCopy]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
+ (NSCharacterSet*) lowercaseLetterCharacterSet
|
|
|
|
|
{
|
|
|
|
|
return AUTORELEASE([[abstractClass performSelector: _cmd] mutableCopy]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
+ (NSCharacterSet*) nonBaseCharacterSet
|
|
|
|
|
{
|
|
|
|
|
return AUTORELEASE([[abstractClass performSelector: _cmd] mutableCopy]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
+ (NSCharacterSet*) punctuationCharacterSet
|
|
|
|
|
{
|
|
|
|
|
return AUTORELEASE([[abstractClass performSelector: _cmd] mutableCopy]);
|
|
|
|
|
}
|
|
|
|
|
|
2005-03-06 10:39:10 +00:00
|
|
|
|
+ (NSCharacterSet*) symbolCharacterSet
|
|
|
|
|
{
|
|
|
|
|
return AUTORELEASE([[abstractClass performSelector: _cmd] mutableCopy]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// FIXME ... deprecated ... remove after next release.
|
2005-02-28 17:18:54 +00:00
|
|
|
|
+ (NSCharacterSet*) symbolAndOperatorCharacterSet
|
|
|
|
|
{
|
|
|
|
|
return AUTORELEASE([[abstractClass performSelector: _cmd] mutableCopy]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
+ (NSCharacterSet*) uppercaseLetterCharacterSet
|
|
|
|
|
{
|
|
|
|
|
return AUTORELEASE([[abstractClass performSelector: _cmd] mutableCopy]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
+ (NSCharacterSet*) whitespaceAndNewlineCharacterSet
|
|
|
|
|
{
|
|
|
|
|
return AUTORELEASE([[abstractClass performSelector: _cmd] mutableCopy]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
+ (NSCharacterSet*) whitespaceCharacterSet
|
|
|
|
|
{
|
|
|
|
|
return AUTORELEASE([[abstractClass performSelector: _cmd] mutableCopy]);
|
|
|
|
|
}
|
|
|
|
|
|
2005-03-08 11:32:24 +00:00
|
|
|
|
+ (NSCharacterSet*) characterSetWithCharactersInString: (NSString*)aString
|
|
|
|
|
{
|
|
|
|
|
NSMutableCharacterSet *ms;
|
|
|
|
|
|
|
|
|
|
ms = [abstractMutableClass new];
|
|
|
|
|
[ms addCharactersInString: aString];
|
|
|
|
|
return AUTORELEASE(ms);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
+ (NSCharacterSet*) characterSetWithRange: (NSRange)aRange
|
|
|
|
|
{
|
|
|
|
|
NSMutableCharacterSet *ms;
|
|
|
|
|
|
|
|
|
|
ms = [abstractMutableClass new];
|
|
|
|
|
[ms addCharactersInRange: aRange];
|
|
|
|
|
return AUTORELEASE(ms);
|
|
|
|
|
}
|
|
|
|
|
|
2001-11-07 16:24:55 +00:00
|
|
|
|
- (void) addCharactersInRange: (NSRange)aRange
|
1995-05-05 21:03:04 +00:00
|
|
|
|
{
|
1999-04-07 11:57:53 +00:00
|
|
|
|
[self subclassResponsibility: _cmd];
|
1995-05-05 21:03:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
2001-11-07 16:24:55 +00:00
|
|
|
|
- (void) addCharactersInString: (NSString*)aString
|
1995-05-05 21:03:04 +00:00
|
|
|
|
{
|
1999-04-07 11:57:53 +00:00
|
|
|
|
[self subclassResponsibility: _cmd];
|
1995-05-05 21:03:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
2005-03-08 11:32:24 +00:00
|
|
|
|
- (id) copyWithZone: (NSZone*)zone
|
1995-05-05 21:03:04 +00:00
|
|
|
|
{
|
2005-03-08 11:32:24 +00:00
|
|
|
|
NSData *bitmap;
|
|
|
|
|
|
|
|
|
|
bitmap = [self bitmapRepresentation];
|
|
|
|
|
return [[NSBitmapCharSet allocWithZone: zone] initWithBitmap: bitmap];
|
1995-05-05 21:03:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
2001-11-07 16:24:55 +00:00
|
|
|
|
- (void) formIntersectionWithCharacterSet: (NSCharacterSet*)otherSet
|
1995-05-05 21:03:04 +00:00
|
|
|
|
{
|
1999-04-07 11:57:53 +00:00
|
|
|
|
[self subclassResponsibility: _cmd];
|
1995-05-05 21:03:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
2005-03-08 11:32:24 +00:00
|
|
|
|
- (void) formUnionWithCharacterSet: (NSCharacterSet*)otherSet
|
1995-05-05 21:03:04 +00:00
|
|
|
|
{
|
1999-04-07 11:57:53 +00:00
|
|
|
|
[self subclassResponsibility: _cmd];
|
1995-05-05 21:03:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
2005-03-08 11:32:24 +00:00
|
|
|
|
- (id) init
|
1995-05-05 21:03:04 +00:00
|
|
|
|
{
|
2005-03-08 11:32:24 +00:00
|
|
|
|
if (GSObjCClass(self) == abstractMutableClass)
|
|
|
|
|
{
|
|
|
|
|
id obj;
|
|
|
|
|
|
|
|
|
|
obj = [NSMutableBitmapCharSet allocWithZone: [self zone]];
|
|
|
|
|
obj = [obj initWithBitmap: nil];
|
|
|
|
|
RELEASE(self);
|
|
|
|
|
self = obj;
|
|
|
|
|
}
|
|
|
|
|
return self;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (id) initWithBitmap: (NSData*)bitmap
|
|
|
|
|
{
|
|
|
|
|
if (GSObjCClass(self) == abstractMutableClass)
|
|
|
|
|
{
|
|
|
|
|
id obj;
|
|
|
|
|
|
|
|
|
|
obj = [NSMutableBitmapCharSet allocWithZone: [self zone]];
|
|
|
|
|
obj = [obj initWithBitmap: bitmap];
|
|
|
|
|
RELEASE(self);
|
|
|
|
|
self = obj;
|
|
|
|
|
}
|
|
|
|
|
return self;
|
1995-05-05 21:03:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
2001-11-07 16:24:55 +00:00
|
|
|
|
- (void) invert
|
1995-05-05 21:03:04 +00:00
|
|
|
|
{
|
1999-04-07 11:57:53 +00:00
|
|
|
|
[self subclassResponsibility: _cmd];
|
1995-05-05 21:03:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
2005-03-08 11:32:24 +00:00
|
|
|
|
- (void) removeCharactersInRange: (NSRange)aRange
|
1995-05-05 21:03:04 +00:00
|
|
|
|
{
|
2005-03-08 11:32:24 +00:00
|
|
|
|
[self subclassResponsibility: _cmd];
|
1995-05-05 21:03:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
2005-03-08 11:32:24 +00:00
|
|
|
|
- (void) removeCharactersInString: (NSString*)aString
|
1995-05-05 21:03:04 +00:00
|
|
|
|
{
|
2005-03-08 11:32:24 +00:00
|
|
|
|
[self subclassResponsibility: _cmd];
|
1995-05-05 21:03:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@end
|