mirror of
https://github.com/gnustep/libs-base.git
synced 2025-05-10 00:00:50 +00:00
Correct (for #486) -localizedDescription to always return a string.
This commit is contained in:
parent
afa5035d2c
commit
479cccebe8
1 changed files with 27 additions and 3 deletions
|
@ -81,14 +81,24 @@
|
||||||
[super dealloc];
|
[super dealloc];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (NSString*) _fallback
|
||||||
|
{
|
||||||
|
return [NSString stringWithFormat: @"Error Domain=%@ Code=%lld",
|
||||||
|
[self domain], (long long)[self code]];
|
||||||
|
}
|
||||||
|
|
||||||
- (NSString*) description
|
- (NSString*) description
|
||||||
{
|
{
|
||||||
NSMutableString *m = [NSMutableString stringWithCapacity: 200];
|
NSMutableString *m = [NSMutableString stringWithCapacity: 200];
|
||||||
NSUInteger count = [_userInfo count];
|
NSUInteger count = [_userInfo count];
|
||||||
NSString *loc = [self localizedDescription];
|
NSString *loc = [self localizedDescription];
|
||||||
|
NSString *fallback = [self _fallback];
|
||||||
|
|
||||||
[m appendFormat: @"Error Domain=%@ Code=%lld \"%@\"",
|
[m appendString: fallback];
|
||||||
[self domain], (long long)[self code], loc];
|
if (NO == [fallback isEqual: loc])
|
||||||
|
{
|
||||||
|
[m appendFormat: @" \"%@\"", loc];
|
||||||
|
}
|
||||||
|
|
||||||
if ([loc isEqual: [_userInfo objectForKey: NSLocalizedDescriptionKey]])
|
if ([loc isEqual: [_userInfo objectForKey: NSLocalizedDescriptionKey]])
|
||||||
{
|
{
|
||||||
|
@ -206,7 +216,21 @@
|
||||||
|
|
||||||
- (NSString *) localizedDescription
|
- (NSString *) localizedDescription
|
||||||
{
|
{
|
||||||
return [_userInfo objectForKey: NSLocalizedDescriptionKey];
|
NSString *s = [_userInfo objectForKey: NSLocalizedDescriptionKey];
|
||||||
|
|
||||||
|
if (nil == s)
|
||||||
|
{
|
||||||
|
s = [_userInfo objectForKey: NSLocalizedFailureReasonErrorKey];
|
||||||
|
if (s)
|
||||||
|
{
|
||||||
|
s = [NSString stringWithFormat: @"Operation failed %@", s];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
s = [self _fallback];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSString *) localizedFailureReason
|
- (NSString *) localizedFailureReason
|
||||||
|
|
Loading…
Reference in a new issue