From 0422591a90ca945173ad1fea1b08415a82b00ac6 Mon Sep 17 00:00:00 2001 From: CaS Date: Wed, 7 Aug 2002 11:06:49 +0000 Subject: [PATCH] Minor fix parsing booleans git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@14241 72102866-910b-0410-8b05-ffd578937521 --- ChangeLog | 4 ++++ Source/NSString.m | 13 ++++++++++++- Source/NSUserDefaults.m | 9 +++++++-- 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index 6477622f1..9bc22c924 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2002-08-07 Richard Frith-Macdonald + + * Source/NSString.m: ([-boolValue]) Accept 'true' as well as 'YES' + 2002-07-29 Adam Fedor * Merge changes from 1.4.0 onto main branch. diff --git a/Source/NSString.m b/Source/NSString.m index 254891aba..8cf1267a1 100644 --- a/Source/NSString.m +++ b/Source/NSString.m @@ -2182,10 +2182,21 @@ handle_printf_atsign (FILE *stream, // xxx Sould we use NSScanner here ? +/** + * If the string consists of the words 'true' or 'yes' (case insensitive) + * or begins with a non-zero numeric value, return YES, otherwise return + * NO. + */ - (BOOL) boolValue { if ([self caseInsensitiveCompare: @"YES"] == NSOrderedSame) - return YES; + { + return YES; + } + if ([self caseInsensitiveCompare: @"true"] == NSOrderedSame) + { + return YES; + } return [self intValue] != 0 ? YES : NO; } diff --git a/Source/NSUserDefaults.m b/Source/NSUserDefaults.m index 3550655eb..72a2f4cf1 100644 --- a/Source/NSUserDefaults.m +++ b/Source/NSUserDefaults.m @@ -811,14 +811,19 @@ static NSString *pathForUser(NSString *user) /** * Looks up a value for a specified default using -objectForKey: - * and checks that it is a boolean. Returns NO if it is not. + * and returns its boolean representation.
+ * Returns NO if it is not a boolean.
+ * The text 'yes' or 'true' or any non zero numeric value is considered + * to be a boolean YES. Other string values are NO. */ - (BOOL) boolForKey: (NSString*)defaultName { id obj = [self stringForKey: defaultName]; if (obj != nil) - return [obj boolValue]; + { + return [obj boolValue]; + } return NO; }