1
/** NSBitmapCharSet - Concrete character set holder
2
Copyright (C) 1993,1994 Free Software Foundation, Inc.
4
Written by: Adam Fedor <fedor@boulder.colorado.edu>
7
This file is part of the GNUstep Base Library.
9
This library is free software; you can redistribute it and/or
10
modify it under the terms of the GNU Library General Public
11
License as published by the Free Software Foundation; either
12
version 2 of the License, or (at your option) any later version.
14
This library is distributed in the hope that it will be useful,
15
but WITHOUT ANY WARRANTY; without even the implied warranty of
16
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17
Library General Public License for more details.
19
You should have received a copy of the GNU Library General Public
20
License along with this library; if not, write to the Free
21
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA.
23
<title>NSBitmapCharSet class reference</title>
24
$Date: 2005/02/22 11:22:43 $ $Revision: 1.16 $
28
#include "Foundation/NSBitmapCharSet.h"
29
#include "Foundation/NSException.h"
30
#include "Foundation/NSCoder.h"
32
@implementation NSBitmapCharSet
36
return [self initWithBitmap: NULL];
39
/** Designated initializer */
40
- (id) initWithBitmap: (NSData*)bitmap
44
if ([bitmap length] != BITMAP_SIZE)
46
NSLog(@"attempt to initialize character set with invalid bitmap");
51
[bitmap getBytes: _data length: BITMAP_SIZE];
56
- (NSData*) bitmapRepresentation
58
return [NSData dataWithBytes: _data length: BITMAP_SIZE];
61
- (BOOL) characterIsMember: (unichar)aCharacter
63
return ISSET(_data[aCharacter/8], aCharacter % 8);
66
- (void) encodeWithCoder: (NSCoder*)aCoder
68
[aCoder encodeObject: [self bitmapRepresentation]];
71
- (id) initWithCoder: (NSCoder*)aCoder
75
rep = [aCoder decodeObject];
76
self = [self initWithBitmap: rep];
82
@implementation NSMutableBitmapCharSet
86
return [self initWithBitmap: NULL];
89
/* Designated initializer */
90
- (id) initWithBitmap: (NSData*)bitmap
94
[bitmap getBytes: _data length: BITMAP_SIZE];
98
- (void) encodeWithCoder: (NSCoder*)aCoder
100
[aCoder encodeObject: [self bitmapRepresentation]];
103
- (id) initWithCoder: (NSCoder*)aCoder
107
rep = [aCoder decodeObject];
108
self = [self initWithBitmap: rep];
112
/* Need to implement the next two methods just like NSBitmapCharSet */
113
- (NSData*) bitmapRepresentation
115
return [NSData dataWithBytes: _data length: BITMAP_SIZE];
118
- (BOOL) characterIsMember: (unichar)aCharacter
120
return ISSET(_data[aCharacter/8], aCharacter % 8);
123
- (void) addCharactersInRange: (NSRange)aRange
127
if (NSMaxRange(aRange) > UNICODE_SIZE)
129
[NSException raise:NSInvalidArgumentException
130
format:@"Specified range exceeds character set"];
134
for (i = aRange.location; i < NSMaxRange(aRange); i++)
136
SETBIT(_data[i/8], i % 8);
140
- (void) addCharactersInString: (NSString*)aString
146
[NSException raise:NSInvalidArgumentException
147
format:@"Adding characters from nil string"];
151
length = [aString length];
155
unichar (*get)(id, SEL, unsigned);
157
get = (unichar (*)(id, SEL, unsigned))
158
[aString methodForSelector: @selector(characterAtIndex:)];
159
for (i = 0; i < length; i++)
163
letter = (*get)(aString, @selector(characterAtIndex:), i);
164
SETBIT(_data[letter/8], letter % 8);
169
- (void) formUnionWithCharacterSet: (NSCharacterSet*)otherSet
172
const char *other_bytes;
174
other_bytes = [[otherSet bitmapRepresentation] bytes];
175
for (i = 0; i < BITMAP_SIZE; i++)
177
_data[i] = (_data[i] | other_bytes[i]);
181
- (void) formIntersectionWithCharacterSet: (NSCharacterSet *)otherSet
184
const char *other_bytes;
186
other_bytes = [[otherSet bitmapRepresentation] bytes];
187
for (i = 0; i < BITMAP_SIZE; i++)
189
_data[i] = (_data[i] & other_bytes[i]);
193
- (void) removeCharactersInRange: (NSRange)aRange
197
if (NSMaxRange(aRange) > UNICODE_SIZE)
199
[NSException raise:NSInvalidArgumentException
200
format:@"Specified range exceeds character set"];
204
for (i = aRange.location; i < NSMaxRange(aRange); i++)
206
CLRBIT(_data[i/8], i % 8);
210
- (void) removeCharactersInString: (NSString*)aString
216
[NSException raise:NSInvalidArgumentException
217
format:@"Removing characters from nil string"];
221
length = [aString length];
225
unichar (*get)(id, SEL, unsigned);
227
get = (unichar (*)(id, SEL, unsigned))
228
[aString methodForSelector: @selector(characterAtIndex:)];
230
for (i = 0; i < length; i++)
234
letter = (*get)(aString, @selector(characterAtIndex:), i);
235
CLRBIT(_data[letter/8], letter % 8);
244
for (i = 0; i < BITMAP_SIZE; i++)
246
_data[i] = ~_data[i];