mirror of
https://github.com/gnustep/libs-base.git
synced 2025-05-30 16:30:41 +00:00
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:
parent
79e7e51a48
commit
4394e1d65b
4 changed files with 137 additions and 122 deletions
|
@ -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>
|
2000-03-19 Richard Frith-Macdonald <rfm@gnu.org>
|
||||||
|
|
||||||
* Source/NSGAttributedString.m: ([setAttributes:range:]) make sure
|
* Source/NSGAttributedString.m: ([setAttributes:range:]) make sure
|
||||||
|
|
|
@ -721,7 +721,7 @@ static NSString *indentStrings[] = {
|
||||||
[item descriptionWithLocale: nil indent: 0 to: result];
|
[item descriptionWithLocale: nil indent: 0 to: result];
|
||||||
if (i != last)
|
if (i != last)
|
||||||
{
|
{
|
||||||
(*appImp)(result, appSel, @",");
|
(*appImp)(result, appSel, @", ");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
(*appImp)(result, appSel, @")");
|
(*appImp)(result, appSel, @")");
|
||||||
|
|
|
@ -662,132 +662,33 @@ static NSString *indentStrings[] = {
|
||||||
to: (id<GNUDescriptionDestination>)result
|
to: (id<GNUDescriptionDestination>)result
|
||||||
{
|
{
|
||||||
IMP myObj = [self methodForSelector: objSel];
|
IMP myObj = [self methodForSelector: objSel];
|
||||||
BOOL canCompare = YES;
|
|
||||||
unsigned i;
|
unsigned i;
|
||||||
NSArray *keyArray = [self allKeys];
|
NSArray *keyArray = [self allKeys];
|
||||||
unsigned numKeys = [keyArray count];
|
unsigned numKeys = [keyArray count];
|
||||||
NSString *plists[numKeys];
|
NSString *plists[numKeys];
|
||||||
NSString *keys[numKeys];
|
NSString *keys[numKeys];
|
||||||
IMP appImp;
|
IMP appImp;
|
||||||
Class lastClass = 0;
|
|
||||||
|
|
||||||
appImp = [(NSObject*)result methodForSelector: appSel];
|
appImp = [(NSObject*)result methodForSelector: appSel];
|
||||||
|
|
||||||
[keyArray getObjects: keys];
|
[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)
|
if (locale == nil)
|
||||||
{
|
{
|
||||||
|
for (i = 0; i < numKeys; i++)
|
||||||
|
{
|
||||||
|
plists[i] = (*myObj)(self, objSel, keys[i]);
|
||||||
|
}
|
||||||
|
|
||||||
(*appImp)(result, appSel, @"{");
|
(*appImp)(result, appSel, @"{");
|
||||||
for (i = 0; i < numKeys; i++)
|
for (i = 0; i < numKeys; i++)
|
||||||
{
|
{
|
||||||
id o = plists[i];
|
id o = plists[i];
|
||||||
|
|
||||||
[keys[i] descriptionWithLocale: nil indent: 0 to: result];
|
[keys[i] descriptionWithLocale: nil indent: 0 to: result];
|
||||||
(*appImp)(result, appSel, @"=");
|
(*appImp)(result, appSel, @" = ");
|
||||||
[o descriptionWithLocale: nil indent: 0 to: result];
|
[o descriptionWithLocale: nil indent: 0 to: result];
|
||||||
(*appImp)(result, appSel, @";");
|
(*appImp)(result, appSel, @"; ");
|
||||||
}
|
}
|
||||||
(*appImp)(result, appSel, @"}");
|
(*appImp)(result, appSel, @"}");
|
||||||
}
|
}
|
||||||
|
@ -795,6 +696,8 @@ static NSString *indentStrings[] = {
|
||||||
{
|
{
|
||||||
NSString *iBaseString;
|
NSString *iBaseString;
|
||||||
NSString *iSizeString;
|
NSString *iSizeString;
|
||||||
|
BOOL canCompare = YES;
|
||||||
|
Class lastClass = 0;
|
||||||
|
|
||||||
if (level < sizeof(indentStrings)/sizeof(id))
|
if (level < sizeof(indentStrings)/sizeof(id))
|
||||||
{
|
{
|
||||||
|
@ -814,6 +717,109 @@ static NSString *indentStrings[] = {
|
||||||
iSizeString = indentStrings[sizeof(indentStrings)/sizeof(id)-1];
|
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");
|
(*appImp)(result, appSel, @"{\n");
|
||||||
for (i = 0; i < numKeys; i++)
|
for (i = 0; i < numKeys; i++)
|
||||||
{
|
{
|
||||||
|
|
|
@ -405,26 +405,26 @@ static NSString *pathForUser(NSString *user)
|
||||||
// Check and if not existent add the Application and the Global domains
|
// Check and if not existent add the Application and the Global domains
|
||||||
if (![_persDomains objectForKey: processName])
|
if (![_persDomains objectForKey: processName])
|
||||||
{
|
{
|
||||||
[_persDomains setObject:
|
[_persDomains
|
||||||
[NSMutableDictionaryClass
|
setObject: [NSMutableDictionaryClass dictionaryWithCapacity: 10]
|
||||||
dictionaryWithCapacity: 10] forKey: processName];
|
forKey: processName];
|
||||||
[self __changePersistentDomain: processName];
|
[self __changePersistentDomain: processName];
|
||||||
}
|
}
|
||||||
if (![_persDomains objectForKey: NSGlobalDomain])
|
if (![_persDomains objectForKey: NSGlobalDomain])
|
||||||
{
|
{
|
||||||
[_persDomains setObject:
|
[_persDomains
|
||||||
[NSMutableDictionaryClass
|
setObject: [NSMutableDictionaryClass dictionaryWithCapacity: 10]
|
||||||
dictionaryWithCapacity: 10] forKey: NSGlobalDomain];
|
forKey: NSGlobalDomain];
|
||||||
[self __changePersistentDomain: NSGlobalDomain];
|
[self __changePersistentDomain: NSGlobalDomain];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create volatile defaults and add the Argument and the Registration domains
|
// Create volatile defaults and add the Argument and the Registration domains
|
||||||
_tempDomains = [[NSMutableDictionaryClass alloc] initWithCapacity: 10];
|
_tempDomains = [[NSMutableDictionaryClass alloc] initWithCapacity: 10];
|
||||||
[_tempDomains setObject: [self __createArgumentDictionary]
|
[_tempDomains setObject: [self __createArgumentDictionary]
|
||||||
forKey: NSArgumentDomain];
|
forKey: NSArgumentDomain];
|
||||||
[_tempDomains setObject:
|
[_tempDomains
|
||||||
[NSMutableDictionaryClass
|
setObject: [NSMutableDictionaryClass dictionaryWithCapacity: 10]
|
||||||
dictionaryWithCapacity: 10] forKey: NSRegistrationDomain];
|
forKey: NSRegistrationDomain];
|
||||||
|
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
@ -444,12 +444,12 @@ static NSString *pathForUser(NSString *user)
|
||||||
|
|
||||||
- (NSString*) description
|
- (NSString*) description
|
||||||
{
|
{
|
||||||
NSMutableString *desc =
|
NSMutableString *desc;
|
||||||
[NSMutableString stringWithFormat: @"%@",[super description]];
|
|
||||||
|
|
||||||
// $$$ Not Implemented
|
desc = [NSMutableString stringWithFormat: @"%@", [super description]];
|
||||||
// It's good idea to put all useful info here -- so I can test it later
|
[desc appendFormat: @" SearchList: %@", _searchList];
|
||||||
[self notImplemented: _cmd];
|
[desc appendFormat: @" Persistant: %@", _persDomains];
|
||||||
|
[desc appendFormat: @" Temporary: %@", _tempDomains];
|
||||||
return desc;
|
return desc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue