Proprtylist extensions and coding for DO improvements plus a couple of

bugfixes


git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@3492 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
richard 1998-12-18 17:05:44 +00:00
parent 06f5ba6dc4
commit fcf610c797
17 changed files with 567 additions and 574 deletions

View file

@ -1,3 +1,22 @@
Fri Dec 18 18:15:00 1998 Richard Frith-Macdonald <richard@brainstorm.co.uk>
Foundation.h: Added NSPathUtilities.h
NSObject.h: Added GNUstep specific methods for describing a
property-list to a stream.
NSDate.h: Moved natural language methods to right place.
NSObject.m: Added GNUstep specific extensions for describing a
property-list to a stream, updated -description to spec.
NSProxy.m: Tidied format and description method.
NSArray.m: Added GNUstep specific extensions for describing a
property-list to a stream.
NSDictionary.m: ditto
NSAttributedString.m: Tidied ([-replacementObjectForPortCoder:])
NSGAttributedString.m: ditto
NSGCString.m: ditto
NSGString.m: ditto
NSString.m: ditto
NSConcreteNumber.m: Added ([-replacementObjectForPortCoder:])
Thu Dec 17 16:12:18 1998 Matthias Klose <doko@cs.tu-berlin.de> Thu Dec 17 16:12:18 1998 Matthias Klose <doko@cs.tu-berlin.de>
* {,*}/GNUmakefile: Include Version and GNUmakefile.local where * {,*}/GNUmakefile: Include Version and GNUmakefile.local where

View file

@ -60,6 +60,7 @@
#include <Foundation/NSMethodSignature.h> #include <Foundation/NSMethodSignature.h>
#include <Foundation/NSNotification.h> #include <Foundation/NSNotification.h>
#include <Foundation/NSNotificationQueue.h> #include <Foundation/NSNotificationQueue.h>
#include <Foundation/NSPathUtilities.h>
#include <Foundation/NSPortCoder.h> #include <Foundation/NSPortCoder.h>
#include <Foundation/NSPortMessage.h> #include <Foundation/NSPortMessage.h>
#include <Foundation/NSPortNameServer.h> #include <Foundation/NSPortNameServer.h>

View file

@ -94,6 +94,7 @@
indent: (unsigned int)level; indent: (unsigned int)level;
- (BOOL) writeToFile: (NSString*)path atomically: (BOOL)useAuxilliaryFile; - (BOOL) writeToFile: (NSString*)path atomically: (BOOL)useAuxilliaryFile;
@end @end

View file

@ -88,6 +88,13 @@ typedef double NSTimeInterval;
- (BOOL) isEqualToDate: (NSDate*)otherDate; - (BOOL) isEqualToDate: (NSDate*)otherDate;
- (NSDate*) laterDate: (NSDate*)otherDate; - (NSDate*) laterDate: (NSDate*)otherDate;
#ifndef STRICT_OPENSTEP
+ (id) dateWithNaturalLanguageString: (NSString *)string;
+ (id) dateWithNaturalLanguageString: (NSString *)string
locale: (NSDictionary *)localeDictionary;
- (id) initWithTimeIntervalSince1970: (NSTimeInterval)seconds;
#endif
@end @end
@ -112,13 +119,6 @@ typedef double NSTimeInterval;
+ (NSArray *)timeZoneArray; + (NSArray *)timeZoneArray;
- (NSArray *)timeZoneDetailArray; - (NSArray *)timeZoneDetailArray;
#ifndef STRICT_OPENSTEP
+ (id) dateWithNaturalLanguageString: (NSString *)string;
+ (id) dateWithNaturalLanguageString: (NSString *)string
locale: (NSDictionary *)localeDictionary;
- (id) initWithTimeIntervalSince1970: (NSTimeInterval)seconds;
#endif
#ifndef NO_GNUSTEP #ifndef NO_GNUSTEP
/* Returns an dictionary that maps abbreviations to the array /* Returns an dictionary that maps abbreviations to the array
containing all the time zone names that use the abbreviation. */ containing all the time zone names that use the abbreviation. */

View file

@ -43,8 +43,10 @@
@class NSArchiver; @class NSArchiver;
@class NSArray; @class NSArray;
@class NSCoder; @class NSCoder;
@class NSDictionary;
@class NSPortCoder; @class NSPortCoder;
@class NSMethodSignature; @class NSMethodSignature;
@class NSMutableString;
@class NSRecursiveLock; @class NSRecursiveLock;
@class NSString; @class NSString;
@class NSInvocation; @class NSInvocation;
@ -162,8 +164,24 @@ enum {NSNotFound = 0x7fffffff};
creating the potential for deadlock. */ creating the potential for deadlock. */
extern NSRecursiveLock *gnustep_global_lock; extern NSRecursiveLock *gnustep_global_lock;
/*
* The GNUDescriptionDestination protocol declares a single method used
* to append a property-list description string to some output destination
* so that property-lists can be converted to strings in a stream avoiding
* the use of ridiculous amounts of memory for deeply nested data structures.
*/
@protocol GNUDescriptionDestination
- (void) appendString: (NSString*)str;
@end
@interface NSObject (GNU) @interface NSObject (GNU)
- (int) compare: anObject; - (int) compare: anObject;
- (void) descriptionTo: (id<GNUDescriptionDestination>)output;
- (void) descriptionWithLocale: (NSDictionary*)aLocale
to: (id<GNUDescriptionDestination>)output;
- (void) descriptionWithLocale: (NSDictionary*)aLocale
indent: (unsigned)level
to: (id<GNUDescriptionDestination>)output;
- (Class)transmuteClassTo:(Class)aClassObject; - (Class)transmuteClassTo:(Class)aClassObject;
- subclassResponsibility:(SEL)aSel; - subclassResponsibility:(SEL)aSel;
- shouldNotImplement:(SEL)aSel; - shouldNotImplement:(SEL)aSel;

