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
This commit is contained in:
richard 2000-03-19 09:23:41 +00:00
parent a9f4a4a66d
commit 54afbd1dcf
4 changed files with 137 additions and 122 deletions

View file

@ -1,3 +1,12 @@
2000-03-19 Richard Frith-Macdonald <rfm@gnu.org>
* 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 <rfm@gnu.org>
* Source/NSGAttributedString.m: ([setAttributes:range:]) make sure

View file

@ -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, @")");

View file

@ -662,132 +662,33 @@ static NSString *indentStrings[] = {
to: (id<GNUDescriptionDestination>)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++)
{

View file

@ -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;
}