From 4394e1d65be6ecc4b897e50ac127edaedd95eec4 Mon Sep 17 00:00:00 2001 From: Richard Frith-MacDonald Date: Sun, 19 Mar 2000 09:23:41 +0000 Subject: [PATCH] Implemented description method for NSUserDefaults. and tidied description stuff git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@6332 72102866-910b-0410-8b05-ffd578937521 --- ChangeLog | 9 ++ Source/NSArray.m | 2 +- Source/NSDictionary.m | 218 +++++++++++++++++++++------------------- Source/NSUserDefaults.m | 30 +++--- 4 files changed, 137 insertions(+), 122 deletions(-) diff --git a/ChangeLog b/ChangeLog index 0eb689fc1..051a6eba9 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2000-03-19 Richard Frith-Macdonald + + * Source/NSUserDefaults.m: ([-description]) implemented. + * Source/NSArray.m: ([-descriptionWithLocale:indent:]) put space + after comma even when doing unformatted description. + * Source/NSDictionary.m: ([-descriptionWithLocale:indent:]) put space + after semicolon and around equals even when doing unformatted + description. Don't sort array items in unformatted description. + 2000-03-19 Richard Frith-Macdonald * Source/NSGAttributedString.m: ([setAttributes:range:]) make sure diff --git a/Source/NSArray.m b/Source/NSArray.m index 6ef8ee3a7..3cba8bda5 100644 --- a/Source/NSArray.m +++ b/Source/NSArray.m @@ -721,7 +721,7 @@ static NSString *indentStrings[] = { [item descriptionWithLocale: nil indent: 0 to: result]; if (i != last) { - (*appImp)(result, appSel, @","); + (*appImp)(result, appSel, @", "); } } (*appImp)(result, appSel, @")"); diff --git a/Source/NSDictionary.m b/Source/NSDictionary.m index 708016892..067455f6d 100644 --- a/Source/NSDictionary.m +++ b/Source/NSDictionary.m @@ -662,132 +662,33 @@ static NSString *indentStrings[] = { to: (id)result { IMP myObj = [self methodForSelector: objSel]; - BOOL canCompare = YES; unsigned i; NSArray *keyArray = [self allKeys]; unsigned numKeys = [keyArray count]; NSString *plists[numKeys]; NSString *keys[numKeys]; IMP appImp; - Class lastClass = 0; appImp = [(NSObject*)result methodForSelector: appSel]; [keyArray getObjects: keys]; - for (i = 0; i < numKeys; i++) - { - if (fastClass(keys[i]) == lastClass) - continue; - if ([keys[i] respondsToSelector: @selector(compare:)] == NO) - { - canCompare = NO; - break; - } - lastClass = fastClass(keys[i]); - } - - if (canCompare) - { -/* - * Shell sort algorithm taken from SortingInAction - a NeXT example - * good value for stride factor is not well-understood - * 3 is a fairly good choice (Sedgewick) - */ -#define STRIDE_FACTOR 3 - unsigned c,d, stride; - BOOL found; - NSComparisonResult (*comp)(id, SEL, id); - int count = numKeys; -#ifdef GSWARN - BOOL badComparison = NO; -#endif - - stride = 1; - while (stride <= count) - { - stride = stride * STRIDE_FACTOR + 1; - } - lastClass = 0; - while (stride > (STRIDE_FACTOR - 1)) - { - // loop to sort for each value of stride - stride = stride / STRIDE_FACTOR; - for (c = stride; c < count; c++) - { - found = NO; - if (stride > c) - { - break; - } - d = c - stride; - while (!found) // move to left until correct place - { - id a = keys[d + stride]; - id b = keys[d]; - Class x; - NSComparisonResult r; - - x = fastClass(a); - if (x != lastClass) - { - lastClass = x; - comp = (NSComparisonResult (*)(id, SEL, id)) - [a methodForSelector: @selector(compare:)]; - } - r = (*comp)(a, @selector(compare:), b); - if (r < 0) - { -#ifdef GSWARN - if (r != NSOrderedAscending) - { - badComparison = YES; - } -#endif - keys[d + stride] = b; - keys[d] = a; - if (stride > d) - { - break; - } - d -= stride; // jump by stride factor - } - else - { -#ifdef GSWARN - if (r != NSOrderedDescending && r != NSOrderedSame) - { - badComparison = YES; - } -#endif - found = YES; - } - } - } - } -#ifdef GSWARN - if (badComparison == YES) - { - NSWarnMLog(@"Detected bad return value from comparison", 0); - } -#endif - } - - for (i = 0; i < numKeys; i++) - { - plists[i] = (*myObj)(self, objSel, keys[i]); - } if (locale == nil) { + for (i = 0; i < numKeys; i++) + { + plists[i] = (*myObj)(self, objSel, keys[i]); + } + (*appImp)(result, appSel, @"{"); for (i = 0; i < numKeys; i++) { id o = plists[i]; [keys[i] descriptionWithLocale: nil indent: 0 to: result]; - (*appImp)(result, appSel, @"="); + (*appImp)(result, appSel, @" = "); [o descriptionWithLocale: nil indent: 0 to: result]; - (*appImp)(result, appSel, @";"); + (*appImp)(result, appSel, @"; "); } (*appImp)(result, appSel, @"}"); } @@ -795,6 +696,8 @@ static NSString *indentStrings[] = { { NSString *iBaseString; NSString *iSizeString; + BOOL canCompare = YES; + Class lastClass = 0; if (level < sizeof(indentStrings)/sizeof(id)) { @@ -814,6 +717,109 @@ static NSString *indentStrings[] = { iSizeString = indentStrings[sizeof(indentStrings)/sizeof(id)-1]; } + for (i = 0; i < numKeys; i++) + { + if (fastClass(keys[i]) == lastClass) + continue; + if ([keys[i] respondsToSelector: @selector(compare:)] == NO) + { + canCompare = NO; + break; + } + lastClass = fastClass(keys[i]); + } + + if (canCompare == YES) + { + /* + * Shell sort algorithm taken from SortingInAction - a NeXT example + * good value for stride factor is not well-understood + * 3 is a fairly good choice (Sedgewick) + */ +#define STRIDE_FACTOR 3 + unsigned c,d, stride; + BOOL found; + NSComparisonResult (*comp)(id, SEL, id); + int count = numKeys; +#ifdef GSWARN + BOOL badComparison = NO; +#endif + + stride = 1; + while (stride <= count) + { + stride = stride * STRIDE_FACTOR + 1; + } + lastClass = 0; + while (stride > (STRIDE_FACTOR - 1)) + { + // loop to sort for each value of stride + stride = stride / STRIDE_FACTOR; + for (c = stride; c < count; c++) + { + found = NO; + if (stride > c) + { + break; + } + d = c - stride; + while (!found) // move to left until correct place + { + id a = keys[d + stride]; + id b = keys[d]; + Class x; + NSComparisonResult r; + + x = fastClass(a); + if (x != lastClass) + { + lastClass = x; + comp = (NSComparisonResult (*)(id, SEL, id)) + [a methodForSelector: @selector(compare:)]; + } + r = (*comp)(a, @selector(compare:), b); + if (r < 0) + { +#ifdef GSWARN + if (r != NSOrderedAscending) + { + badComparison = YES; + } +#endif + keys[d + stride] = b; + keys[d] = a; + if (stride > d) + { + break; + } + d -= stride; // jump by stride factor + } + else + { +#ifdef GSWARN + if (r != NSOrderedDescending && r != NSOrderedSame) + { + badComparison = YES; + } +#endif + found = YES; + } + } + } + } +#ifdef GSWARN + if (badComparison == YES) + { + NSWarnMLog(@"Detected bad return value from comparison", 0); + } +#endif + } + + for (i = 0; i < numKeys; i++) + { + plists[i] = (*myObj)(self, objSel, keys[i]); + } + (*appImp)(result, appSel, @"{\n"); for (i = 0; i < numKeys; i++) { diff --git a/Source/NSUserDefaults.m b/Source/NSUserDefaults.m index 4052104be..71a16100c 100644 --- a/Source/NSUserDefaults.m +++ b/Source/NSUserDefaults.m @@ -405,26 +405,26 @@ static NSString *pathForUser(NSString *user) // Check and if not existent add the Application and the Global domains if (![_persDomains objectForKey: processName]) { - [_persDomains setObject: - [NSMutableDictionaryClass - dictionaryWithCapacity: 10] forKey: processName]; + [_persDomains + setObject: [NSMutableDictionaryClass dictionaryWithCapacity: 10] + forKey: processName]; [self __changePersistentDomain: processName]; } if (![_persDomains objectForKey: NSGlobalDomain]) { - [_persDomains setObject: - [NSMutableDictionaryClass - dictionaryWithCapacity: 10] forKey: NSGlobalDomain]; + [_persDomains + setObject: [NSMutableDictionaryClass dictionaryWithCapacity: 10] + forKey: NSGlobalDomain]; [self __changePersistentDomain: NSGlobalDomain]; } // Create volatile defaults and add the Argument and the Registration domains _tempDomains = [[NSMutableDictionaryClass alloc] initWithCapacity: 10]; [_tempDomains setObject: [self __createArgumentDictionary] - forKey: NSArgumentDomain]; - [_tempDomains setObject: - [NSMutableDictionaryClass - dictionaryWithCapacity: 10] forKey: NSRegistrationDomain]; + forKey: NSArgumentDomain]; + [_tempDomains + setObject: [NSMutableDictionaryClass dictionaryWithCapacity: 10] + forKey: NSRegistrationDomain]; return self; } @@ -444,12 +444,12 @@ static NSString *pathForUser(NSString *user) - (NSString*) description { - NSMutableString *desc = - [NSMutableString stringWithFormat: @"%@",[super description]]; + NSMutableString *desc; - // $$$ Not Implemented - // It's good idea to put all useful info here -- so I can test it later - [self notImplemented: _cmd]; + desc = [NSMutableString stringWithFormat: @"%@", [super description]]; + [desc appendFormat: @" SearchList: %@", _searchList]; + [desc appendFormat: @" Persistant: %@", _persDomains]; + [desc appendFormat: @" Temporary: %@", _tempDomains]; return desc; }