View file

@ -36,20 +36,21 @@
unsigned int _retain_count; unsigned int _retain_count;
} }
+ alloc; + (id) alloc;
+ allocWithZone: (NSZone*)zone; + (id) allocWithZone: (NSZone*)zone;
+ (Class) class; + (Class) class;
+ (void) load; + (void) load;
+ (BOOL) respondsToSelector: (SEL)aSelector; + (BOOL) respondsToSelector: (SEL)aSelector;
- (void) dealloc; - (void) dealloc;
- (NSString*) description;
- (void) forwardInvocation: (NSInvocation*)anInvocation; - (void) forwardInvocation: (NSInvocation*)anInvocation;
- methodSignatureForSelector: (SEL)aSelector; - (NSMethodSignature*) methodSignatureForSelector: (SEL)aSelector;
@end @end
@interface NSProxy(GNUstepExtensions) @interface NSProxy(GNUstepExtensions)
- forward: (SEL)aSel :(arglist_t)frame; - (id) forward: (SEL)aSel :(arglist_t)frame;
@end @end
@interface Object (IsProxy) @interface Object (IsProxy)

View file

@ -265,7 +265,6 @@ enum {
#ifndef NO_GNUSTEP #ifndef NO_GNUSTEP
- (BOOL) boolValue; - (BOOL) boolValue;
- (NSString*) descriptionForPropertyList;
- (id) initWithCharactersNoCopy: (unichar*)chars - (id) initWithCharactersNoCopy: (unichar*)chars
length: (unsigned int)length length: (unsigned int)length
fromZone: (NSZone*)zone; fromZone: (NSZone*)zone;

View file

@ -37,6 +37,8 @@
#include <Foundation/NSException.h> #include <Foundation/NSException.h>
#include <Foundation/NSAutoreleasePool.h> #include <Foundation/NSAutoreleasePool.h>
#include <gnustep/base/fast.x>
@class NSArrayEnumerator; @class NSArrayEnumerator;
@class NSArrayEnumeratorReverse; @class NSArrayEnumeratorReverse;
@ -604,112 +606,89 @@ static Class NSMutableArray_concrete_class;
indent: (unsigned int)level indent: (unsigned int)level
{ {
NSMutableString *result; NSMutableString *result;
unsigned size;
unsigned indentSize; result = [NSMutableString stringWithCapacity: 20*[self count]];
unsigned indentBase; [self descriptionWithLocale: locale
NSMutableString *iBaseString; indent: level
NSMutableString *iSizeString; to: (id<GNUDescriptionDestination>)result];
NSAutoreleasePool *arp = [NSAutoreleasePool new]; return result;
}
static NSString *indentStrings[] = {
@"",
@" ",
@"\t",
@"\t ",
@"\t\t",
@"\t\t ",
@"\t\t\t",
@"\t\t\t ",
@"\t\t\t\t",
@"\t\t\t\t ",
@"\t\t\t\t\t",
@"\t\t\t\t\t ",
@"\t\t\t\t\t\t"
};
- (void) descriptionWithLocale: (NSDictionary*)locale
indent: (unsigned int)level
to: (id<GNUDescriptionDestination>)result
{
NSString *iBaseString;
NSString *iSizeString;
unsigned count = [self count]; unsigned count = [self count];
NSString *plists[count]; NSString *plists[count];
unsigned i; unsigned i;
SEL appSel;
IMP appImp;
appSel = @selector(appendString:);
appImp = [(NSObject*)result methodForSelector: appSel];
if (level < sizeof(indentStrings)/sizeof(NSString*))
iBaseString = indentStrings[level];
else
iBaseString = indentStrings[sizeof(indentStrings)/sizeof(NSString*)-1];
level++;
if (level < sizeof(indentStrings)/sizeof(NSString*))
iSizeString = indentStrings[level];
else
iSizeString = indentStrings[sizeof(indentStrings)/sizeof(NSString*)-1];
(*appImp)(result, appSel, @"(\n");
[self getObjects: plists]; [self getObjects: plists];
for (i = 0; i < count; i++)
{
id item = plists[i];
/* (*appImp)(result, appSel, iSizeString);
* Indentation is at four space intervals using tab characters to
* replace multiples of eight spaces.
*
* We work out the sizes of the strings needed to perform indentation for
* this level and build strings to make up the indentation.
*/
indentBase = level << 2;
count = indentBase >> 3;
if ((indentBase % 8) == 0) {
indentBase = count;
}
else {
indentBase == count + 4;
}
iBaseString = [NSMutableString stringWithCapacity: indentBase];
for (i = 0; i < count; i++) {
[iBaseString appendString: @"\t"];
}
if (count != indentBase) {
[iBaseString appendString: @" "];
}
level++; if ([item respondsToSelector:
indentSize = level << 2; @selector(descriptionWithLocale:indent:)])
count = indentSize >> 3; {
if ((indentSize % 8) == 0) { [item descriptionWithLocale: locale indent: level to: result];
indentSize = count;
}
else {
indentSize == count + 4;
}
iSizeString = [NSMutableString stringWithCapacity: indentSize];
for (i = 0; i < count; i++) {
[iSizeString appendString: @"\t"];
}
if (count != indentSize) {
[iSizeString appendString: @" "];
}
/*
* Basic size is - opening bracket, newline, closing bracket,
* indentation for the closing bracket, and a nul terminator.
*/
size = 4 + indentBase;
count = [self count];
for (i = 0; i < count; i++) {
id item;
item = plists[i];
if ([item isKindOfClass: [NSString class]]) {
item = [item descriptionForPropertyList];
} }
else if ([item respondsToSelector: else if ([item respondsToSelector:
@selector(descriptionWithLocale:indent:)]) { @selector(descriptionWithLocale:)])
item = [item descriptionWithLocale: locale indent: level]; {
[item descriptionWithLocale: locale to: result];
} }
else if ([item respondsToSelector: else
@selector(descriptionWithLocale:)]) { {
item = [item descriptionWithLocale: locale]; [item descriptionTo: result];
} }
else { if (i == count - 1)
item = [item description]; {
(*appImp)(result, appSel, @"\n");
} }
plists[i] = item; else
{
size += [item length] + indentSize; (*appImp)(result, appSel, @",\n");
if (i == count - 1) {
size += 1; /* newline */
}
else {
size += 2; /* ',' and newline */
} }
} }
(*appImp)(result, appSel, iBaseString);
result = [[NSMutableString alloc] initWithCapacity: size]; (*appImp)(result, appSel, @")");
[result appendString: @"(\n"];
for (i = 0; i < count; i++) {
[result appendString: iSizeString];
[result appendString: plists[i]];
if (i == count - 1) {
[result appendString: @"\n"];
}
else {
[result appendString: @",\n"];
}
}
[result appendString: iBaseString];
[result appendString: @")"];
[arp release];
return [result autorelease];
} }
@end @end

View file

@ -49,6 +49,7 @@
#include <Foundation/NSGAttributedString.h> #include <Foundation/NSGAttributedString.h>
#include <Foundation/NSException.h> #include <Foundation/NSException.h>
#include <Foundation/NSAutoreleasePool.h> #include <Foundation/NSAutoreleasePool.h>
#include <Foundation/NSPortCoder.h>
@implementation NSAttributedString @implementation NSAttributedString
@ -113,9 +114,12 @@ static Class NSMutableAttributedString_concrete_class;
{ {
return [self class]; return [self class];
} }
- replacementObjectForPortCoder:(NSPortCoder*)aCoder
- (id) replacementObjectForPortCoder: (NSPortCoder*)aCoder
{ {
if ([aCoder isByref] == NO)
return self; return self;
return [super replacementObjectForPortCoder: aCoder];
} }
//NSCopying protocol //NSCopying protocol

View file

@ -28,6 +28,7 @@
#include <Foundation/NSString.h> #include <Foundation/NSString.h>
#include <Foundation/NSException.h> #include <Foundation/NSException.h>
#include <Foundation/NSCoder.h> #include <Foundation/NSCoder.h>
#include <Foundation/NSPortCoder.h>
#include <gnustep/base/Coder.h> #include <gnustep/base/Coder.h>
/* This file should be run through a preprocessor with the macro TYPE_ORDER /* This file should be run through a preprocessor with the macro TYPE_ORDER
@ -336,6 +337,13 @@
return [self class]; return [self class];
} }
- (id) replacementObjectForPortCoder: (NSPortCoder*)aCoder
{
if ([aCoder isByref] == NO)
return self;
return [super replacementObjectForPortCoder: aCoder];
}
- (void) encodeWithCoder: coder - (void) encodeWithCoder: coder
{ {
const char *type = [self objCType]; const char *type = [self objCType];

View file

@ -527,69 +527,27 @@ compareIt(id o1, id o2, void* context)
- (NSString*) descriptionInStringsFileFormat - (NSString*) descriptionInStringsFileFormat
{ {
NSMutableString *result; NSMutableString *result = [NSMutableString stringWithCapacity: 1024];
int size; NSEnumerator *enumerator;
int i;
NSAutoreleasePool *arp = [NSAutoreleasePool new];
NSArray *keysArray = [self allKeys];
int numKeys = [keysArray count];
NSString *plists[numKeys];
NSString *keys[numKeys];
[keysArray getObjects: keys];
size = 1;
for (i = 0; i < numKeys; i++) {
NSString *newKey;
id key; id key;
id item;
key = keys[i]; enumerator = [self keyEnumerator];
item = [self objectForKey: key]; while ((key = [enumerator nextObject]) != nil)
if ([key respondsToSelector: @selector(descriptionForPropertyList)]) { {
newKey = [key descriptionForPropertyList]; id val = [self objectForKey: key];
}
else {
newKey = [key description];
}
keys[i] = newKey;
if (item == nil) { [key descriptionWithLocale: nil
item = @""; to: (id<GNUDescriptionDestination>)result];
} if (val != nil && [val isEqualToString: @""] == NO)
else if ([item isKindOfClass: [NSString class]]) { {
item = [item descriptionForPropertyList];
}
else {
item = [item description];
}
plists[i] = item;
size += [newKey length] + [item length];
if ([item length]) {
size += 5;
}
else {
size += 2;
}
}
result = [[NSMutableString alloc] initWithCapacity: size];
for (i = 0; i < numKeys; i++) {
NSString* item = plists[i];
[result appendString: keys[i]];
if ([item length]) {
[result appendString: @" = "]; [result appendString: @" = "];
[result appendString: item]; [val descriptionWithLocale: nil
to: (id<GNUDescriptionDestination>)result];
} }
[result appendString: @";\n"]; [result appendString: @";\n"];
} }
[arp release]; return result;
return [result autorelease];
} }
- (NSString*) descriptionWithLocale: (NSDictionary*)locale - (NSString*) descriptionWithLocale: (NSDictionary*)locale
@ -601,141 +559,112 @@ compareIt(id o1, id o2, void* context)
indent: (unsigned int)level indent: (unsigned int)level
{ {
NSMutableString *result; NSMutableString *result;
result = [NSMutableString stringWithCapacity: 20*[self count]];
[self descriptionWithLocale: locale
indent: level
to: (id<GNUDescriptionDestination>)result];
return result;
}
static NSString *indentStrings[] = {
@"",
@" ",
@"\t",
@"\t ",
@"\t\t",
@"\t\t ",
@"\t\t\t",
@"\t\t\t ",
@"\t\t\t\t",
@"\t\t\t\t ",
@"\t\t\t\t\t",
@"\t\t\t\t\t ",
@"\t\t\t\t\t\t"
};
- (void) descriptionWithLocale: (NSDictionary*)locale
indent: (unsigned int)level
to: (id<GNUDescriptionDestination>)result
{
NSEnumerator *enumerator; NSEnumerator *enumerator;
id key; id key;
BOOL canCompare = YES; BOOL canCompare = YES;
int count; NSString *iBaseString;
int size; NSString *iSizeString;
int indentSize;
int indentBase;
NSMutableString *iBaseString;
NSMutableString *iSizeString;
int i; int i;
NSAutoreleasePool *arp = [NSAutoreleasePool new];
NSArray *keyArray = [self allKeys]; NSArray *keyArray = [self allKeys];
NSMutableArray *theKeys = [NSMutableArray arrayWithArray: keyArray]; NSMutableArray *theKeys = [NSMutableArray arrayWithArray: keyArray];
int numKeys = [theKeys count]; int numKeys = [theKeys count];
NSString *plists[numKeys]; NSString *plists[numKeys];
NSString *keys[numKeys]; NSString *keys[numKeys];
SEL appSel;
IMP appImp;
/* appSel = @selector(appendString:);
* Indentation is at four space intervals using tab characters to appImp = [(NSObject*)result methodForSelector: appSel];
* replace multiples of eight spaces.
*
* We work out the sizes of the strings needed to perform indentation for
* this level and build strings to make up the indentation.
*/
indentBase = level << 2;
count = indentBase >> 3;
if ((indentBase % 8) == 0) {
indentBase = count;
}
else {
indentBase == count + 4;
}
iBaseString = [NSMutableString stringWithCapacity: indentBase];
for (i = 0; i < count; i++) {
[iBaseString appendString: @"\t"];
}
if (count != indentBase) {
[iBaseString appendString: @" "];
}
if (level < sizeof(indentStrings)/sizeof(NSString*))
iBaseString = indentStrings[level];
else
iBaseString = indentStrings[sizeof(indentStrings)/sizeof(NSString*)-1];
level++; level++;
indentSize = level << 2; if (level < sizeof(indentStrings)/sizeof(NSString*))
count = indentSize >> 3; iSizeString = indentStrings[level];
if ((indentSize % 8) == 0) { else
indentSize = count; iSizeString = indentStrings[sizeof(indentStrings)/sizeof(NSString*)-1];
}
else {
indentSize == count + 4;
}
iSizeString = [NSMutableString stringWithCapacity: indentSize];
for (i = 0; i < count; i++) {
[iSizeString appendString: @"\t"];
}
if (count != indentSize) {
[iSizeString appendString: @" "];
}
/*
* Basic size is - opening bracket, newline, closing bracket,
* indentation for the closing bracket, and a nul terminator.
*/
size = 4 + indentBase;
enumerator = [self keyEnumerator]; enumerator = [self keyEnumerator];
while ((key = [enumerator nextObject]) != nil) { while ((key = [enumerator nextObject]) != nil)
if ([key respondsToSelector: @selector(compare:)] == NO) { {
if ([key respondsToSelector: @selector(compare:)] == NO)
{
canCompare = NO; canCompare = NO;
break; break;
} }
} }
if (canCompare) { if (canCompare)
{
[theKeys sortUsingSelector: @selector(compare:)]; [theKeys sortUsingSelector: @selector(compare:)];
} }
[theKeys getObjects: keys]; [theKeys getObjects: keys];
for (i = 0; i < numKeys; i++) { for (i = 0; i < numKeys; i++)
NSString *newKey; {
id item; plists[i] = [self objectForKey: keys[i]];
key = keys[i];
item = [self objectForKey: key];
if ([key respondsToSelector: @selector(descriptionForPropertyList)]) {
newKey = [key descriptionForPropertyList];
} }
else {
newKey = [key description];
}
keys[i] = newKey;
if ([item isKindOfClass: [NSString class]]) { (*appImp)(result, appSel, @"{\n");
item = [item descriptionForPropertyList]; for (i = 0; i < numKeys; i++)
{
id item = plists[i];
(*appImp)(result, appSel, iSizeString);
[keys[i] descriptionTo: result];
(*appImp)(result, appSel, @" = ");
if ([item respondsToSelector:
@selector(descriptionWithLocale:indent:)])
{
[item descriptionWithLocale: locale indent: level to: result];
} }
else if ([item respondsToSelector: else if ([item respondsToSelector:
@selector(descriptionWithLocale:indent:)]) { @selector(descriptionWithLocale:)])
item = [item descriptionWithLocale: locale indent: level]; {
} [item descriptionWithLocale: locale to: result];
else if ([item respondsToSelector:
@selector(descriptionWithLocale:)]) {
item = [item descriptionWithLocale: locale];
}
else {
item = [item description];
}
plists[i] = item;
size += [newKey length] + [item length] + indentSize;
if (i == numKeys - 1) {
size += 4; /* ' = ' and newline */
}
else {
size += 5; /* ' = ' and ';' and newline */
} }
else
{
[item descriptionTo: result];
} }
result = [[NSMutableString alloc] initWithCapacity: size]; (*appImp)(result, appSel, @";\n");
[result appendString: @"{\n"];
for (i = 0; i < numKeys; i++) {
[result appendString: iSizeString];
[result appendString: keys[i]];
[result appendString: @" = "];
[result appendString: plists[i]];
if (i == numKeys - 1) {
[result appendString: @"\n"];
} }
else { (*appImp)(result, appSel, iBaseString);
[result appendString: @";\n"]; (*appImp)(result, appSel, @"}");
}
}
[result appendString: iBaseString];
[result appendString: @"}"];
[arp release];
return [result autorelease];
} }
@end @end

