diff --git a/ChangeLog b/ChangeLog index 87d86e860..f4d58e37b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,22 @@ +Fri Dec 18 18:15:00 1998 Richard Frith-Macdonald + + 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 * {,*}/GNUmakefile: Include Version and GNUmakefile.local where diff --git a/Headers/gnustep/base/Foundation.h b/Headers/gnustep/base/Foundation.h index 5eefe1d84..c9084c40d 100644 --- a/Headers/gnustep/base/Foundation.h +++ b/Headers/gnustep/base/Foundation.h @@ -60,6 +60,7 @@ #include #include #include +#include #include #include #include diff --git a/Headers/gnustep/base/NSArray.h b/Headers/gnustep/base/NSArray.h index 3bfbbf83c..fa3c37b67 100644 --- a/Headers/gnustep/base/NSArray.h +++ b/Headers/gnustep/base/NSArray.h @@ -94,6 +94,7 @@ indent: (unsigned int)level; - (BOOL) writeToFile: (NSString*)path atomically: (BOOL)useAuxilliaryFile; + @end diff --git a/Headers/gnustep/base/NSDate.h b/Headers/gnustep/base/NSDate.h index 7400eb770..9f654cc9c 100644 --- a/Headers/gnustep/base/NSDate.h +++ b/Headers/gnustep/base/NSDate.h @@ -88,6 +88,13 @@ typedef double NSTimeInterval; - (BOOL) isEqualToDate: (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 @@ -112,13 +119,6 @@ typedef double NSTimeInterval; + (NSArray *)timeZoneArray; - (NSArray *)timeZoneDetailArray; -#ifndef STRICT_OPENSTEP -+ (id) dateWithNaturalLanguageString: (NSString *)string; -+ (id) dateWithNaturalLanguageString: (NSString *)string - locale: (NSDictionary *)localeDictionary; -- (id) initWithTimeIntervalSince1970: (NSTimeInterval)seconds; -#endif - #ifndef NO_GNUSTEP /* Returns an dictionary that maps abbreviations to the array containing all the time zone names that use the abbreviation. */ diff --git a/Headers/gnustep/base/NSObject.h b/Headers/gnustep/base/NSObject.h index ab57f1ad6..d6098a136 100644 --- a/Headers/gnustep/base/NSObject.h +++ b/Headers/gnustep/base/NSObject.h @@ -43,8 +43,10 @@ @class NSArchiver; @class NSArray; @class NSCoder; +@class NSDictionary; @class NSPortCoder; @class NSMethodSignature; +@class NSMutableString; @class NSRecursiveLock; @class NSString; @class NSInvocation; @@ -162,8 +164,24 @@ enum {NSNotFound = 0x7fffffff}; creating the potential for deadlock. */ 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) - (int) compare: anObject; +- (void) descriptionTo: (id)output; +- (void) descriptionWithLocale: (NSDictionary*)aLocale + to: (id)output; +- (void) descriptionWithLocale: (NSDictionary*)aLocale + indent: (unsigned)level + to: (id)output; - (Class)transmuteClassTo:(Class)aClassObject; - subclassResponsibility:(SEL)aSel; - shouldNotImplement:(SEL)aSel; diff --git a/Headers/gnustep/base/NSProxy.h b/Headers/gnustep/base/NSProxy.h index 29150cf24..40d253cc5 100644 --- a/Headers/gnustep/base/NSProxy.h +++ b/Headers/gnustep/base/NSProxy.h @@ -36,20 +36,21 @@ unsigned int _retain_count; } -+ alloc; -+ allocWithZone: (NSZone*)zone; ++ (id) alloc; ++ (id) allocWithZone: (NSZone*)zone; + (Class) class; + (void) load; + (BOOL) respondsToSelector: (SEL)aSelector; - (void) dealloc; +- (NSString*) description; - (void) forwardInvocation: (NSInvocation*)anInvocation; -- methodSignatureForSelector: (SEL)aSelector; +- (NSMethodSignature*) methodSignatureForSelector: (SEL)aSelector; @end @interface NSProxy(GNUstepExtensions) -- forward: (SEL)aSel :(arglist_t)frame; +- (id) forward: (SEL)aSel :(arglist_t)frame; @end @interface Object (IsProxy) diff --git a/Headers/gnustep/base/NSString.h b/Headers/gnustep/base/NSString.h index 254bfcbb5..9d1332cad 100644 --- a/Headers/gnustep/base/NSString.h +++ b/Headers/gnustep/base/NSString.h @@ -265,7 +265,6 @@ enum { #ifndef NO_GNUSTEP - (BOOL) boolValue; -- (NSString*) descriptionForPropertyList; - (id) initWithCharactersNoCopy: (unichar*)chars length: (unsigned int)length fromZone: (NSZone*)zone; diff --git a/Source/NSArray.m b/Source/NSArray.m index 65a66a110..5b2b01f04 100644 --- a/Source/NSArray.m +++ b/Source/NSArray.m @@ -37,6 +37,8 @@ #include #include +#include + @class NSArrayEnumerator; @class NSArrayEnumeratorReverse; @@ -603,113 +605,90 @@ static Class NSMutableArray_concrete_class; - (NSString*) descriptionWithLocale: (NSDictionary*)locale indent: (unsigned int)level { - NSMutableString *result; - unsigned size; - unsigned indentSize; - unsigned indentBase; - NSMutableString *iBaseString; - NSMutableString *iSizeString; - NSAutoreleasePool *arp = [NSAutoreleasePool new]; - unsigned count = [self count]; - NSString *plists[count]; - unsigned i; + NSMutableString *result; - [self getObjects: plists]; + result = [NSMutableString stringWithCapacity: 20*[self count]]; + [self descriptionWithLocale: locale + indent: level + to: (id)result]; + return result; +} - /* - * 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: @" "]; - } +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" +}; - level++; - indentSize = level << 2; - count = indentSize >> 3; - if ((indentSize % 8) == 0) { - indentSize = count; - } - else { - indentSize == count + 4; - } - iSizeString = [NSMutableString stringWithCapacity: indentSize]; - for (i = 0; i < count; i++) { - [iSizeString appendString: @"\t"]; - } - if (count != indentSize) { - [iSizeString appendString: @" "]; - } +- (void) descriptionWithLocale: (NSDictionary*)locale + indent: (unsigned int)level + to: (id)result +{ + NSString *iBaseString; + NSString *iSizeString; + unsigned count = [self count]; + NSString *plists[count]; + unsigned i; + SEL appSel; + IMP appImp; - /* - * Basic size is - opening bracket, newline, closing bracket, - * indentation for the closing bracket, and a nul terminator. - */ - size = 4 + indentBase; + appSel = @selector(appendString:); + appImp = [(NSObject*)result methodForSelector: appSel]; - count = [self count]; - for (i = 0; i < count; i++) { - id item; + 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]; - item = plists[i]; - if ([item isKindOfClass: [NSString class]]) { - item = [item descriptionForPropertyList]; + (*appImp)(result, appSel, @"(\n"); + + [self getObjects: plists]; + for (i = 0; i < count; i++) + { + id item = plists[i]; + + (*appImp)(result, appSel, iSizeString); + + if ([item respondsToSelector: + @selector(descriptionWithLocale:indent:)]) + { + [item descriptionWithLocale: locale indent: level to: result]; } - else if ([item respondsToSelector: - @selector(descriptionWithLocale:indent:)]) { - item = [item descriptionWithLocale: locale indent: level]; + else if ([item respondsToSelector: + @selector(descriptionWithLocale:)]) + { + [item descriptionWithLocale: locale to: result]; } - else if ([item respondsToSelector: - @selector(descriptionWithLocale:)]) { - item = [item descriptionWithLocale: locale]; + else + { + [item descriptionTo: result]; } - else { - item = [item description]; + if (i == count - 1) + { + (*appImp)(result, appSel, @"\n"); } - plists[i] = item; - - size += [item length] + indentSize; - if (i == count - 1) { - size += 1; /* newline */ - } - else { - size += 2; /* ',' and newline */ + else + { + (*appImp)(result, appSel, @",\n"); } } - - result = [[NSMutableString alloc] initWithCapacity: size]; - [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]; + (*appImp)(result, appSel, iBaseString); + (*appImp)(result, appSel, @")"); } @end diff --git a/Source/NSAttributedString.m b/Source/NSAttributedString.m index 8305dbb73..13bd07324 100644 --- a/Source/NSAttributedString.m +++ b/Source/NSAttributedString.m @@ -49,6 +49,7 @@ #include #include #include +#include @implementation NSAttributedString @@ -113,9 +114,12 @@ static Class NSMutableAttributedString_concrete_class; { return [self class]; } -- replacementObjectForPortCoder:(NSPortCoder*)aCoder + +- (id) replacementObjectForPortCoder: (NSPortCoder*)aCoder { + if ([aCoder isByref] == NO) return self; + return [super replacementObjectForPortCoder: aCoder]; } //NSCopying protocol diff --git a/Source/NSConcreteNumber.m b/Source/NSConcreteNumber.m index cd939d83d..419b9d661 100644 --- a/Source/NSConcreteNumber.m +++ b/Source/NSConcreteNumber.m @@ -28,6 +28,7 @@ #include #include #include +#include #include /* This file should be run through a preprocessor with the macro TYPE_ORDER @@ -336,6 +337,13 @@ return [self class]; } +- (id) replacementObjectForPortCoder: (NSPortCoder*)aCoder +{ + if ([aCoder isByref] == NO) + return self; + return [super replacementObjectForPortCoder: aCoder]; +} + - (void) encodeWithCoder: coder { const char *type = [self objCType]; diff --git a/Source/NSDictionary.m b/Source/NSDictionary.m index b64337370..42b13d864 100644 --- a/Source/NSDictionary.m +++ b/Source/NSDictionary.m @@ -527,215 +527,144 @@ compareIt(id o1, id o2, void* context) - (NSString*) descriptionInStringsFileFormat { - NSMutableString *result; - int size; - int i; - NSAutoreleasePool *arp = [NSAutoreleasePool new]; - NSArray *keysArray = [self allKeys]; - int numKeys = [keysArray count]; - NSString *plists[numKeys]; - NSString *keys[numKeys]; + NSMutableString *result = [NSMutableString stringWithCapacity: 1024]; + NSEnumerator *enumerator; + id key; - [keysArray getObjects: keys]; + enumerator = [self keyEnumerator]; + while ((key = [enumerator nextObject]) != nil) + { + id val = [self objectForKey: key]; - size = 1; - - for (i = 0; i < numKeys; i++) { - NSString *newKey; - id key; - id item; - - key = keys[i]; - item = [self objectForKey: key]; - if ([key respondsToSelector: @selector(descriptionForPropertyList)]) { - newKey = [key descriptionForPropertyList]; - } - else { - newKey = [key description]; - } - keys[i] = newKey; - - if (item == nil) { - item = @""; - } - 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; - } + [key descriptionWithLocale: nil + to: (id)result]; + if (val != nil && [val isEqualToString: @""] == NO) + { + [result appendString: @" = "]; + [val descriptionWithLocale: nil + to: (id)result]; + } + [result appendString: @";\n"]; } - 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: item]; - } - [result appendString: @";\n"]; - } - - [arp release]; - - return [result autorelease]; + return result; } - (NSString*) descriptionWithLocale: (NSDictionary*)locale { - return [self descriptionWithLocale: locale indent: 0]; + return [self descriptionWithLocale: locale indent: 0]; } - (NSString*) descriptionWithLocale: (NSDictionary*)locale indent: (unsigned int)level { - NSMutableString *result; - NSEnumerator *enumerator; - id key; - BOOL canCompare = YES; - int count; - int size; - int indentSize; - int indentBase; - NSMutableString *iBaseString; - NSMutableString *iSizeString; - int i; - NSAutoreleasePool *arp = [NSAutoreleasePool new]; - NSArray *keyArray = [self allKeys]; - NSMutableArray *theKeys = [NSMutableArray arrayWithArray: keyArray]; - int numKeys = [theKeys count]; - NSString *plists[numKeys]; - NSString *keys[numKeys]; + NSMutableString *result; - /* - * 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: @" "]; - } + result = [NSMutableString stringWithCapacity: 20*[self count]]; + [self descriptionWithLocale: locale + indent: level + to: (id)result]; + return result; +} - level++; - indentSize = level << 2; - count = indentSize >> 3; - if ((indentSize % 8) == 0) { - indentSize = count; - } - else { - indentSize == count + 4; - } - iSizeString = [NSMutableString stringWithCapacity: indentSize]; - for (i = 0; i < count; i++) { - [iSizeString appendString: @"\t"]; - } - if (count != indentSize) { - [iSizeString appendString: @" "]; - } +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" +}; - /* - * Basic size is - opening bracket, newline, closing bracket, - * indentation for the closing bracket, and a nul terminator. - */ - size = 4 + indentBase; +- (void) descriptionWithLocale: (NSDictionary*)locale + indent: (unsigned int)level + to: (id)result +{ + NSEnumerator *enumerator; + id key; + BOOL canCompare = YES; + NSString *iBaseString; + NSString *iSizeString; + int i; + NSArray *keyArray = [self allKeys]; + NSMutableArray *theKeys = [NSMutableArray arrayWithArray: keyArray]; + int numKeys = [theKeys count]; + NSString *plists[numKeys]; + NSString *keys[numKeys]; + SEL appSel; + IMP appImp; - enumerator = [self keyEnumerator]; - while ((key = [enumerator nextObject]) != nil) { - if ([key respondsToSelector: @selector(compare:)] == NO) { - canCompare = NO; - break; + 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]; + + enumerator = [self keyEnumerator]; + while ((key = [enumerator nextObject]) != nil) + { + if ([key respondsToSelector: @selector(compare:)] == NO) + { + canCompare = NO; + break; } } - if (canCompare) { - [theKeys sortUsingSelector: @selector(compare:)]; + if (canCompare) + { + [theKeys sortUsingSelector: @selector(compare:)]; } - [theKeys getObjects: keys]; - for (i = 0; i < numKeys; i++) { - NSString *newKey; - id item; - - 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]]) { - item = [item descriptionForPropertyList]; - } - else if ([item respondsToSelector: - @selector(descriptionWithLocale:indent:)]) { - item = [item descriptionWithLocale: locale indent: level]; - } - 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 */ - } + [theKeys getObjects: keys]; + for (i = 0; i < numKeys; i++) + { + plists[i] = [self objectForKey: keys[i]]; } - result = [[NSMutableString alloc] initWithCapacity: size]; - [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"]; + (*appImp)(result, appSel, @"{\n"); + 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 { - [result appendString: @";\n"]; + else if ([item respondsToSelector: + @selector(descriptionWithLocale:)]) + { + [item descriptionWithLocale: locale to: result]; } + else + { + [item descriptionTo: result]; + } + + (*appImp)(result, appSel, @";\n"); } - [result appendString: iBaseString]; - [result appendString: @"}"]; - - [arp release]; - - return [result autorelease]; + (*appImp)(result, appSel, iBaseString); + (*appImp)(result, appSel, @"}"); } @end diff --git a/Source/NSGAttributedString.m b/Source/NSGAttributedString.m index 4b7facdcd..99eb1270a 100644 --- a/Source/NSGAttributedString.m +++ b/Source/NSGAttributedString.m @@ -156,15 +156,6 @@ NSDictionary *_attributesAtIndexEffectiveRange( return nil; } -- (Class) classForPortCoder -{ - return [self class]; -} -- replacementObjectForPortCoder:(NSPortCoder*)aCoder -{ - return self; -} - - (void) encodeWithCoder: aCoder { [super encodeWithCoder:aCoder]; @@ -221,15 +212,6 @@ NSDictionary *_attributesAtIndexEffectiveRange( @implementation NSGMutableAttributedString -- (Class) classForPortCoder -{ - return [self class]; -} -- replacementObjectForPortCoder:(NSPortCoder*)aCoder -{ - return self; -} - - (void) encodeWithCoder: aCoder { [super encodeWithCoder:aCoder]; diff --git a/Source/NSGCString.m b/Source/NSGCString.m index 0def86ce0..2672783d6 100644 --- a/Source/NSGCString.m +++ b/Source/NSGCString.m @@ -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 { [aCoder encodeValueOfObjCType:@encode(unsigned) at:&_count]; @@ -511,88 +491,104 @@ static IMP msInitImp; /* designated initialiser for mutable */ return [self initWithCStringNoCopy: buf length: length fromZone: z]; } -- (NSString*) descriptionForPropertyList +- (void) descriptionTo: (NSMutableString*)output { - if (_count == 0) { - return @"\"\""; + if (_count == 0) + { + [output appendString: @"\"\""]; } - else { - unsigned i; - unsigned length = _count; - BOOL needQuote = NO; + else + { + unsigned i; + unsigned length = _count; + BOOL needQuote = NO; - for (i = 0; i < _count; i++) { - char val = _contents_chars[i]; + for (i = 0; i < _count; i++) + { + char val = _contents_chars[i]; - if (isalnum(val)) { - continue; + if (isalnum(val)) + { + continue; } - switch (val) { - case '\a': - case '\b': - case '\t': - case '\r': - case '\n': - case '\v': - case '\f': - case '\\': - case '"' : - length += 1; - break; + switch (val) + { + case '\a': + case '\b': + case '\t': + case '\r': + case '\n': + case '\v': + case '\f': + case '\\': + case '"' : + length += 1; + break; - default: - if (val == ' ' || isprint(val)) { - needQuote = YES; - } - else { - length += 3; - } - break; + default: + if (val == ' ' || isprint(val)) + { + needQuote = YES; + } + else + { + length += 3; + } + break; } } - if (needQuote || length != _count) { - NSZone *z = fastZone(self); - char *buf = NSZoneMalloc(z, length+3); - char *ptr = buf; - NSString *result; + if (needQuote || length != _count) + { + NSZone *z = fastZone(self); + char *buf = NSZoneMalloc(z, length+3); + char *ptr = buf; + NSString *result; - *ptr++ = '"'; - for (i = 0; i < _count; i++) { - char val = _contents_chars[i]; + *ptr++ = '"'; + for (i = 0; i < _count; i++) + { + char val = _contents_chars[i]; - switch (val) { - case '\a': *ptr++ = '\\'; *ptr++ = 'a'; break; - case '\b': *ptr++ = '\\'; *ptr++ = 'b'; break; - case '\t': *ptr++ = '\\'; *ptr++ = 't'; break; - case '\r': *ptr++ = '\\'; *ptr++ = 'r'; break; - case '\n': *ptr++ = '\\'; *ptr++ = 'n'; break; - case '\v': *ptr++ = '\\'; *ptr++ = 'v'; break; - case '\f': *ptr++ = '\\'; *ptr++ = 'f'; break; - case '\\': *ptr++ = '\\'; *ptr++ = '\\'; break; - case '"' : *ptr++ = '\\'; *ptr++ = '"'; break; + switch (val) + { + case '\a': *ptr++ = '\\'; *ptr++ = 'a'; break; + case '\b': *ptr++ = '\\'; *ptr++ = 'b'; break; + case '\t': *ptr++ = '\\'; *ptr++ = 't'; break; + case '\r': *ptr++ = '\\'; *ptr++ = 'r'; break; + case '\n': *ptr++ = '\\'; *ptr++ = 'n'; break; + case '\v': *ptr++ = '\\'; *ptr++ = 'v'; break; + case '\f': *ptr++ = '\\'; *ptr++ = 'f'; break; + case '\\': *ptr++ = '\\'; *ptr++ = '\\'; break; + case '"' : *ptr++ = '\\'; *ptr++ = '"'; break; - default: - if (isprint(val) || val == ' ') { - *ptr++ = val; - } - else { - *ptr++ = '\\'; - *ptr++ = '0'; - *ptr++ = ((val&0700)>>6)+'0'; - *ptr++ = ((val&070)>>3)+'0'; - *ptr++ = (val&07)+'0'; - } - break; + default: + if (isprint(val) || val == ' ') + { + *ptr++ = val; + } + else + { + *ptr++ = '\\'; + *ptr++ = '0'; + *ptr++ = ((val&0700)>>6)+'0'; + *ptr++ = ((val&070)>>3)+'0'; + *ptr++ = (val&07)+'0'; + } + break; } } - *ptr++ = '"'; - *ptr = '\0'; - result = [[[_fastCls._NSGCString alloc] initWithCStringNoCopy: buf - length: length+2 fromZone: z] autorelease]; - return result; + *ptr++ = '"'; + *ptr = '\0'; + result = [[_fastCls._NSGCString alloc] initWithCStringNoCopy: buf + length: length+2 fromZone: z]; + [output appendString: result]; + [result release]; + } + else + { + [output appendString: self]; } - return self; } } @end diff --git a/Source/NSGString.m b/Source/NSGString.m index 7d6fcbafc..786040bf5 100644 --- a/Source/NSGString.m +++ b/Source/NSGString.m @@ -303,17 +303,6 @@ } } -- (Class) classForPortCoder -{ - return [self class]; -} - -- replacementObjectForPortCoder:(NSPortCoder*)aCoder -{ - return self; -} - - // FOR IndexedCollection SUPPORT; - objectAtIndex: (unsigned)index diff --git a/Source/NSObject.m b/Source/NSObject.m index fa3711b1b..ae9e27013 100644 --- a/Source/NSObject.m +++ b/Source/NSObject.m @@ -33,6 +33,7 @@ #include #include #include +#include #include #include #include @@ -515,12 +516,31 @@ static BOOL double_release_check_enabled = NO; - (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 { - return [NSString stringWithCString: class_get_class_name(self)]; + return [NSString stringWithFormat: @"<%s>", object_get_class_name(self)]; +} + +- (void) descriptionTo: (id)output +{ + [output appendString: [self description]]; +} + +- (void) descriptionWithLocale: (NSDictionary*)aLocale + to: (id)output +{ + [output appendString: [(id)self descriptionWithLocale: aLocale]]; +} + +- (void) descriptionWithLocale: (NSDictionary*)aLocale + indent: (unsigned)level + to: (id)output +{ + [output appendString: [(id)self descriptionWithLocale: aLocale indent: level]]; } + (void) poseAsClass: (Class)aClassObject diff --git a/Source/NSProxy.m b/Source/NSProxy.m index ec90e8c2e..24df1e37e 100644 --- a/Source/NSProxy.m +++ b/Source/NSProxy.m @@ -35,43 +35,48 @@ + (id) alloc { - return [self allocWithZone: NSDefaultMallocZone()]; + return [self allocWithZone: NSDefaultMallocZone()]; } + (id) allocWithZone: (NSZone*)z { - NSProxy* ob = (NSProxy*) NSAllocateObject (self, 0, z); - return ob; + NSProxy* ob = (NSProxy*) NSAllocateObject(self, 0, z); + return ob; } -+ autorelease ++ (id) autorelease { - return self; + return self; } + (Class) class { - return self; + return self; } + (void) load { - /* Do nothing */ + /* Do nothing */ +} + ++ (NSString*) description +{ + return [NSString stringWithFormat: @"<%s>", object_get_class_name(self)]; } + (BOOL) respondsToSelector: (SEL)aSelector { - return (class_get_class_method(self, aSelector) != METHOD_NULL); + return (class_get_class_method(self, aSelector) != METHOD_NULL); } + (void) release { - /* Do nothing */ + /* Do nothing */ } -+ retain ++ (id) retain { - return self; + return self; } + (Class) superclass @@ -79,175 +84,185 @@ return class_get_super_class (self); } -- autorelease +- (id) autorelease { - [NSAutoreleasePool addObject:self]; - return self; + [NSAutoreleasePool addObject:self]; + return self; } - (Class) class { - return object_get_class(self); + return object_get_class(self); } #if 0 - (BOOL) conformsToProtocol: (Protocol*)aProtocol { - NSInvocation* inv; - NSMethodSignature* sig; - BOOL result; + NSInvocation *inv; + NSMethodSignature *sig; + BOOL result; - sig = [self methodSignatureForSelector:@selector(conformsToProtocol:)]; - inv = [NSInvocation invocationWithMethodSignature:sig]; - [inv setSelector:@selector(conformsToProtocol:)]; - [inv setArgument:aProtocol atIndex:2]; - [self forwardInvocation:inv]; - [inv getReturnValue: &result]; - return result; + sig = [self methodSignatureForSelector:@selector(conformsToProtocol:)]; + inv = [NSInvocation invocationWithMethodSignature:sig]; + [inv setSelector:@selector(conformsToProtocol:)]; + [inv setArgument:aProtocol atIndex:2]; + [self forwardInvocation:inv]; + [inv getReturnValue: &result]; + return result; } #endif - (void) dealloc { - NSDeallocateObject((NSObject*)self); + NSDeallocateObject((NSObject*)self); } - (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 { - [NSException raise: NSInvalidArgumentException - format: @"NSProxy should not implement '%s'", + [NSException raise: NSInvalidArgumentException + format: @"NSProxy should not implement '%s'", sel_get_name(_cmd)]; } - (unsigned int) hash { - 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); } - (BOOL) isKindOfClass: (Class)aClass { - Class class = self->isa; + Class class = self->isa; - while (class != nil) { - if (class == aClass) { - return YES; + while (class != nil) + { + if (class == aClass) + { + return YES; } - class = class_get_super_class(class); + class = class_get_super_class(class); } - return NO; + return NO; } - (BOOL) isMemberOfClass: (Class)aClass { - return(self->isa == aClass); + return(self->isa == aClass); } - (BOOL) isProxy { - return YES; + return YES; } -- notImplemented: (SEL)aSel +- (id) notImplemented: (SEL)aSel { - [NSException raise: NSGenericException - format: @"NSProxy notImplemented %s", sel_get_name(aSel)]; - return self; + [NSException raise: NSGenericException + format: @"NSProxy notImplemented %s", sel_get_name(aSel)]; + return self; } - (NSMethodSignature*) methodSignatureForSelector: (SEL)aSelector { - [NSException raise: NSInvalidArgumentException format: + [NSException raise: NSInvalidArgumentException format: @"NSProxy should not implement 'methodSignatureForSelector:'"]; - 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) { - [NSException raise: NSGenericException - format: @"invalid selector passed to %s", + if (!msg) + { + [NSException raise: NSGenericException + format: @"invalid selector passed to %s", sel_get_name(_cmd)]; - return nil; + return nil; } - 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) { - [NSException raise: NSGenericException - format: @"invalid selector passed to %s", + if (!msg) + { + [NSException raise: NSGenericException + format: @"invalid selector passed to %s", sel_get_name(_cmd)]; - return nil; + return nil; } - 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) { - [NSException raise: NSGenericException - format: @"invalid selector passed to %s", + if (!msg) + { + [NSException raise: NSGenericException + format: @"invalid selector passed to %s", sel_get_name(_cmd)]; - return nil; + return nil; } - return (*msg)(self, aSelector, anObject, anotherObject); + return (*msg)(self, aSelector, anObject, anotherObject); } - (void) release { - if (_retain_count-- == 0) { - [self dealloc]; + if (_retain_count-- == 0) + { + [self dealloc]; } } #if 0 - (BOOL) respondsToSelector: (SEL)aSelector { - NSInvocation* inv; - NSMethodSignature* sig; - BOOL result; + NSInvocation* inv; + NSMethodSignature* sig; + BOOL result; - sig = [self methodSignatureForSelector:@selector(respondsToSelector:)]; - inv = [NSInvocation invocationWithMethodSignature:sig]; - [inv setSelector:@selector(respondsToSelector:)]; - [inv setArgument:(void*)aSelector atIndex:2]; - [self forwardInvocation:inv]; - [inv getReturnValue: &result]; - return result; + sig = [self methodSignatureForSelector:@selector(respondsToSelector:)]; + inv = [NSInvocation invocationWithMethodSignature:sig]; + [inv setSelector:@selector(respondsToSelector:)]; + [inv setArgument:(void*)aSelector atIndex:2]; + [self forwardInvocation:inv]; + [inv getReturnValue: &result]; + return result; } #endif -- retain +- (id) retain { - _retain_count++; - return self; + _retain_count++; + return self; } - (unsigned int) retainCount { - return _retain_count + 1; + return _retain_count + 1; } + (unsigned) retainCount @@ -255,19 +270,19 @@ return UINT_MAX; } -- self +- (id) self { - return self; + return self; } - (Class) superclass { - return object_get_super_class(self); + return object_get_super_class(self); } -- (NSZone*)zone +- (NSZone*) zone { - return NSZoneFromPointer(self); + return NSZoneFromPointer(self); } @end diff --git a/Source/NSString.m b/Source/NSString.m index 1e63665f6..c50a803ca 100644 --- a/Source/NSString.m +++ b/Source/NSString.m @@ -50,6 +50,8 @@ #include #include #include +#include +#include #include #include @@ -2588,7 +2590,6 @@ else return ret; } -// #ifndef STRICT_OPENSTEP + (NSString*) pathWithComponents: (NSArray*)components { NSString *s = [components objectAtIndex: 0]; @@ -2677,93 +2678,102 @@ else d = [self dataUsingEncoding: NSUnicodeStringEncoding]; return [d writeToFile: filename atomically: useAuxiliaryFile]; } -// #endif -// #ifndef NO_GNUSTEP - -- (NSString*) descriptionForPropertyList +- (void) descriptionTo: (NSMutableString*)output { - static NSCharacterSet *quotables = nil; + static NSCharacterSet *quotables = nil; - if (quotables == nil) { - quotables = [[NSCharacterSet alphanumericCharacterSet] invertedSet]; - [quotables retain]; + if ([self length] == 0) + { + [output appendString: @"\"\""]; + return; } - if ([self length] == 0 || - [self rangeOfCharacterFromSet: quotables].length > 0) { - const char *cstring = [self cString]; - const char *from; - int len = 0; + if (quotables == nil) + { + quotables = [[NSCharacterSet alphanumericCharacterSet] invertedSet]; + [quotables retain]; + } - for (from = cstring; *from; from++) { - switch (*from) { - case '\a': - case '\b': - case '\t': - case '\r': - case '\n': - case '\v': - case '\f': - case '\\': - case '\'' : - case '"' : - len += 2; - break; + if ([self rangeOfCharacterFromSet: quotables].length > 0) + { + const char *cstring = [self cString]; + const char *from; + int len = 0; + + for (from = cstring; *from; from++) + { + switch (*from) + { + case '\a': + case '\b': + case '\t': + case '\r': + case '\n': + case '\v': + case '\f': + case '\\': + case '\'' : + case '"' : + len += 2; + break; + + default: + if (isprint(*from) || *from == ' ') + { + len++; + } + else + { + len += 4; + } + break; + } + } + + { + char buf[len+3]; + char *ptr = buf; + + *ptr++ = '"'; + for (from = cstring; *from; from++) + { + switch (*from) + { + case '\a': *ptr++ = '\\'; *ptr++ = 'a'; break; + case '\b': *ptr++ = '\\'; *ptr++ = 'b'; break; + case '\t': *ptr++ = '\\'; *ptr++ = 't'; break; + case '\r': *ptr++ = '\\'; *ptr++ = 'r'; break; + case '\n': *ptr++ = '\\'; *ptr++ = 'n'; break; + case '\v': *ptr++ = '\\'; *ptr++ = 'v'; break; + case '\f': *ptr++ = '\\'; *ptr++ = 'f'; break; + case '\\': *ptr++ = '\\'; *ptr++ = '\\'; break; + case '\'': *ptr++ = '\\'; *ptr++ = '\''; break; + case '"' : *ptr++ = '\\'; *ptr++ = '"'; break; default: - if (isprint(*from) || *from == ' ') { - len++; + if (isprint(*from) || *from == ' ') + { + *ptr++ = *from; } - else { - len += 4; + else + { + sprintf(ptr, "\\%03o", *(unsigned char*)from); + ptr = &ptr[4]; } - break; - } - } - - if (len == 0) { - return @"\"\""; - } - else { - char buf[len+3]; - char *ptr = buf; - NSString *result; - - *ptr++ = '"'; - for (from = cstring; *from; from++) { - switch (*from) { - case '\a': *ptr++ = '\\'; *ptr++ = 'a'; break; - case '\b': *ptr++ = '\\'; *ptr++ = 'b'; break; - case '\t': *ptr++ = '\\'; *ptr++ = 't'; break; - case '\r': *ptr++ = '\\'; *ptr++ = 'r'; break; - case '\n': *ptr++ = '\\'; *ptr++ = 'n'; break; - case '\v': *ptr++ = '\\'; *ptr++ = 'v'; break; - case '\f': *ptr++ = '\\'; *ptr++ = 'f'; break; - case '\\': *ptr++ = '\\'; *ptr++ = '\\'; break; - case '\'': *ptr++ = '\\'; *ptr++ = '\''; break; - case '"' : *ptr++ = '\\'; *ptr++ = '"'; break; - - default: - if (isprint(*from) || *from == ' ') { - *ptr++ = *from; - } - else { - sprintf(ptr, "\\%03o", *(unsigned char*)from); - ptr = &ptr[4]; - } - break; - } - } - *ptr++ = '"'; - *ptr = '\0'; - result = [NSString stringWithCString: buf]; - return result; - } + break; + } + } + *ptr++ = '"'; + *ptr = '\0'; + [output appendString: [NSString stringWithCString: buf]]; + } + } + else + { + [output appendString: self]; } - return self; } -// #endif /* NO_GNUSTEP */ /* NSCopying Protocol */ @@ -2797,6 +2807,28 @@ else 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