description tidyups

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@6297 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Richard Frith-MacDonald 2000-03-17 13:13:08 +00:00
parent 0781dc0250
commit 6978b88eed
14 changed files with 526 additions and 190 deletions

View file

@ -37,6 +37,7 @@
#include <Foundation/NSUtilities.h>
#include <Foundation/NSException.h>
#include <Foundation/NSAutoreleasePool.h>
#include <Foundation/NSUserDefaults.h>
#include <Foundation/NSDebug.h>
#include <base/fast.x>
@ -626,26 +627,35 @@ static SEL rlSel = @selector(removeLastObject);
GS_RANGE_CHECK(aRange, c);
if (aRange.length == 0)
return [NSArray array];
{
na = [NSArray array];
}
else
{
id objects[aRange.length];
{
id objects[aRange.length];
[self getObjects: objects range: aRange];
na = [NSArray arrayWithObjects: objects count: aRange.length];
}
[self getObjects: objects range: aRange];
na = [NSArray arrayWithObjects: objects count: aRange.length];
}
return na;
}
- (NSEnumerator*) objectEnumerator
{
return AUTORELEASE([[NSArrayEnumerator allocWithZone: NSDefaultMallocZone()]
initWithArray: self]);
id e;
e = [NSArrayEnumerator allocWithZone: NSDefaultMallocZone()];
e = [e initWithArray: self];
return AUTORELEASE(e);
}
- (NSEnumerator*) reverseObjectEnumerator
{
return AUTORELEASE([[NSArrayEnumeratorReverse allocWithZone: NSDefaultMallocZone()] initWithArray: self]);
id e;
e = [NSArrayEnumeratorReverse allocWithZone: NSDefaultMallocZone()];
e = [e initWithArray: self];
return AUTORELEASE(e);
}
- (NSString*) description
@ -663,7 +673,8 @@ static SEL rlSel = @selector(removeLastObject);
{
NSMutableString *result;
result = AUTORELEASE([[NSGMutableCString alloc] initWithCapacity: 20*[self count]]);
result = [[NSGMutableCString alloc] initWithCapacity: 20*[self count]];
result = AUTORELEASE(result);
[self descriptionWithLocale: locale
indent: level
to: (id<GNUDescriptionDestination>)result];
@ -690,64 +701,85 @@ static NSString *indentStrings[] = {
indent: (unsigned int)level
to: (id<GNUDescriptionDestination>)result
{
NSString *iBaseString;
NSString *iSizeString;
unsigned count = [self count];
unsigned last = count - 1;
NSString *plists[count];
unsigned i;
IMP appImp;
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];
for (i = 0; i < count; i++)
{
id item = plists[i];
(*appImp)(result, appSel, iSizeString);
if ([item respondsToSelector:
@selector(descriptionWithLocale:indent:)])
if (locale == nil)
{
(*appImp)(result, appSel, @"(");
for (i = 0; i < count; i++)
{
[item descriptionWithLocale: locale indent: level to: result];
}
else if ([item respondsToSelector:
@selector(descriptionWithLocale:)])
{
[item descriptionWithLocale: locale to: result];
}
else
{
[item descriptionTo: result];
}
if (i == count - 1)
{
(*appImp)(result, appSel, @"\n");
}
else
{
(*appImp)(result, appSel, @",\n");
id item = plists[i];
[item descriptionWithLocale: nil indent: 0 to: result];
if (i != last)
{
(*appImp)(result, appSel, @",");
}
}
(*appImp)(result, appSel, @")");
}
else
{
NSString *iBaseString;
NSString *iSizeString;
if (level < sizeof(indentStrings)/sizeof(id))
{
iBaseString = indentStrings[level];
}
else
{
iBaseString = indentStrings[sizeof(indentStrings)/sizeof(id)-1];
}
level++;
if (level < sizeof(indentStrings)/sizeof(id))
{
iSizeString = indentStrings[level];
}
else
{
iSizeString = indentStrings[sizeof(indentStrings)/sizeof(id)-1];
}
(*appImp)(result, appSel, @"(\n");
for (i = 0; i < count; i++)
{
id item = plists[i];
(*appImp)(result, appSel, iSizeString);
[item descriptionWithLocale: locale indent: level to: result];
if (i == last)
{
(*appImp)(result, appSel, @"\n");
}
else
{
(*appImp)(result, appSel, @",\n");
}
}
(*appImp)(result, appSel, iBaseString);
(*appImp)(result, appSel, @")");
}
(*appImp)(result, appSel, iBaseString);
(*appImp)(result, appSel, @")");
}
- (BOOL) writeToFile: (NSString *)path atomically: (BOOL)useAuxiliaryFile
{
return [[self description] writeToFile: path atomically: useAuxiliaryFile];
NSDictionary *loc;
NSString *desc;
loc = [[NSUserDefaults standardUserDefaults] dictionaryRepresentation];
desc = [self descriptionWithLocale: loc indent: 0];
return [desc writeToFile: path atomically: useAuxiliaryFile];
}
@end

View file

@ -176,6 +176,26 @@ static Class NSMutableAttributedString_concrete_class;
return nil;
}
- (NSString*) description
{
NSRange r = NSMakeRange(0, 0);
unsigned index = NSMaxRange(r);
unsigned length = [self length];
NSString *string = [self string];
NSDictionary *attrs;
NSMutableString *desc;
desc = AUTORELEASE([[super description] mutableCopy]);
while (index <= length &&
(attrs = [self attributesAtIndex: index effectiveRange: &r]) != nil)
{
index = NSMaxRange(r);
[desc appendFormat: @"\nRange: %@ Chars:'%@' Attrs: %@",
NSStringFromRange(r), [string substringFromRange: r], attrs];
}
return desc;
}
//Retrieving character information
- (unsigned int) length
{

View file

@ -32,6 +32,7 @@
#include <Foundation/NSException.h>
#include <Foundation/NSAutoreleasePool.h>
#include <Foundation/NSFileManager.h>
#include <Foundation/NSUserDefaults.h>
#include <Foundation/NSDebug.h>
@interface NSDictionaryNonCore : NSDictionary
@ -577,12 +578,18 @@ compareIt(id o1, id o2, void* context)
- (BOOL) writeToFile: (NSString *)path atomically: (BOOL)useAuxiliaryFile
{
return [[self description] writeToFile: path atomically: useAuxiliaryFile];
NSDictionary *loc;
NSString *desc;
loc = [[NSUserDefaults standardUserDefaults] dictionaryRepresentation];
desc = [self descriptionWithLocale: loc indent: 0];
return [desc writeToFile: path atomically: useAuxiliaryFile];
}
- (NSString*) description
{
return [self descriptionWithLocale: nil];
return [self descriptionWithLocale: nil indent: 0];
}
- (NSString*) descriptionInStringsFileFormat
@ -601,11 +608,13 @@ compareIt(id o1, id o2, void* context)
id val = (*myObj)(self, objSel, key);
[key descriptionWithLocale: nil
indent: 0
to: (id<GNUDescriptionDestination>)result];
if (val != nil && [val isEqualToString: @""] == NO)
{
(*appImp)(result, appSel, @" = ");
[val descriptionWithLocale: nil
indent: 0
to: (id<GNUDescriptionDestination>)result];
}
(*appImp)(result, appSel, @";\n");
@ -654,8 +663,6 @@ static NSString *indentStrings[] = {
{
IMP myObj = [self methodForSelector: objSel];
BOOL canCompare = YES;
NSString *iBaseString;
NSString *iSizeString;
unsigned i;
NSArray *keyArray = [self allKeys];
unsigned numKeys = [keyArray count];
@ -666,16 +673,6 @@ static NSString *indentStrings[] = {
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];
[keyArray getObjects: keys];
for (i = 0; i < numKeys; i++)
{
@ -780,34 +777,57 @@ static NSString *indentStrings[] = {
plists[i] = (*myObj)(self, objSel, keys[i]);
}
(*appImp)(result, appSel, @"{\n");
for (i = 0; i < numKeys; i++)
if (locale == nil)
{
id item = plists[i];
(*appImp)(result, appSel, iSizeString);
[keys[i] descriptionTo: result];
(*appImp)(result, appSel, @" = ");
if ([item respondsToSelector: @selector(descriptionWithLocale:indent:)])
(*appImp)(result, appSel, @"{");
for (i = 0; i < numKeys; i++)
{
[item descriptionWithLocale: locale indent: level to: result];
id o = plists[i];
[keys[i] descriptionWithLocale: nil indent: 0 to: result];
(*appImp)(result, appSel, @"=");
[o descriptionWithLocale: nil indent: 0 to: result];
(*appImp)(result, appSel, @";");
}
else if ([item respondsToSelector: @selector(descriptionWithLocale:)])
(*appImp)(result, appSel, @"}");
}
else
{
NSString *iBaseString;
NSString *iSizeString;
if (level < sizeof(indentStrings)/sizeof(id))
{
[item descriptionWithLocale: locale to: result];
iBaseString = indentStrings[level];
}
else
{
[item descriptionTo: result];
iBaseString = indentStrings[sizeof(indentStrings)/sizeof(id)-1];
}
level++;
if (level < sizeof(indentStrings)/sizeof(id))
{
iSizeString = indentStrings[level];
}
else
{
iSizeString = indentStrings[sizeof(indentStrings)/sizeof(id)-1];
}
(*appImp)(result, appSel, @";\n");
(*appImp)(result, appSel, @"{\n");
for (i = 0; i < numKeys; i++)
{
id o = plists[i];
(*appImp)(result, appSel, iSizeString);
[keys[i] descriptionWithLocale: nil indent: 0 to: result];
(*appImp)(result, appSel, @" = ");
[o descriptionWithLocale: locale indent: level to: result];
(*appImp)(result, appSel, @";\n");
}
(*appImp)(result, appSel, iBaseString);
(*appImp)(result, appSel, @"}");
}
(*appImp)(result, appSel, iBaseString);
(*appImp)(result, appSel, @"}");
}
@end

View file

@ -595,7 +595,9 @@ static IMP msInitImp; /* designated initialiser for mutable */
return [self initWithCStringNoCopy: buf length: length fromZone: z];
}
- (void) descriptionTo: (id<GNUDescriptionDestination>)output
- (void) descriptionWithLocale: (NSDictionary*)aLocale
indent: (unsigned) level
to: (id<GNUDescriptionDestination>)output
{
if (output == nil)
return;

View file

@ -780,7 +780,7 @@ static BOOL deallocNotifications = NO;
- (NSString*) description
{
return [NSString stringWithFormat: @"<%s: %lx>",
object_get_class_name(self), (unsigned long)self];
object_get_class_name(self), (unsigned long)self];
}
+ (NSString*) description
@ -788,22 +788,40 @@ static BOOL deallocNotifications = NO;
return [NSString stringWithCString: object_get_class_name(self)];
}
- (void) descriptionTo: (id<GNUDescriptionDestination>)output
- (NSString*) descriptionWithLocale: (NSDictionary*)locale
{
[output appendString: [self description]];
return [self description];
}
- (void) descriptionWithLocale: (NSDictionary*)aLocale
to: (id<GNUDescriptionDestination>)output
+ (NSString*) descriptionWithLocale: (NSDictionary*)locale
{
[output appendString: [(id)self descriptionWithLocale: aLocale]];
return [self description];
}
- (NSString*) descriptionWithLocale: (NSDictionary*)locale indent: (unsigned)c
{
return [self descriptionWithLocale: locale];
}
+ (NSString*) descriptionWithLocale: (NSDictionary*)locale indent: (unsigned)c
{
return [self descriptionWithLocale: locale];
}
- (void) descriptionWithLocale: (NSDictionary*)aLocale
indent: (unsigned)level
to: (id<GNUDescriptionDestination>)output
{
[output appendString: [(id)self descriptionWithLocale: aLocale indent: level]];
[output appendString:
[(id)self descriptionWithLocale: aLocale indent: level]];
}
+ (void) descriptionWithLocale: (NSDictionary*)aLocale
indent: (unsigned)level
to: (id<GNUDescriptionDestination>)output
{
[output appendString:
[(id)self descriptionWithLocale: aLocale indent: level]];
}
+ (void) poseAsClass: (Class)aClassObject
@ -1273,7 +1291,7 @@ static BOOL deallocNotifications = NO;
double_release_check_enabled = enable;
}
- (int)compare:anotherObject;
- (int) compare: (id)anotherObject;
{
if ([self isEqual:anotherObject])
return 0;
@ -1285,34 +1303,34 @@ static BOOL deallocNotifications = NO;
return -1;
}
- (BOOL)isMetaClass
- (BOOL) isMetaClass
{
return NO;
}
- (BOOL)isClass
- (BOOL) isClass
{
return object_is_class(self);
}
- (BOOL)isInstance
- (BOOL) isInstance
{
return object_is_instance(self);
}
- (BOOL)isMemberOfClassNamed:(const char *)aClassName
- (BOOL) isMemberOfClassNamed: (const char*)aClassName
{
return ((aClassName!=NULL)
&&!strcmp(class_get_class_name(self->isa), aClassName));
}
+ (struct objc_method_description *)descriptionForInstanceMethod:(SEL)aSel
+ (struct objc_method_description *) descriptionForInstanceMethod: (SEL)aSel
{
return ((struct objc_method_description *)
class_get_instance_method(self, aSel));
}
- (struct objc_method_description *)descriptionForMethod:(SEL)aSel
- (struct objc_method_description *) descriptionForMethod: (SEL)aSel
{
return ((struct objc_method_description *)
(object_is_instance(self)
@ -1320,7 +1338,7 @@ static BOOL deallocNotifications = NO;
:class_get_class_method(self->isa, aSel)));
}
- (Class)transmuteClassTo:(Class)aClassObject
- (Class) transmuteClassTo: (Class)aClassObject
{
if (object_is_instance(self))
if (class_is_class(aClassObject))
@ -1334,7 +1352,7 @@ static BOOL deallocNotifications = NO;
return nil;
}
- subclassResponsibility:(SEL)aSel
- (id) subclassResponsibility: (SEL)aSel
{
[NSException
raise: NSGenericException
@ -1342,7 +1360,7 @@ static BOOL deallocNotifications = NO;
return nil;
}
- shouldNotImplement:(SEL)aSel
- (id) shouldNotImplement: (SEL)aSel
{
[NSException
raise: NSGenericException
@ -1351,7 +1369,7 @@ static BOOL deallocNotifications = NO;
return nil;
}
+ (int)streamVersion: (TypedStream*)aStream
+ (int) streamVersion: (TypedStream*)aStream
{
if (aStream->mode == OBJC_READONLY)
return objc_get_stream_class_version (aStream, self);

View file

@ -2264,7 +2264,9 @@ handle_printf_atsign (FILE *stream,
return [d writeToFile: filename atomically: useAuxiliaryFile];
}
- (void) descriptionTo: (id<GNUDescriptionDestination>)output
- (void) descriptionWithLocale: (NSDictionary*)aLocale
indent: (unsigned)level
to: (id<GNUDescriptionDestination>)output
{
if ([self length] == 0)
{
@ -2273,8 +2275,9 @@ handle_printf_atsign (FILE *stream,
}
if (quotables == nil)
setupQuotables();
{
setupQuotables();
}
if ([self rangeOfCharacterFromSet: quotables].length > 0)
{
const char *cstring = [self cString];