mirror of
https://github.com/gnustep/libs-base.git
synced 2025-04-22 16:33:29 +00:00
Initial revision
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@420 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
bfc8c30324
commit
2402c8664d
2 changed files with 231 additions and 0 deletions
54
Headers/gnustep/base/NSBitmapCharSet.h
Normal file
54
Headers/gnustep/base/NSBitmapCharSet.h
Normal file
|
@ -0,0 +1,54 @@
|
|||
/* Interface for NSBitmapCharSet for GNUStep
|
||||
Copyright (C) 1995 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of the GNU Objective C Class Library.
|
||||
|
||||
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.
|
||||
|
||||
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
|
||||
Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
|
||||
#ifndef __NSBitmapCharSet_h_OBJECTS_INCLUDE
|
||||
#define __NSBitmapCharSet_h_OBJECTS_INCLUDE
|
||||
|
||||
#include <Foundation/NSCharacterSet.h>
|
||||
#include <Foundation/NSData.h>
|
||||
|
||||
#define UNICODE_SIZE 65536
|
||||
#define BITMAP_SIZE UNICODE_SIZE/8
|
||||
|
||||
#ifndef SETBIT
|
||||
#define SETBIT(a,i) ((a) |= 1<<(i))
|
||||
#define CLRBIT(a,i) ((a) &= ~(1<<(i)))
|
||||
#define ISSET(a,i) ((((a) & (1<<(i)))) > 0) ? YES : NO;
|
||||
#endif
|
||||
|
||||
@interface NSBitmapCharSet : NSCharacterSet
|
||||
{
|
||||
char data[BITMAP_SIZE];
|
||||
}
|
||||
|
||||
- initWithBitmap:(NSData *)bitmap;
|
||||
|
||||
@end
|
||||
|
||||
@interface NSMutableBitmapCharSet : NSMutableCharacterSet
|
||||
{
|
||||
char data[BITMAP_SIZE];
|
||||
}
|
||||
|
||||
- initWithBitmap:(NSData *)bitmap;
|
||||
|
||||
@end
|
||||
|
||||
#endif /* __NSBitmapCharSet_h_OBJECTS_INCLUDE */
|
177
Source/NSBitmapCharSet.m
Normal file
177
Source/NSBitmapCharSet.m
Normal file
|
@ -0,0 +1,177 @@
|
|||
/* NSBitmapCharSet - Concrete character set holder
|
||||
Copyright (C) 1993,1994 Free Software Foundation, Inc.
|
||||
|
||||
Written by: Adam Fedor <fedor@boulder.colorado.edu>
|
||||
Date: Apr 1995
|
||||
|
||||
This file is part of the GNU Objective C Class Library.
|
||||
|
||||
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.
|
||||
|
||||
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
|
||||
Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
|
||||
#include <Foundation/NSBitmapCharSet.h>
|
||||
#include <Foundation/NSException.h>
|
||||
|
||||
@implementation NSBitmapCharSet
|
||||
|
||||
- init
|
||||
{
|
||||
return [self initWithBitmap:NULL];
|
||||
}
|
||||
|
||||
/* Designated initializer */
|
||||
- initWithBitmap:(NSData *)bitmap
|
||||
{
|
||||
[super init];
|
||||
[bitmap getBytes:data length:BITMAP_SIZE];
|
||||
return self;
|
||||
}
|
||||
|
||||
- (NSData *)bitmapRepresentation
|
||||
{
|
||||
return [NSData dataWithBytes:data length:BITMAP_SIZE];
|
||||
}
|
||||
|
||||
- (BOOL)characterIsMember:(unichar)aCharacter
|
||||
{
|
||||
return ISSET(data[aCharacter/8], aCharacter % 8);
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation NSMutableBitmapCharSet
|
||||
|
||||
- init
|
||||
{
|
||||
return [self initWithBitmap:NULL];
|
||||
}
|
||||
|
||||
/* Designated initializer */
|
||||
- initWithBitmap:(NSData *)bitmap
|
||||
{
|
||||
[super init];
|
||||
if (bitmap)
|
||||
[bitmap getBytes:data length:BITMAP_SIZE];
|
||||
return self;
|
||||
}
|
||||
|
||||
/* Need to implement the next two methods just like NSBitmapCharSet */
|
||||
- (NSData *)bitmapRepresentation
|
||||
{
|
||||
return [NSData dataWithBytes:data length:BITMAP_SIZE];
|
||||
}
|
||||
|
||||
- (BOOL)characterIsMember:(unichar)aCharacter
|
||||
{
|
||||
return ISSET(data[aCharacter/8], aCharacter % 8);
|
||||
}
|
||||
|
||||
- (void)addCharactersInRange:(NSRange)aRange
|
||||
{
|
||||
int i;
|
||||
|
||||
if (NSMaxRange(aRange) > UNICODE_SIZE)
|
||||
{
|
||||
[NSException raise:NSInvalidArgumentException
|
||||
format:@"Specified range exceeds character set"];
|
||||
/* NOT REACHED */
|
||||
}
|
||||
|
||||
for (i=aRange.location; i < NSMaxRange(aRange); i++)
|
||||
SETBIT(data[i/8], i % 8);
|
||||
}
|
||||
|
||||
- (void)addCharactersInString:(NSString *)aString
|
||||
{
|
||||
int i, length;
|
||||
|
||||
if (!aString)
|
||||
{
|
||||
[NSException raise:NSInvalidArgumentException
|
||||
format:@"Adding characters from nil string"];
|
||||
/* NOT REACHED */
|
||||
}
|
||||
|
||||
length = [aString length];
|
||||
for (i=0; i < length; i++)
|
||||
{
|
||||
unichar letter = [aString characterAtIndex:i];
|
||||
SETBIT(data[letter/8], letter % 8);
|
||||
}
|
||||
}
|
||||
|
||||
- (void)formUnionWithCharacterSet:(NSCharacterSet *)otherSet
|
||||
{
|
||||
int i;
|
||||
const char *other_bytes;
|
||||
|
||||
other_bytes = [[otherSet bitmapRepresentation] bytes];
|
||||
for (i=0; i < BITMAP_SIZE; i++)
|
||||
data[i] = (data[i] || other_bytes[i]);
|
||||
}
|
||||
|
||||
- (void)formIntersectionWithCharacterSet:(NSCharacterSet *)otherSet
|
||||
{
|
||||
int i;
|
||||
const char *other_bytes;
|
||||
|
||||
other_bytes = [[otherSet bitmapRepresentation] bytes];
|
||||
for (i=0; i < BITMAP_SIZE; i++)
|
||||
data[i] = (data[i] && other_bytes[i]);
|
||||
}
|
||||
|
||||
- (void)removeCharactersInRange:(NSRange)aRange
|
||||
{
|
||||
int i;
|
||||
|
||||
if (NSMaxRange(aRange) > UNICODE_SIZE)
|
||||
{
|
||||
[NSException raise:NSInvalidArgumentException
|
||||
format:@"Specified range exceeds character set"];
|
||||
/* NOT REACHED */
|
||||
}
|
||||
|
||||
for (i=aRange.location; i < NSMaxRange(aRange); i++)
|
||||
CLRBIT(data[i/8], i % 8);
|
||||
}
|
||||
|
||||
- (void)removeCharactersInString:(NSString *)aString
|
||||
{
|
||||
int i, length;
|
||||
|
||||
if (!aString)
|
||||
{
|
||||
[NSException raise:NSInvalidArgumentException
|
||||
format:@"Removing characters from nil string"];
|
||||
/* NOT REACHED */
|
||||
}
|
||||
|
||||
length = [aString length];
|
||||
for (i=0; i < length; i++)
|
||||
{
|
||||
unichar letter = [aString characterAtIndex:i];
|
||||
CLRBIT(data[letter/8], letter % 8);
|
||||
}
|
||||
}
|
||||
|
||||
- (void)invert
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i=0; i < BITMAP_SIZE; i++)
|
||||
data[i] = ~data[i];
|
||||
}
|
||||
|
||||
@end
|
Loading…
Reference in a new issue