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
|
1999-09-09 02:56:20 +00:00
|
|
|
Software Foundation, Inc., 59 Temple Place, Suite 330, 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"
|
|
|
|
#include "Foundation/NSBitmapCharSet.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"
|
1995-05-05 21:03:04 +00:00
|
|
|
|
2005-02-27 10:46:19 +00:00
|
|
|
#include "../NSCharacterSets/NSCharacterSetData.h"
|
1995-05-05 21:03:04 +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;
|
1996-09-02 13:53:26 +00:00
|
|
|
|
2005-02-27 10:46:19 +00:00
|
|
|
@interface GSStaticCharSet : NSCharacterSet
|
|
|
|
{
|
|
|
|
const unsigned char *_data;
|
|
|
|
int _index;
|
|
|
|
}
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation GSStaticCharSet
|
|
|
|
|
|
|
|
- (id) init
|
|
|
|
{
|
|
|
|
DESTROY(self);
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (id) initWithIndex: (int)index bytes: (const unsigned char*)bitmap
|
|
|
|
{
|
|
|
|
_index = index;
|
|
|
|
_data = bitmap;
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSData*) bitmapRepresentation
|
|
|
|
{
|
|
|
|
return [NSData dataWithBytes: _data length: BITMAP_SIZE];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL) characterIsMember: (unichar)aCharacter
|
|
|
|
{
|
|
|
|
return ISSET(_data[aCharacter/8], aCharacter % 8);
|
|
|
|
}
|
|
|
|
|
|
|
|
- (Class) classForCoder
|
|
|
|
{
|
|
|
|
return [NSCharacterSet class];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) encodeWithCoder: (NSCoder*)aCoder
|
|
|
|
{
|
|
|
|
[aCoder encodeValueOfObjCType: @encode(int) at: &_index];
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
2004-06-22 22:40:40 +00:00
|
|
|
/**
|
|
|
|
* Represents a set of unicode characters. Used by [NSScanner] and [NSString]
|
|
|
|
* for parsing-related methods.
|
|
|
|
*/
|
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];
|
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
|
|
|
}
|
|
|
|
|
1995-08-30 21:31:29 +00:00
|
|
|
/* Provide a default object for allocation */
|
2001-11-07 16:24:55 +00:00
|
|
|
+ (id) allocWithZone: (NSZone*)zone
|
1995-08-30 21:31:29 +00:00
|
|
|
{
|
2003-12-23 23:19:00 +00:00
|
|
|
if (self == abstractClass)
|
|
|
|
return NSAllocateObject([NSBitmapCharSet self], 0, zone);
|
|
|
|
else
|
|
|
|
return NSAllocateObject(self, 0, zone);
|
1995-08-30 21:31:29 +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.
|
|
|
|
*/
|
|
|
|
+ (NSCharacterSet*) _staticSet: (unsigned char*)bytes 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-02-27 10:46:19 +00:00
|
|
|
cache_set[number]
|
|
|
|
= [[GSStaticCharSet alloc] initWithIndex: number bytes: bytes];
|
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
|
|
|
}
|
|
|
|
|
2004-06-22 22:40:40 +00:00
|
|
|
/**
|
|
|
|
* Returns a character set containing letters, numbers, and diacritical
|
|
|
|
* marks. Note that "letters" includes all alphabetic as well as Chinese
|
|
|
|
* characters, etc..
|
|
|
|
*/
|
2001-11-07 16:24:55 +00:00
|
|
|
+ (NSCharacterSet*) alphanumericCharacterSet
|
1995-05-05 21:03:04 +00:00
|
|
|
{
|
2005-02-27 10:46:19 +00:00
|
|
|
return [self _staticSet: alphanumericCharSet number: 0];
|
1995-05-05 21:03:04 +00:00
|
|
|
}
|
|
|
|
|
2004-06-22 22:40:40 +00:00
|
|
|
/**
|
|
|
|
* Returns a character set containing control and format characters.
|
|
|
|
*/
|
2001-11-07 16:24:55 +00:00
|
|
|
+ (NSCharacterSet*) controlCharacterSet
|
1995-05-05 21:03:04 +00:00
|
|
|
{
|
2005-02-27 10:46:19 +00:00
|
|
|
return [self _staticSet: controlCharSet number: 1];
|
1995-05-05 21:03:04 +00:00
|
|
|
}
|
|
|
|
|
2002-08-20 10:22:05 +00:00
|
|
|
/**
|
|
|
|
* Returns a character set containing characters that represent
|
|
|
|
* the decimal digits 0 through 9.
|
|
|
|
*/
|
2001-11-07 16:24:55 +00:00
|
|
|
+ (NSCharacterSet*) decimalDigitCharacterSet
|
1995-05-05 21:03:04 +00:00
|
|
|
{
|
2005-02-27 10:46:19 +00:00
|
|
|
return [self _staticSet: decimalDigitCharSet number: 2];
|
1995-05-05 21:03:04 +00:00
|
|
|
}
|
|
|
|
|
2002-08-20 10:22:05 +00:00
|
|
|
/**
|
|
|
|
* Returns a character set containing individual charactars that
|
|
|
|
* can be represented also by a composed character sequence.
|
|
|
|
*/
|
2001-11-07 16:24:55 +00:00
|
|
|
+ (NSCharacterSet*) decomposableCharacterSet
|
1995-05-05 21:03:04 +00:00
|
|
|
{
|
2005-02-27 10:46:19 +00:00
|
|
|
return [self _staticSet: decomposableCharSet number: 3];
|
1995-05-05 21:03:04 +00:00
|
|
|
}
|
|
|
|
|
2002-08-20 10:22:05 +00:00
|
|
|
/**
|
|
|
|
* Returns a character set containing unassigned (illegal)
|
|
|
|
* character values.
|
|
|
|
*/
|
2001-11-07 16:24:55 +00:00
|
|
|
+ (NSCharacterSet*) illegalCharacterSet
|
1995-05-05 21:03:04 +00:00
|
|
|
{
|
2005-02-27 10:46:19 +00:00
|
|
|
return [self _staticSet: illegalCharSet number: 4];
|
1995-05-05 21:03:04 +00:00
|
|
|
}
|
|
|
|
|
2004-06-22 22:40:40 +00:00
|
|
|
/**
|
|
|
|
* Returns a character set containing letters, including all alphabetic as
|
|
|
|
* well as Chinese characters, etc..
|
|
|
|
*/
|
2001-11-07 16:24:55 +00:00
|
|
|
+ (NSCharacterSet*) letterCharacterSet
|
1995-05-05 21:03:04 +00:00
|
|
|
{
|
2005-02-27 10:46:19 +00:00
|
|
|
return [self _staticSet: letterCharSet number: 5];
|
1995-05-05 21:03:04 +00:00
|
|
|
}
|
|
|
|
|
2002-08-20 10:22:05 +00:00
|
|
|
/**
|
|
|
|
* Returns a character set that contains the lowercase characters.
|
|
|
|
* This set does not include caseless characters, only those that
|
|
|
|
* have corresponding characters in uppercase and/or titlecase.
|
|
|
|
*/
|
2001-11-07 16:24:55 +00:00
|
|
|
+ (NSCharacterSet*) lowercaseLetterCharacterSet
|
1995-05-05 21:03:04 +00:00
|
|
|
{
|
2005-02-27 10:46:19 +00:00
|
|
|
return [self _staticSet: lowercaseLetterCharSet number: 6];
|
1995-05-05 21:03:04 +00:00
|
|
|
}
|
|
|
|
|
2004-06-22 22:40:40 +00:00
|
|
|
/**
|
|
|
|
* Returns a character set containing characters for diacritical marks, which
|
|
|
|
* are usually only rendered in conjunction with another character.
|
|
|
|
*/
|
2001-11-07 16:24:55 +00:00
|
|
|
+ (NSCharacterSet*) nonBaseCharacterSet
|
1995-05-05 21:03:04 +00:00
|
|
|
{
|
2005-02-27 10:46:19 +00:00
|
|
|
return [self _staticSet: nonBaseCharSet number: 7];
|
1995-05-05 21:03:04 +00:00
|
|
|
}
|
|
|
|
|
2004-06-22 22:40:40 +00:00
|
|
|
/**
|
|
|
|
* Returns a character set containing punctuation marks.
|
|
|
|
*/
|
2001-12-17 14:31:42 +00:00
|
|
|
+ (NSCharacterSet*) punctuationCharacterSet
|
1998-11-16 19:36:51 +00:00
|
|
|
{
|
2005-02-27 10:46:19 +00:00
|
|
|
return [self _staticSet: punctuationCharSet number: 8];
|
1998-11-16 19:36:51 +00:00
|
|
|
}
|
|
|
|
|
2004-06-22 22:40:40 +00:00
|
|
|
/**
|
|
|
|
* Returns a character set containing mathematical symbols, etc..
|
|
|
|
*/
|
2001-12-17 14:31:42 +00:00
|
|
|
+ (NSCharacterSet*) symbolAndOperatorCharacterSet
|
1999-04-09 15:34:49 +00:00
|
|
|
{
|
2005-02-27 10:46:19 +00:00
|
|
|
return [self _staticSet: symbolAndOperatorCharSet number: 9];
|
1999-04-09 15:34:49 +00:00
|
|
|
}
|
|
|
|
|
2002-08-20 10:22:05 +00:00
|
|
|
/**
|
|
|
|
* Returns a character set that contains the uppercase characters.
|
|
|
|
* This set does not include caseless characters, only those that
|
|
|
|
* have corresponding characters in lowercase and/or titlecase.
|
|
|
|
*/
|
2001-11-07 16:24:55 +00:00
|
|
|
+ (NSCharacterSet*) uppercaseLetterCharacterSet
|
1995-05-05 21:03:04 +00:00
|
|
|
{
|
2005-02-27 10:46:19 +00:00
|
|
|
return [self _staticSet: uppercaseLetterCharSet number: 10];
|
1995-05-05 21:03:04 +00:00
|
|
|
}
|
|
|
|
|
2002-08-20 10:22:05 +00:00
|
|
|
/**
|
|
|
|
* Returns a character set that contains the whitespace characters,
|
|
|
|
* plus the newline characters, values 0x000A and 0x000D.
|
|
|
|
*/
|
2001-11-07 16:24:55 +00:00
|
|
|
+ (NSCharacterSet*) whitespaceAndNewlineCharacterSet
|
1995-05-05 21:03:04 +00:00
|
|
|
{
|
2005-02-27 10:46:19 +00:00
|
|
|
return [self _staticSet: whitespaceAndNlCharSet number: 11];
|
1995-05-05 21:03:04 +00:00
|
|
|
}
|
|
|
|
|
2002-08-20 10:22:05 +00:00
|
|
|
/**
|
|
|
|
* Returns a character set that contains the whitespace characters.
|
|
|
|
*/
|
2001-11-07 16:24:55 +00:00
|
|
|
+ (NSCharacterSet*) whitespaceCharacterSet
|
1995-05-05 21:03:04 +00:00
|
|
|
{
|
2005-02-27 10:46:19 +00:00
|
|
|
return [self _staticSet: whitespaceCharSet number: 12];
|
1995-05-05 21:03:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Creating custom character sets
|
|
|
|
|
2002-08-20 10:22:05 +00:00
|
|
|
/**
|
|
|
|
* Returns a character set containing characters as encoded in the
|
|
|
|
* data object.
|
|
|
|
*/
|
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
|
|
|
}
|
|
|
|
|
2004-06-22 22:40:40 +00:00
|
|
|
/**
|
|
|
|
* Returns set with characters in aString, or empty set for empty string.
|
|
|
|
* Raises an exception if given a nil string.
|
|
|
|
*/
|
2001-11-07 16:24:55 +00:00
|
|
|
+ (NSCharacterSet*) characterSetWithCharactersInString: (NSString*)aString
|
1995-05-05 21:03:04 +00:00
|
|
|
{
|
2001-11-07 16:24:55 +00:00
|
|
|
unsigned i;
|
|
|
|
unsigned length;
|
|
|
|
unsigned char *bytes;
|
1999-04-07 11:57:53 +00:00
|
|
|
NSMutableData *bitmap = [NSMutableData dataWithLength: BITMAP_SIZE];
|
1995-08-30 21:31:29 +00:00
|
|
|
|
|
|
|
if (!aString)
|
|
|
|
{
|
1999-04-07 11:57:53 +00:00
|
|
|
[NSException raise: NSInvalidArgumentException
|
|
|
|
format: @"Creating character set with nil string"];
|
1995-08-30 21:31:29 +00:00
|
|
|
/* NOT REACHED */
|
|
|
|
}
|
|
|
|
|
|
|
|
length = [aString length];
|
|
|
|
bytes = [bitmap mutableBytes];
|
2001-11-07 16:24:55 +00:00
|
|
|
for (i = 0; i < length; i++)
|
1995-08-30 21:31:29 +00:00
|
|
|
{
|
1999-04-07 11:57:53 +00:00
|
|
|
unichar letter = [aString characterAtIndex: i];
|
2001-11-07 16:24:55 +00:00
|
|
|
|
1995-08-30 21:31:29 +00:00
|
|
|
SETBIT(bytes[letter/8], letter % 8);
|
|
|
|
}
|
|
|
|
|
1999-04-07 11:57:53 +00:00
|
|
|
return [self characterSetWithBitmapRepresentation: bitmap];
|
1995-05-05 21:03:04 +00:00
|
|
|
}
|
|
|
|
|
2004-06-22 22:40:40 +00:00
|
|
|
/**
|
|
|
|
* Returns set containing unicode index range given by aRange.
|
|
|
|
*/
|
2001-11-07 16:24:55 +00:00
|
|
|
+ (NSCharacterSet*)characterSetWithRange: (NSRange)aRange
|
1995-05-05 21:03:04 +00:00
|
|
|
{
|
2001-11-07 16:24:55 +00:00
|
|
|
unsigned i;
|
|
|
|
unsigned char *bytes;
|
1999-04-07 11:57:53 +00:00
|
|
|
NSMutableData *bitmap = [NSMutableData dataWithLength: BITMAP_SIZE];
|
1995-08-30 21:31:29 +00:00
|
|
|
|
|
|
|
if (NSMaxRange(aRange) > UNICODE_SIZE)
|
|
|
|
{
|
1999-04-07 11:57:53 +00:00
|
|
|
[NSException raise: NSInvalidArgumentException
|
|
|
|
format: @"Specified range exceeds character set"];
|
1995-08-30 21:31:29 +00:00
|
|
|
/* NOT REACHED */
|
|
|
|
}
|
|
|
|
|
2001-11-07 16:24:55 +00:00
|
|
|
bytes = (unsigned char*)[bitmap mutableBytes];
|
|
|
|
for (i = aRange.location; i < NSMaxRange(aRange); i++)
|
|
|
|
{
|
1995-08-30 21:31:29 +00:00
|
|
|
SETBIT(bytes[i/8], i % 8);
|
2001-11-07 16:24:55 +00:00
|
|
|
}
|
1999-04-07 11:57:53 +00:00
|
|
|
return [self characterSetWithBitmapRepresentation: bitmap];
|
1995-05-05 21:03:04 +00:00
|
|
|
}
|
|
|
|
|
2004-06-22 22:40:40 +00:00
|
|
|
/**
|
|
|
|
* Initializes from a bitmap. (See [NSBitmapCharSet].) File must have
|
|
|
|
* extension "<code>.bitmap</code>". (To get around this load the file
|
|
|
|
* into data yourself and use
|
|
|
|
* [NSCharacterSet -characterSetWithBitmapRepresentation].
|
|
|
|
*/
|
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;
|
|
|
|
}
|
|
|
|
|
2002-08-20 10:22:05 +00:00
|
|
|
/**
|
|
|
|
* Returns a bitmap representation of the receiver's character set
|
|
|
|
* suitable for archiving or writing to a file, in an NSData object.
|
|
|
|
*/
|
2001-11-07 16:24:55 +00:00
|
|
|
- (NSData*) bitmapRepresentation
|
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;
|
|
|
|
}
|
|
|
|
|
2002-08-20 10:22:05 +00:00
|
|
|
/**
|
|
|
|
* Returns YES if the receiver contains <em>aCharacter</em>, NO if
|
|
|
|
* it does not.
|
|
|
|
*/
|
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;
|
|
|
|
}
|
|
|
|
|
1998-07-29 09:22:18 +00:00
|
|
|
- (void) encodeWithCoder: (NSCoder*)aCoder
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
- (id) initWithCoder: (NSCoder*)aCoder
|
|
|
|
{
|
2005-02-27 10:46:19 +00:00
|
|
|
if ([self class] == [NSCharacterSet class])
|
|
|
|
{
|
|
|
|
int index;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Abstract class returns characterset from cache.
|
|
|
|
*/
|
|
|
|
DESTROY(self);
|
|
|
|
[aCoder decodeValueOfObjCType: @encode(int) at: &index];
|
|
|
|
self = RETAIN([NSCharacterSet _staticSet: 0 number: index]);
|
|
|
|
}
|
|
|
|
return self;
|
1998-07-29 09:22:18 +00:00
|
|
|
}
|
|
|
|
|
1998-07-29 14:46:16 +00:00
|
|
|
- (BOOL) isEqual: (id)anObject
|
|
|
|
{
|
|
|
|
if (anObject == self)
|
|
|
|
return YES;
|
1999-04-07 11:57:53 +00:00
|
|
|
if ([anObject isKindOfClass: [NSCharacterSet class]])
|
1998-07-29 14:46:16 +00:00
|
|
|
{
|
2001-11-07 16:24:55 +00:00
|
|
|
unsigned i;
|
1998-07-29 14:46:16 +00:00
|
|
|
|
|
|
|
for (i = 0; i <= 0xffff; i++)
|
2001-11-07 16:24:55 +00:00
|
|
|
{
|
|
|
|
if ([self characterIsMember: (unichar)i]
|
|
|
|
!= [anObject characterIsMember: (unichar)i])
|
|
|
|
{
|
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
}
|
1998-07-29 14:46:16 +00:00
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
|
2002-08-20 10:22:05 +00:00
|
|
|
/**
|
|
|
|
* Returns a character set containing only characters that the
|
|
|
|
* receiver does not contain.
|
|
|
|
*/
|
2001-11-07 16:24:55 +00:00
|
|
|
- (NSCharacterSet*) invertedSet
|
1995-05-05 21:03:04 +00:00
|
|
|
{
|
2001-11-07 16:24:55 +00:00
|
|
|
unsigned i;
|
|
|
|
unsigned length;
|
|
|
|
unsigned char *bytes;
|
|
|
|
NSMutableData *bitmap;
|
1995-05-05 21:03:04 +00:00
|
|
|
|
1999-06-03 10:59:25 +00:00
|
|
|
bitmap = AUTORELEASE([[self bitmapRepresentation] mutableCopy]);
|
1995-08-30 21:31:29 +00:00
|
|
|
length = [bitmap length];
|
|
|
|
bytes = [bitmap mutableBytes];
|
2001-11-07 16:24:55 +00:00
|
|
|
for (i = 0; i < length; i++)
|
|
|
|
{
|
1995-08-30 21:31:29 +00:00
|
|
|
bytes[i] = ~bytes[i];
|
2001-11-07 16:24:55 +00:00
|
|
|
}
|
1999-04-07 11:57:53 +00:00
|
|
|
return [[self class] characterSetWithBitmapRepresentation: bitmap];
|
1995-05-05 21:03:04 +00:00
|
|
|
}
|
|
|
|
|
1995-08-30 21:31:29 +00:00
|
|
|
|
|
|
|
// NSCopying, NSMutableCopying
|
2001-11-07 16:24:55 +00:00
|
|
|
- (id) copyWithZone: (NSZone*)zone
|
1995-05-05 21:03:04 +00:00
|
|
|
{
|
|
|
|
if (NSShouldRetainWithZone(self, zone))
|
1999-06-03 10:59:25 +00:00
|
|
|
return RETAIN(self);
|
1995-05-05 21:03:04 +00:00
|
|
|
else
|
1999-06-03 10:59:25 +00:00
|
|
|
return NSCopyObject (self, 0, zone);
|
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
|
|
|
|
|
2004-06-22 22:40:40 +00:00
|
|
|
/**
|
|
|
|
* An [NSCharacterSet] that can be modified.
|
|
|
|
*/
|
1995-05-05 21:03:04 +00:00
|
|
|
@implementation NSMutableCharacterSet
|
|
|
|
|
1995-08-30 21:31:29 +00:00
|
|
|
/* Provide a default object for allocation */
|
2001-11-07 16:24:55 +00:00
|
|
|
+ (id) allocWithZone: (NSZone*)zone
|
1995-08-30 21:31:29 +00:00
|
|
|
{
|
|
|
|
return NSAllocateObject([NSMutableBitmapCharSet self], 0, zone);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* 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
|
|
|
}
|
|
|
|
|
2004-06-22 22:40:40 +00:00
|
|
|
/* Mutable subclasses must implement ALL of these methods. */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Adds characters specified by unicode indices in aRange to set.
|
|
|
|
*/
|
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
|
|
|
}
|
|
|
|
|
2004-06-22 22:40:40 +00:00
|
|
|
/**
|
|
|
|
* Adds characters in aString to set.
|
|
|
|
*/
|
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
|
|
|
}
|
|
|
|
|
2004-06-22 22:40:40 +00:00
|
|
|
/**
|
|
|
|
* Set union of character sets.
|
|
|
|
*/
|
2001-11-07 16:24:55 +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
|
|
|
}
|
|
|
|
|
2004-06-22 22:40:40 +00:00
|
|
|
/**
|
|
|
|
* Set intersection of character sets.
|
|
|
|
*/
|
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
|
|
|
}
|
|
|
|
|
2004-06-22 22:40:40 +00:00
|
|
|
/**
|
|
|
|
* Drop given range of characters. No error for characters not currently in
|
|
|
|
* set.
|
|
|
|
*/
|
2001-11-07 16:24:55 +00:00
|
|
|
- (void) removeCharactersInRange: (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
|
|
|
}
|
|
|
|
|
2004-06-22 22:40:40 +00:00
|
|
|
/**
|
|
|
|
* Drop characters in aString. No error for characters not currently in
|
|
|
|
* set.
|
|
|
|
*/
|
2001-11-07 16:24:55 +00:00
|
|
|
- (void) removeCharactersInString: (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
|
|
|
}
|
|
|
|
|
2004-06-22 22:40:40 +00:00
|
|
|
/**
|
|
|
|
* Remove all characters currently in set and add all other characters.
|
|
|
|
*/
|
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
|
|
|
}
|
|
|
|
|
|
|
|
// NSCopying, NSMutableCopying
|
2001-11-07 16:24:55 +00:00
|
|
|
- (id) copyWithZone: (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 [[NSBitmapCharSet allocWithZone: zone] initWithBitmap: bitmap];
|
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
|
|
|
{
|
1999-04-07 11:57:53 +00:00
|
|
|
return [super mutableCopyWithZone: zone];
|
1995-05-05 21:03:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@end
|