- Issue #57, Rolf Jansen's NSSystemInfoPanel implementation

- Rolf Jansen's NSImageCell's NSCoding implementation
- NSCharacterSet interface/behavior fix suggestion by thinker at thinkertons
This commit is contained in:
Christopher Lloyd 2008-01-09 15:53:47 +00:00
parent cba2f18b98
commit e74537fe1e
16 changed files with 332 additions and 61 deletions

View File

@ -1346,6 +1346,14 @@
FE7247A70C0622F2007CBC51 /* NSTextAttachmentCell.m in Sources */ = {isa = PBXBuildFile; fileRef = FE7247A50C0622F2007CBC51 /* NSTextAttachmentCell.m */; };
FE7248510C0676AA007CBC51 /* NSTypesetter_concrete.h in Headers */ = {isa = PBXBuildFile; fileRef = FE72484F0C0676AA007CBC51 /* NSTypesetter_concrete.h */; };
FE7248520C0676AA007CBC51 /* NSTypesetter_concrete.m in Sources */ = {isa = PBXBuildFile; fileRef = FE7248500C0676AA007CBC51 /* NSTypesetter_concrete.m */; };
FE82867B0D34727900F7489F /* NSApplicationIcon.tiff in Resources */ = {isa = PBXBuildFile; fileRef = FE8286770D34727900F7489F /* NSApplicationIcon.tiff */; };
FE82867C0D34727900F7489F /* NSSystemInfoPanel.h in Headers */ = {isa = PBXBuildFile; fileRef = FE8286780D34727900F7489F /* NSSystemInfoPanel.h */; settings = {ATTRIBUTES = (Private, ); }; };
FE82867D0D34727900F7489F /* NSSystemInfoPanel.m in Sources */ = {isa = PBXBuildFile; fileRef = FE8286790D34727900F7489F /* NSSystemInfoPanel.m */; };
FE82867E0D34727900F7489F /* NSSystemInfoPanel.nib in Resources */ = {isa = PBXBuildFile; fileRef = FE82867A0D34727900F7489F /* NSSystemInfoPanel.nib */; };
FE82867F0D34727900F7489F /* NSApplicationIcon.tiff in Resources */ = {isa = PBXBuildFile; fileRef = FE8286770D34727900F7489F /* NSApplicationIcon.tiff */; };
FE8286800D34727900F7489F /* NSSystemInfoPanel.h in Headers */ = {isa = PBXBuildFile; fileRef = FE8286780D34727900F7489F /* NSSystemInfoPanel.h */; settings = {ATTRIBUTES = (Private, ); }; };
FE8286810D34727900F7489F /* NSSystemInfoPanel.m in Sources */ = {isa = PBXBuildFile; fileRef = FE8286790D34727900F7489F /* NSSystemInfoPanel.m */; };
FE8286820D34727900F7489F /* NSSystemInfoPanel.nib in Resources */ = {isa = PBXBuildFile; fileRef = FE82867A0D34727900F7489F /* NSSystemInfoPanel.nib */; };
FE86887F0BC3FFA4009F515C /* NSButtonCell_disclosure_highlighted.tif in Resources */ = {isa = PBXBuildFile; fileRef = FE86887C0BC3FFA4009F515C /* NSButtonCell_disclosure_highlighted.tif */; };
FE8688800BC3FFA4009F515C /* NSButtonCell_disclosure_normal.tif in Resources */ = {isa = PBXBuildFile; fileRef = FE86887D0BC3FFA4009F515C /* NSButtonCell_disclosure_normal.tif */; };
FE8688810BC3FFA4009F515C /* NSButtonCell_disclosure_selected.tif in Resources */ = {isa = PBXBuildFile; fileRef = FE86887E0BC3FFA4009F515C /* NSButtonCell_disclosure_selected.tif */; };
@ -2148,6 +2156,10 @@
FE7247A50C0622F2007CBC51 /* NSTextAttachmentCell.m */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.objc; path = NSTextAttachmentCell.m; sourceTree = "<group>"; };
FE72484F0C0676AA007CBC51 /* NSTypesetter_concrete.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = NSTypesetter_concrete.h; sourceTree = "<group>"; };
FE7248500C0676AA007CBC51 /* NSTypesetter_concrete.m */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.objc; path = NSTypesetter_concrete.m; sourceTree = "<group>"; };
FE8286770D34727900F7489F /* NSApplicationIcon.tiff */ = {isa = PBXFileReference; lastKnownFileType = image.tiff; path = NSApplicationIcon.tiff; sourceTree = "<group>"; };
FE8286780D34727900F7489F /* NSSystemInfoPanel.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = NSSystemInfoPanel.h; sourceTree = "<group>"; };
FE8286790D34727900F7489F /* NSSystemInfoPanel.m */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.objc; path = NSSystemInfoPanel.m; sourceTree = "<group>"; };
FE82867A0D34727900F7489F /* NSSystemInfoPanel.nib */ = {isa = PBXFileReference; lastKnownFileType = wrapper.nib; path = NSSystemInfoPanel.nib; sourceTree = "<group>"; };
FE86887C0BC3FFA4009F515C /* NSButtonCell_disclosure_highlighted.tif */ = {isa = PBXFileReference; lastKnownFileType = image.tiff; path = NSButtonCell_disclosure_highlighted.tif; sourceTree = "<group>"; };
FE86887D0BC3FFA4009F515C /* NSButtonCell_disclosure_normal.tif */ = {isa = PBXFileReference; lastKnownFileType = image.tiff; path = NSButtonCell_disclosure_normal.tif; sourceTree = "<group>"; };
FE86887E0BC3FFA4009F515C /* NSButtonCell_disclosure_selected.tif */ = {isa = PBXFileReference; lastKnownFileType = image.tiff; path = NSButtonCell_disclosure_selected.tif; sourceTree = "<group>"; };
@ -2467,6 +2479,7 @@
6E2B53C30976075200DA0954 /* NSStringDrawer.m */,
6E2B549C0976075200DA0954 /* NSStringDrawing.h */,
6E2B53C50976075200DA0954 /* NSStringDrawing.m */,
FE8286760D34725900F7489F /* NSSystemInfoPanel */,
6E2B54A60976075200DA0954 /* NSTableColumn.h */,
6E2B53C70976075200DA0954 /* NSTableColumn.m */,
6E2B54A80976075200DA0954 /* NSTableCornerView.h */,
@ -3175,6 +3188,17 @@
path = NSInterfacePart;
sourceTree = "<group>";
};
FE8286760D34725900F7489F /* NSSystemInfoPanel */ = {
isa = PBXGroup;
children = (
FE8286770D34727900F7489F /* NSApplicationIcon.tiff */,
FE8286780D34727900F7489F /* NSSystemInfoPanel.h */,
FE8286790D34727900F7489F /* NSSystemInfoPanel.m */,
FE82867A0D34727900F7489F /* NSSystemInfoPanel.nib */,
);
path = NSSystemInfoPanel;
sourceTree = "<group>";
};
FE8BAF1A0BC9EC0B0007FACA /* NSKeyValueBinding */ = {
isa = PBXGroup;
children = (
@ -3556,6 +3580,7 @@
FEA8A98C0CD2CBC000E1E936 /* NSUserInterfaceValidation.h in Headers */,
FE8D94AD0CE3A6C700AFB060 /* NSControllerSelectionProxy.h in Headers */,
FE8D95220CE4057300AFB060 /* NSMultipleValueBinder.h in Headers */,
FE82867C0D34727900F7489F /* NSSystemInfoPanel.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@ -3897,6 +3922,7 @@
FEA8A98D0CD2CBC000E1E936 /* NSUserInterfaceValidation.h in Headers */,
FE8D94AB0CE3A6C700AFB060 /* NSControllerSelectionProxy.h in Headers */,
FE8D95200CE4057300AFB060 /* NSMultipleValueBinder.h in Headers */,
FE8286800D34727900F7489F /* NSSystemInfoPanel.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@ -4058,6 +4084,8 @@
FE8688800BC3FFA4009F515C /* NSButtonCell_disclosure_normal.tif in Resources */,
FE8688810BC3FFA4009F515C /* NSButtonCell_disclosure_selected.tif in Resources */,
C8B239A30BF8EEB500CA33AF /* defaultBindingOptions.plist in Resources */,
FE82867B0D34727900F7489F /* NSApplicationIcon.tiff in Resources */,
FE82867E0D34727900F7489F /* NSSystemInfoPanel.nib in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@ -4103,6 +4131,8 @@
FE01AAB80C5D9BCB00AEA51A /* NSButtonCell_disclosure_normal.tif in Resources */,
FE01AAB90C5D9BCB00AEA51A /* NSButtonCell_disclosure_selected.tif in Resources */,
FE01AABA0C5D9BCB00AEA51A /* defaultBindingOptions.plist in Resources */,
FE82867F0D34727900F7489F /* NSApplicationIcon.tiff in Resources */,
FE8286820D34727900F7489F /* NSSystemInfoPanel.nib in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@ -4456,6 +4486,7 @@
FE311FA70CCC430200EBD696 /* KGFont_gdi.m in Sources */,
FE8D94AE0CE3A6C700AFB060 /* NSControllerSelectionProxy.m in Sources */,
FE8D95230CE4057300AFB060 /* NSMultipleValueBinder.m in Sources */,
FE82867D0D34727900F7489F /* NSSystemInfoPanel.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@ -4789,6 +4820,7 @@
FE311FA90CCC430200EBD696 /* KGFont_gdi.m in Sources */,
FE8D94AC0CE3A6C700AFB060 /* NSControllerSelectionProxy.m in Sources */,
FE8D95210CE4057300AFB060 /* NSMultipleValueBinder.m in Sources */,
FE8286810D34727900F7489F /* NSSystemInfoPanel.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};

View File

@ -25,6 +25,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
#import <AppKit/NSImage.h>
#import <AppKit/NSImageView.h>
#import <AppKit/NSSheetContext.h>
#import <AppKit/NSSystemInfoPanel.h>
NSString *NSModalPanelRunLoopMode=@"NSModalPanelRunLoopMode";
NSString *NSEventTrackingRunLoopMode=@"NSEventTrackingRunLoopMode";
@ -864,7 +865,10 @@ id NSApp=nil;
}
-(void)orderFrontStandardAboutPanelWithOptions:(NSDictionary *)options {
NSUnimplementedMethod();
NSSystemInfoPanel *standardAboutPanel = [[NSSystemInfoPanel
standardAboutPanel] retain];
[standardAboutPanel showInfoPanel:self];
}
-(void)activateContextHelpMode:sender {

View File

@ -35,6 +35,7 @@ typedef enum {
} NSImageFrameStyle;
@interface NSImageCell : NSCell {
BOOL _animates;
NSImageAlignment _imageAlignment;
NSImageScaling _imageScaling;
NSImageFrameStyle _frameStyle;

View File

@ -12,9 +12,37 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
#import <AppKit/NSGraphics.h>
#import <AppKit/CGContext.h>
#import <AppKit/NSGraphicsContext.h>
#import <AppKit/NSNibKeyedUnarchiver.h>
@implementation NSImageCell
-(void)encodeWithCoder:(NSCoder *)coder
{
[super encodeWithCoder:coder];
[coder encodeBool:_animates forKey:@"NSAnimates"];
[coder encodeInt:_imageAlignment forKey:@"NSAlign"];
[coder encodeInt:_imageScaling forKey:@"NSScale"];
[coder encodeInt:_frameStyle forKey:@"NSStyle"];
}
-(id)initWithCoder:(NSCoder *)coder
{
[super initWithCoder:coder];
if([coder isKindOfClass:[NSNibKeyedUnarchiver class]])
{
NSNibKeyedUnarchiver *keyed=(NSNibKeyedUnarchiver *)coder;
_animates = [keyed decodeBoolForKey:@"NSAnimates"];
_imageAlignment = [keyed decodeIntForKey:@"NSAlign"];
_imageScaling = [keyed decodeIntForKey:@"NSScale"];
_frameStyle = [keyed decodeIntForKey:@"NSStyle"];
}
else
[NSException raise:NSInvalidArgumentException format:@"%@ can not initWithCoder:%@",isa,[coder class]];
return self;
}
-(NSImage *)_imageValue {
id result=[self image];

Binary file not shown.

View File

@ -0,0 +1,27 @@
/* Copyright (c) 2007 Dr. Rolf Jansen
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
#import <AppKit/NSPanel.h>
@class NSImageView,NSTextField;
@interface NSSystemInfoPanel : NSObject
{
IBOutlet NSImageView *appIconView;
IBOutlet NSTextField *appNameField;
IBOutlet NSScrollView *creditScrollView;
IBOutlet NSTextView *creditView;
IBOutlet NSPanel *infoPanel;
IBOutlet NSTextField *legalTextField;
IBOutlet NSTextField *versionField;
}
+ (NSSystemInfoPanel *)standardAboutPanel;
- (IBAction)showInfoPanel:(id)sender;
@end

View File

@ -0,0 +1,83 @@
/* Copyright (c) 2007 Dr. Rolf Jansen
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
#import <Foundation/NSDictionary.h>
#import <Appkit/NSAttributedString.h>
#import <AppKit/NSImage.h>
#import <AppKit/NSNibLoading.h>
#import <AppKit/NSSystemInfoPanel.h>
#import <AppKit/NSScreen.h>
#import <AppKit/NSImageView.h>
#import <AppKit/NSText.h>
@implementation NSSystemInfoPanel
static NSSystemInfoPanel *_sharedInfoPanel = nil;
+ (NSSystemInfoPanel *)standardAboutPanel
{
if(_sharedInfoPanel == nil)
{
_sharedInfoPanel = [NSSystemInfoPanel alloc];
if(![NSBundle loadNibNamed:@"NSSystemInfoPanel" owner:_sharedInfoPanel])
NSLog(@"Cannot load NSSystemInfoPanel.nib");
}
return _sharedInfoPanel;
}
- (void)awakeFromNib
{
NSImage *icon = [NSImage imageNamed:[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleIconFile"]];
if (icon != nil)
[appIconView setImage:icon];
[appNameField setStringValue:[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleName"]];
[versionField setStringValue:[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"]];
NSRect frame = [infoPanel frame];
NSString *resourceFileName = [[NSBundle mainBundle] pathForResource:@"Credits" ofType:@"rtf"];
if (resourceFileName != nil)
{
frame.size.height += 90;
[creditView readRTFDFromFile:resourceFileName];
}
else
[creditScrollView setFrame:NSMakeRect(0, 0, 0, 0)];
resourceFileName = [[NSBundle mainBundle] pathForResource:@"InfoPlist" ofType:@"strings"];
if (resourceFileName != nil)
{
NSData *data = [NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"InfoPlist" ofType:@"strings"]];
char *p, *q, *r, *s = calloc(1, [data length]+1);
[data getBytes:s];
if ((p = strstr(s, "NSHumanReadableCopyright")) != NULL)
{
p += 24;
while (*p != '\0' && *p++ != '"');
q = p;
while (*q != '\0' && *q != '"')
q++;
*q = '\0';
[legalTextField setStringValue:[[[NSString alloc] initWithUTF8String:p] autorelease]];
}
free(s);
}
frame.origin.y = [[NSScreen mainScreen] frame].size.height - 150 - frame.size.height;
frame.origin.x = ([[NSScreen mainScreen] frame].size.width - frame.size.width)/2.0;
[infoPanel setFrame:frame display:NO];
}
- (IBAction)showInfoPanel:(id)sender
{
[infoPanel makeKeyAndOrderFront:sender];
}
@end

View File

@ -0,0 +1,27 @@
{
IBClasses = (
{CLASS = FirstResponder; LANGUAGE = ObjC; SUPERCLASS = NSObject; },
{
ACTIONS = {showInfoPanel = id; };
CLASS = NSSystemInfoPanel;
LANGUAGE = ObjC;
OUTLETS = {
appIconView = NSImageView;
appNameField = NSTextField;
creditScrollView = NSScrollView;
creditView = NSTextView;
infoPanel = NSPanel;
legalTextField = NSTextField;
versionField = NSTextField;
};
SUPERCLASS = NSObject;
},
{
CLASS = NSSystemInfoPanelIconView;
LANGUAGE = ObjC;
OUTLETS = {target = id; };
SUPERCLASS = NSView;
}
);
IBVersion = 1;
}

View File

@ -0,0 +1,35 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IBDocumentLocation</key>
<string>65 96 356 240 0 0 1024 746 </string>
<key>IBFramework Version</key>
<string>489.0</string>
<key>IBOldestOS</key>
<integer>3</integer>
<key>IBOpenObjects</key>
<array>
<integer>195</integer>
</array>
<key>IBSystem Version</key>
<string>8S165</string>
<key>IBUserGuides</key>
<dict>
<key>InfoPanel</key>
<dict>
<key>guideLocations</key>
<array/>
<key>guidesLocked</key>
<string>NO</string>
</dict>
<key>Window</key>
<dict>
<key>guideLocations</key>
<array/>
<key>guidesLocked</key>
<string>NO</string>
</dict>
</dict>
</dict>
</plist>

Binary file not shown.

View File

@ -1,4 +1,4 @@
/* Copyright (c) 2006-2007 Rolf Jansen
/* Copyright (c) 2006-2007 Dr. Rolf Jansen
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

View File

@ -12,23 +12,23 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
@interface NSCharacterSet : NSObject <NSCopying,NSMutableCopying,NSCoding>
+(NSCharacterSet *)characterSetWithBitmapRepresentation:(NSData *)data;
+(NSCharacterSet *)characterSetWithCharactersInString:(NSString *)string;
+(NSCharacterSet *)characterSetWithContentsOfFile:(NSString *)path;
+(NSCharacterSet *)characterSetWithRange:(NSRange)range;
+characterSetWithBitmapRepresentation:(NSData *)data;
+characterSetWithCharactersInString:(NSString *)string;
+characterSetWithContentsOfFile:(NSString *)path;
+characterSetWithRange:(NSRange)range;
+(NSCharacterSet *)alphanumericCharacterSet;
+(NSCharacterSet *)controlCharacterSet;
+(NSCharacterSet *)decimalDigitCharacterSet;
+(NSCharacterSet *)decomposableCharacterSet;
+(NSCharacterSet *)illegalCharacterSet;
+(NSCharacterSet *)letterCharacterSet;
+(NSCharacterSet *)lowercaseLetterCharacterSet;
+(NSCharacterSet *)nonBaseCharacterSet;
+(NSCharacterSet *)punctuationCharacterSet;
+(NSCharacterSet *)uppercaseLetterCharacterSet;
+(NSCharacterSet *)whitespaceAndNewlineCharacterSet;
+(NSCharacterSet *)whitespaceCharacterSet;
+alphanumericCharacterSet;
+controlCharacterSet;
+decimalDigitCharacterSet;
+decomposableCharacterSet;
+illegalCharacterSet;
+letterCharacterSet;
+lowercaseLetterCharacterSet;
+nonBaseCharacterSet;
+punctuationCharacterSet;
+uppercaseLetterCharacterSet;
+whitespaceAndNewlineCharacterSet;
+whitespaceCharacterSet;
-(BOOL)characterIsMember:(unichar)character;
-(NSCharacterSet *)invertedSet;

View File

@ -25,8 +25,7 @@ static NSMapTable *nameToSet=NULL;
+(void)initialize {
if(self==[NSCharacterSet class]){
nameToSet=NSCreateMapTable(NSObjectMapKeyCallBacks,
NSObjectMapValueCallBacks,0);
nameToSet=NSCreateMapTable(NSObjectMapKeyCallBacks,NSObjectMapValueCallBacks,0);
}
}
@ -34,7 +33,6 @@ static NSMapTable *nameToSet=NULL;
return [self retain];
}
-mutableCopyWithZone:(NSZone *)zone {
return [[NSMutableCharacterSet_bitmap allocWithZone:NULL] initWithCharacterSet:self];
}
@ -53,15 +51,15 @@ static NSMapTable *nameToSet=NULL;
NSUnimplementedMethod();
}
+(NSCharacterSet *)characterSetWithBitmapRepresentation:(NSData *)data {
+characterSetWithBitmapRepresentation:(NSData *)data {
return NSAutorelease(NSCharacterSet_bitmapNewWithBitmap(NULL,data));
}
+(NSCharacterSet *)characterSetWithCharactersInString:(NSString *)string {
+characterSetWithCharactersInString:(NSString *)string {
return NSAutorelease([[NSCharacterSet_string allocWithZone:NULL] initWithString:string inverted:NO]);
}
+(NSCharacterSet *)characterSetWithContentsOfFile:(NSString *)path {
+characterSetWithContentsOfFile:(NSString *)path {
NSData *data=[NSData dataWithContentsOfFile:path];
if(data==nil)
@ -70,7 +68,7 @@ static NSMapTable *nameToSet=NULL;
return [self characterSetWithBitmapRepresentation:data];
}
+(NSCharacterSet *)characterSetWithRange:(NSRange)range {
+characterSetWithRange:(NSRange)range {
return NSAutorelease([[NSCharacterSet_range allocWithZone:NULL] initWithRange:range]);
}
@ -79,74 +77,74 @@ static NSString *pathForCharacterSet(NSString *name){
NSString *path=[bundle pathForResource:name ofType:@"bitmap"];
if(path==nil)
[NSException raise:@"NSCharacterSetFailedException"
format:@"NSCharacterSet unable to find bitmap for %@",name];
[NSException raise:@"NSCharacterSetFailedException" format:@"NSCharacterSet unable to find bitmap for %@",name];
return path;
}
static NSCharacterSet *sharedSetWithName(NSString *name){
NSCharacterSet *set;
static NSCharacterSet *sharedSetWithName(Class cls,NSString *name){
NSCharacterSet *result;
if((set=NSMapGet(nameToSet,name))==nil){
NSString *path=pathForCharacterSet(name);
if((set=[NSCharacterSet characterSetWithContentsOfFile:path])!=nil)
NSMapInsert(nameToSet,name,set);
if(cls!=[NSCharacterSet class])
result=[cls characterSetWithContentsOfFile:pathForCharacterSet(name)];
else {
if((result=NSMapGet(nameToSet,name))==nil){
if((result=[NSCharacterSet characterSetWithContentsOfFile:pathForCharacterSet(name)])!=nil)
NSMapInsert(nameToSet,name,result);
}
}
return set;
return result;
}
+(NSCharacterSet *)alphanumericCharacterSet {
return sharedSetWithName(@"alphanumericCharacterSet");
+alphanumericCharacterSet {
return sharedSetWithName(self,@"alphanumericCharacterSet");
}
+(NSCharacterSet *)controlCharacterSet {
return sharedSetWithName(@"controlCharacterSet");
+controlCharacterSet {
return sharedSetWithName(self,@"controlCharacterSet");
}
+(NSCharacterSet *)decimalDigitCharacterSet {
return sharedSetWithName(@"decimalDigitCharacterSet");
+decimalDigitCharacterSet {
return sharedSetWithName(self,@"decimalDigitCharacterSet");
}
+(NSCharacterSet *)decomposableCharacterSet {
return sharedSetWithName(@"decomposableCharacterSet");
+decomposableCharacterSet {
return sharedSetWithName(self,@"decomposableCharacterSet");
}
+(NSCharacterSet *)illegalCharacterSet {
return sharedSetWithName(@"illegalCharacterSet");
+illegalCharacterSet {
return sharedSetWithName(self,@"illegalCharacterSet");
}
+(NSCharacterSet *)letterCharacterSet {
return sharedSetWithName(@"letterCharacterSet");
+letterCharacterSet {
return sharedSetWithName(self,@"letterCharacterSet");
}
+(NSCharacterSet *)lowercaseLetterCharacterSet {
return sharedSetWithName(@"lowercaseLetterCharacterSet");
+lowercaseLetterCharacterSet {
return sharedSetWithName(self,@"lowercaseLetterCharacterSet");
}
+(NSCharacterSet *)nonBaseCharacterSet {
return sharedSetWithName(@"nonBaseCharacterSet");
+nonBaseCharacterSet {
return sharedSetWithName(self,@"nonBaseCharacterSet");
}
+(NSCharacterSet *)punctuationCharacterSet {
return sharedSetWithName(@"punctuationCharacterSet");
+punctuationCharacterSet {
return sharedSetWithName(self,@"punctuationCharacterSet");
}
+(NSCharacterSet *)uppercaseLetterCharacterSet {
return sharedSetWithName(@"uppercaseLetterCharacterSet");
+uppercaseLetterCharacterSet {
return sharedSetWithName(self,@"uppercaseLetterCharacterSet");
}
+(NSCharacterSet *)whitespaceAndNewlineCharacterSet {
return sharedSetWithName(@"whitespaceAndNewlineCharacterSet");
+whitespaceAndNewlineCharacterSet {
return sharedSetWithName(self,@"whitespaceAndNewlineCharacterSet");
}
+(NSCharacterSet *)whitespaceCharacterSet {
return sharedSetWithName(@"whitespaceCharacterSet");
+whitespaceCharacterSet {
return sharedSetWithName(self,@"whitespaceCharacterSet");
}
-(BOOL)characterIsMember:(unichar)character {
NSInvalidAbstractInvocation();
return NO;

View File

@ -9,6 +9,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
// Original - Christopher Lloyd <cjwl@objc.net>
#import <Foundation/NSMutableCharacterSet.h>
#import <Foundation/NSRaise.h>
#import "NSMutableCharacterSet_bitmap.h"
@implementation NSMutableCharacterSet
@ -19,6 +20,18 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
return NSAllocateObject(self,0,zone);
}
+characterSetWithBitmapRepresentation:(NSData *)data {
return [[[NSMutableCharacterSet_bitmap alloc] initWithData:data] autorelease];
}
+characterSetWithCharactersInString:(NSString *)string {
return [[[NSMutableCharacterSet_bitmap alloc] initWithString:string] autorelease];
}
+characterSetWithRange:(NSRange)range {
return [[[NSMutableCharacterSet_bitmap alloc] initWithRange:range] autorelease];
}
-(void)addCharactersInString:(NSString *)string {
NSInvalidAbstractInvocation();
}

View File

@ -15,5 +15,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
-initWithCharacterSet:(NSCharacterSet *)set;
-initWithData:(NSData *)data;
-initWithString:(NSString *)string;
-initWithRange:(NSRange)range;
@end

View File

@ -49,6 +49,27 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
return self;
}
-initWithString:(NSString *)string {
NSUInteger i,length=[string length];
unichar buffer[length];
[string getCharacters:buffer];
for(i=0;i<length;i++)
bitmapSet(_bitmap,buffer[i]);
return self;
}
-initWithRange:(NSRange)range {
NSUInteger i;
for(i=range.location;i<NSMaxRange(range);i++)
bitmapSet(_bitmap,i);
return self;
}
-(void)addCharactersInString:(NSString *)string {
unsigned i,length=[string length];
unichar unicode[length];