View file

@ -156,15 +156,6 @@ NSDictionary *_attributesAtIndexEffectiveRange(
return nil; return nil;
} }
- (Class) classForPortCoder
{
return [self class];
}
- replacementObjectForPortCoder:(NSPortCoder*)aCoder
{
return self;
}
- (void) encodeWithCoder: aCoder - (void) encodeWithCoder: aCoder
{ {
[super encodeWithCoder:aCoder]; [super encodeWithCoder:aCoder];
@ -221,15 +212,6 @@ NSDictionary *_attributesAtIndexEffectiveRange(
@implementation NSGMutableAttributedString @implementation NSGMutableAttributedString
- (Class) classForPortCoder
{
return [self class];
}
- replacementObjectForPortCoder:(NSPortCoder*)aCoder
{
return self;
}
- (void) encodeWithCoder: aCoder - (void) encodeWithCoder: aCoder
{ {
[super encodeWithCoder:aCoder]; [super encodeWithCoder:aCoder];

View file

@ -161,26 +161,6 @@ static IMP msInitImp; /* designated initialiser for mutable */
} }
} }
- (Class) classForArchiver
{
return [self class];
}
- (Class) classForCoder
{
return [self class];
}
- (Class) classForPortCoder
{
return [self class];
}
- replacementObjectForPortCoder:(NSPortCoder*)aCoder
{
return self;
}
- (void) encodeWithCoder: aCoder - (void) encodeWithCoder: aCoder
{ {
[aCoder encodeValueOfObjCType:@encode(unsigned) at:&_count]; [aCoder encodeValueOfObjCType:@encode(unsigned) at:&_count];
@ -511,23 +491,28 @@ static IMP msInitImp; /* designated initialiser for mutable */
return [self initWithCStringNoCopy: buf length: length fromZone: z]; return [self initWithCStringNoCopy: buf length: length fromZone: z];
} }
- (NSString*) descriptionForPropertyList - (void) descriptionTo: (NSMutableString*)output
{ {
if (_count == 0) { if (_count == 0)
return @"\"\""; {
[output appendString: @"\"\""];
} }
else { else
{
unsigned i; unsigned i;
unsigned length = _count; unsigned length = _count;
BOOL needQuote = NO; BOOL needQuote = NO;
for (i = 0; i < _count; i++) { for (i = 0; i < _count; i++)
{
char val = _contents_chars[i]; char val = _contents_chars[i];
if (isalnum(val)) { if (isalnum(val))
{
continue; continue;
} }
switch (val) { switch (val)
{
case '\a': case '\a':
case '\b': case '\b':
case '\t': case '\t':
@ -541,27 +526,32 @@ static IMP msInitImp; /* designated initialiser for mutable */
break; break;
default: default:
if (val == ' ' || isprint(val)) { if (val == ' ' || isprint(val))
{
needQuote = YES; needQuote = YES;
} }
else { else
{
length += 3; length += 3;
} }
break; break;
} }
} }
if (needQuote || length != _count) { if (needQuote || length != _count)
{
NSZone *z = fastZone(self); NSZone *z = fastZone(self);
char *buf = NSZoneMalloc(z, length+3); char *buf = NSZoneMalloc(z, length+3);
char *ptr = buf; char *ptr = buf;
NSString *result; NSString *result;
*ptr++ = '"'; *ptr++ = '"';
for (i = 0; i < _count; i++) { for (i = 0; i < _count; i++)
{
char val = _contents_chars[i]; char val = _contents_chars[i];
switch (val) { switch (val)
{
case '\a': *ptr++ = '\\'; *ptr++ = 'a'; break; case '\a': *ptr++ = '\\'; *ptr++ = 'a'; break;
case '\b': *ptr++ = '\\'; *ptr++ = 'b'; break; case '\b': *ptr++ = '\\'; *ptr++ = 'b'; break;
case '\t': *ptr++ = '\\'; *ptr++ = 't'; break; case '\t': *ptr++ = '\\'; *ptr++ = 't'; break;
@ -573,10 +563,12 @@ static IMP msInitImp; /* designated initialiser for mutable */
case '"' : *ptr++ = '\\'; *ptr++ = '"'; break; case '"' : *ptr++ = '\\'; *ptr++ = '"'; break;
default: default:
if (isprint(val) || val == ' ') { if (isprint(val) || val == ' ')
{
*ptr++ = val; *ptr++ = val;
} }
else { else
{
*ptr++ = '\\'; *ptr++ = '\\';
*ptr++ = '0'; *ptr++ = '0';
*ptr++ = ((val&0700)>>6)+'0'; *ptr++ = ((val&0700)>>6)+'0';
@ -588,11 +580,15 @@ static IMP msInitImp; /* designated initialiser for mutable */
} }
*ptr++ = '"'; *ptr++ = '"';
*ptr = '\0'; *ptr = '\0';
result = [[[_fastCls._NSGCString alloc] initWithCStringNoCopy: buf result = [[_fastCls._NSGCString alloc] initWithCStringNoCopy: buf
length: length+2 fromZone: z] autorelease]; length: length+2 fromZone: z];
return result; [output appendString: result];
[result release];
}
else
{
[output appendString: self];
} }
return self;
} }
} }
@end @end

View file

@ -303,17 +303,6 @@
} }
} }
- (Class) classForPortCoder
{
return [self class];
}
- replacementObjectForPortCoder:(NSPortCoder*)aCoder
{
return self;
}
// FOR IndexedCollection SUPPORT; // FOR IndexedCollection SUPPORT;
- objectAtIndex: (unsigned)index - objectAtIndex: (unsigned)index

View file

@ -33,6 +33,7 @@
#include <Foundation/NSAutoreleasePool.h> #include <Foundation/NSAutoreleasePool.h>
#include <Foundation/NSString.h> #include <Foundation/NSString.h>
#include <gnustep/base/o_map.h> #include <gnustep/base/o_map.h>
#include <Foundation/NSArray.h>
#include <Foundation/NSException.h> #include <Foundation/NSException.h>
#include <Foundation/NSPortCoder.h> #include <Foundation/NSPortCoder.h>
#include <Foundation/NSDistantObject.h> #include <Foundation/NSDistantObject.h>
@ -515,12 +516,31 @@ static BOOL double_release_check_enabled = NO;
- (NSString*) description - (NSString*) description
{ {
return [NSString stringWithCString: object_get_class_name(self)]; return [NSString stringWithFormat: @"<%s %lx>",
object_get_class_name(self), (unsigned long)self];
} }
+ (NSString*) description + (NSString*) description
{ {
return [NSString stringWithCString: class_get_class_name(self)]; return [NSString stringWithFormat: @"<%s>", object_get_class_name(self)];
}
- (void) descriptionTo: (id<GNUDescriptionDestination>)output
{
[output appendString: [self description]];
}
- (void) descriptionWithLocale: (NSDictionary*)aLocale
to: (id<GNUDescriptionDestination>)output
{
[output appendString: [(id)self descriptionWithLocale: aLocale]];
}
- (void) descriptionWithLocale: (NSDictionary*)aLocale
indent: (unsigned)level
to: (id<GNUDescriptionDestination>)output
{
[output appendString: [(id)self descriptionWithLocale: aLocale indent: level]];
} }
+ (void) poseAsClass: (Class)aClassObject + (void) poseAsClass: (Class)aClassObject

View file

@ -40,11 +40,11 @@
+ (id) allocWithZone: (NSZone*)z + (id) allocWithZone: (NSZone*)z
{ {
NSProxy* ob = (NSProxy*) NSAllocateObject (self, 0, z); NSProxy* ob = (NSProxy*) NSAllocateObject(self, 0, z);
return ob; return ob;
} }
+ autorelease + (id) autorelease
{ {
return self; return self;
} }
@ -59,6 +59,11 @@
/* Do nothing */ /* Do nothing */
} }
+ (NSString*) description
{
return [NSString stringWithFormat: @"<%s>", object_get_class_name(self)];
}
+ (BOOL) respondsToSelector: (SEL)aSelector + (BOOL) respondsToSelector: (SEL)aSelector
{ {
return (class_get_class_method(self, aSelector) != METHOD_NULL); return (class_get_class_method(self, aSelector) != METHOD_NULL);
@ -69,7 +74,7 @@
/* Do nothing */ /* Do nothing */
} }
+ retain + (id) retain
{ {
return self; return self;
} }
@ -79,7 +84,7 @@
return class_get_super_class (self); return class_get_super_class (self);
} }
- autorelease - (id) autorelease
{ {
[NSAutoreleasePool addObject:self]; [NSAutoreleasePool addObject:self];
return self; return self;
@ -93,8 +98,8 @@
#if 0 #if 0
- (BOOL) conformsToProtocol: (Protocol*)aProtocol - (BOOL) conformsToProtocol: (Protocol*)aProtocol
{ {
NSInvocation* inv; NSInvocation *inv;
NSMethodSignature* sig; NSMethodSignature *sig;
BOOL result; BOOL result;
sig = [self methodSignatureForSelector:@selector(conformsToProtocol:)]; sig = [self methodSignatureForSelector:@selector(conformsToProtocol:)];
@ -114,7 +119,8 @@
- (NSString*) description - (NSString*) description
{ {
return [NSString stringWithCString: object_get_class_name(self)]; return [NSString stringWithFormat: @"<%s %lx>",
object_get_class_name(self), (unsigned long)self];
} }
- (void) forwardInvocation: (NSInvocation*)anInvocation - (void) forwardInvocation: (NSInvocation*)anInvocation
@ -129,12 +135,12 @@
return (unsigned int)self; return (unsigned int)self;
} }
- init - (id) init
{ {
return self; return self;
} }
- (BOOL) isEqual: anObject - (BOOL) isEqual: (id)anObject
{ {
return (self == anObject); return (self == anObject);
} }
@ -143,8 +149,10 @@
{ {
Class class = self->isa; Class class = self->isa;
while (class != nil) { while (class != nil)
if (class == aClass) { {
if (class == aClass)
{
return YES; return YES;
} }
class = class_get_super_class(class); class = class_get_super_class(class);
@ -162,7 +170,7 @@
return YES; return YES;
} }
- notImplemented: (SEL)aSel - (id) notImplemented: (SEL)aSel
{ {
[NSException raise: NSGenericException [NSException raise: NSGenericException
format: @"NSProxy notImplemented %s", sel_get_name(aSel)]; format: @"NSProxy notImplemented %s", sel_get_name(aSel)];
@ -176,11 +184,12 @@
return nil; return nil;
} }
- performSelector: (SEL)aSelector - (id) performSelector: (SEL)aSelector
{ {
IMP msg = objc_msg_lookup(self, aSelector); IMP msg = objc_msg_lookup(self, aSelector);
if (!msg) { if (!msg)
{
[NSException raise: NSGenericException [NSException raise: NSGenericException
format: @"invalid selector passed to %s", format: @"invalid selector passed to %s",
sel_get_name(_cmd)]; sel_get_name(_cmd)];
@ -189,11 +198,13 @@
return (*msg)(self, aSelector); return (*msg)(self, aSelector);
} }
- performSelector: (SEL)aSelector withObject: anObject - (id) performSelector: (SEL)aSelector
withObject: (id)anObject
{ {
IMP msg = objc_msg_lookup(self, aSelector); IMP msg = objc_msg_lookup(self, aSelector);
if (!msg) { if (!msg)
{
[NSException raise: NSGenericException [NSException raise: NSGenericException
format: @"invalid selector passed to %s", format: @"invalid selector passed to %s",
sel_get_name(_cmd)]; sel_get_name(_cmd)];
@ -202,11 +213,14 @@
return (*msg)(self, aSelector, anObject); return (*msg)(self, aSelector, anObject);
} }
- performSelector: (SEL)aSelector withObject: anObject withObject: anotherObject - (id) performSelector: (SEL)aSelector
withObject: (id)anObject
withObject: (id)anotherObject
{ {
IMP msg = objc_msg_lookup(self, aSelector); IMP msg = objc_msg_lookup(self, aSelector);
if (!msg) { if (!msg)
{
[NSException raise: NSGenericException [NSException raise: NSGenericException
format: @"invalid selector passed to %s", format: @"invalid selector passed to %s",
sel_get_name(_cmd)]; sel_get_name(_cmd)];
@ -217,7 +231,8 @@
- (void) release - (void) release
{ {
if (_retain_count-- == 0) { if (_retain_count-- == 0)
{
[self dealloc]; [self dealloc];
} }
} }
@ -239,7 +254,7 @@
} }
#endif #endif
- retain - (id) retain
{ {
_retain_count++; _retain_count++;
return self; return self;
@ -255,7 +270,7 @@
return UINT_MAX; return UINT_MAX;
} }
- self - (id) self
{ {
return self; return self;
} }
@ -265,7 +280,7 @@
return object_get_super_class(self); return object_get_super_class(self);
} }
- (NSZone*)zone - (NSZone*) zone
{ {
return NSZoneFromPointer(self); return NSZoneFromPointer(self);
} }

View file

@ -50,6 +50,8 @@
#include <Foundation/NSDictionary.h> #include <Foundation/NSDictionary.h>
#include <Foundation/NSUserDefaults.h> #include <Foundation/NSUserDefaults.h>
#include <Foundation/NSFileManager.h> #include <Foundation/NSFileManager.h>
#include <Foundation/NSPortCoder.h>
#include <Foundation/NSPathUtilities.h>
#include <gnustep/base/IndexedCollection.h> #include <gnustep/base/IndexedCollection.h>
#include <Foundation/NSData.h> #include <Foundation/NSData.h>
@ -2588,7 +2590,6 @@ else
return ret; return ret;
} }
// #ifndef STRICT_OPENSTEP
+ (NSString*) pathWithComponents: (NSArray*)components + (NSString*) pathWithComponents: (NSArray*)components
{ {
NSString *s = [components objectAtIndex: 0]; NSString *s = [components objectAtIndex: 0];
@ -2677,27 +2678,33 @@ else
d = [self dataUsingEncoding: NSUnicodeStringEncoding]; d = [self dataUsingEncoding: NSUnicodeStringEncoding];
return [d writeToFile: filename atomically: useAuxiliaryFile]; return [d writeToFile: filename atomically: useAuxiliaryFile];
} }
// #endif
// #ifndef NO_GNUSTEP - (void) descriptionTo: (NSMutableString*)output
- (NSString*) descriptionForPropertyList
{ {
static NSCharacterSet *quotables = nil; static NSCharacterSet *quotables = nil;
if (quotables == nil) { if ([self length] == 0)
{
[output appendString: @"\"\""];
return;
}
if (quotables == nil)
{
quotables = [[NSCharacterSet alphanumericCharacterSet] invertedSet]; quotables = [[NSCharacterSet alphanumericCharacterSet] invertedSet];
[quotables retain]; [quotables retain];
} }
if ([self length] == 0 || if ([self rangeOfCharacterFromSet: quotables].length > 0)
[self rangeOfCharacterFromSet: quotables].length > 0) { {
const char *cstring = [self cString]; const char *cstring = [self cString];
const char *from; const char *from;
int len = 0; int len = 0;
for (from = cstring; *from; from++) { for (from = cstring; *from; from++)
switch (*from) { {
switch (*from)
{
case '\a': case '\a':
case '\b': case '\b':
case '\t': case '\t':
@ -2712,27 +2719,27 @@ else
break; break;
default: default:
if (isprint(*from) || *from == ' ') { if (isprint(*from) || *from == ' ')
{
len++; len++;
} }
else { else
{
len += 4; len += 4;
} }
break; break;
} }
} }
if (len == 0) { {
return @"\"\"";
}
else {
char buf[len+3]; char buf[len+3];
char *ptr = buf; char *ptr = buf;
NSString *result;
*ptr++ = '"'; *ptr++ = '"';
for (from = cstring; *from; from++) { for (from = cstring; *from; from++)
switch (*from) { {
switch (*from)
{
case '\a': *ptr++ = '\\'; *ptr++ = 'a'; break; case '\a': *ptr++ = '\\'; *ptr++ = 'a'; break;
case '\b': *ptr++ = '\\'; *ptr++ = 'b'; break; case '\b': *ptr++ = '\\'; *ptr++ = 'b'; break;
case '\t': *ptr++ = '\\'; *ptr++ = 't'; break; case '\t': *ptr++ = '\\'; *ptr++ = 't'; break;
@ -2745,10 +2752,12 @@ else
case '"' : *ptr++ = '\\'; *ptr++ = '"'; break; case '"' : *ptr++ = '\\'; *ptr++ = '"'; break;
default: default:
if (isprint(*from) || *from == ' ') { if (isprint(*from) || *from == ' ')
{
*ptr++ = *from; *ptr++ = *from;
} }
else { else
{
sprintf(ptr, "\\%03o", *(unsigned char*)from); sprintf(ptr, "\\%03o", *(unsigned char*)from);
ptr = &ptr[4]; ptr = &ptr[4];
} }
@ -2757,13 +2766,14 @@ else
} }
*ptr++ = '"'; *ptr++ = '"';
*ptr = '\0'; *ptr = '\0';
result = [NSString stringWithCString: buf]; [output appendString: [NSString stringWithCString: buf]];
return result;
} }
} }
return self; else
{
[output appendString: self];
}
} }
// #endif /* NO_GNUSTEP */
/* NSCopying Protocol */ /* NSCopying Protocol */
@ -2797,6 +2807,28 @@ else
return self; return self;
} }
- (Class) classForArchiver
{
return [self class];
}
- (Class) classForCoder
{
return [self class];
}
- (Class) classForPortCoder
{
return [self class];
}
- (id) replacementObjectForPortCoder: (NSPortCoder*)aCoder
{
if ([aCoder isByref] == NO)
return self;
return [super replacementObjectForPortCoder: aCoder];
}
@end @end