locale tweaks

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@32006 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Richard Frith-MacDonald 2011-02-07 17:21:00 +00:00
parent a44bf0713b
commit 525371f50b
2 changed files with 22 additions and 5 deletions

View file

@ -1,3 +1,10 @@
2011-02-07 Richard Frith-Macdonald <rfm@gnu.org>
* Source/NSLocale.m: Fix canonical identifiers to return the input
string if no other value is found. Refrain from putting nil locale
identifier in dictionary. Fix leak of components dictionary when
returning an existing locale by id.
2011-02-04 Richard Frith-Macdonald <rfm@gnu.org> 2011-02-04 Richard Frith-Macdonald <rfm@gnu.org>
* Source/NSConcretePointerFunctions.m: objects with weak memory should * Source/NSConcretePointerFunctions.m: objects with weak memory should

View file

@ -273,9 +273,15 @@ static NSRecursiveLock *classLock = nil;
[self _updateCanonicalLocales]; [self _updateCanonicalLocales];
localeId = [canonicalLocales objectForKey: string]; localeId = [canonicalLocales objectForKey: string];
localeComps = [localeId componentsSeparatedByString: @"_"]; if (nil == localeId)
result = [localeComps objectAtIndex: 0]; {
result = string;
}
else
{
localeComps = [localeId componentsSeparatedByString: @"_"];
result = [localeComps objectAtIndex: 0];
}
return result; return result;
} }
@ -736,12 +742,18 @@ static NSRecursiveLock *classLock = nil;
#else #else
localeId = [NSLocale canonicalLocaleIdentifierFromString: string]; localeId = [NSLocale canonicalLocaleIdentifierFromString: string];
#endif #endif
if (nil == localeId)
{
[self release];
return nil;
}
[classLock lock]; [classLock lock];
newLocale = [allLocales objectForKey: localeId]; newLocale = [allLocales objectForKey: localeId];
if (nil == newLocale) if (nil == newLocale)
{ {
_localeId = [localeId copy]; _localeId = [localeId copy];
_components = [[NSMutableDictionary alloc] initWithCapacity: 0];
[allLocales setObject: self forKey: localeId]; [allLocales setObject: self forKey: localeId];
} }
else else
@ -750,8 +762,6 @@ static NSRecursiveLock *classLock = nil;
self = [newLocale retain]; self = [newLocale retain];
} }
[classLock unlock]; [classLock unlock];
_components = [[NSMutableDictionary alloc] initWithCapacity: 0];
return self; return self;
} }