mirror of
https://github.com/gnustep/libs-base.git
synced 2025-04-23 00:41:02 +00:00
Change behavior of -boolValue to match the new MacOS-X method of the same name.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@26110 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
726b05507e
commit
b4c5948f8d
3 changed files with 34 additions and 69 deletions
|
@ -9,6 +9,8 @@
|
|||
* Source/Additions/Unicode.m: add lockign for nl_langinfo
|
||||
* Source/Additions/GSMime.m: New method to parse headers
|
||||
* Headers/Additions/GNUstepBase/GSMime.h: ditto
|
||||
* Source/NSString.m: Change ([-boolValue]) to match new MacOS-X method.
|
||||
* Source/GSString.m: ditto
|
||||
|
||||
2008-02-19 Nicola Pero <nicola.pero@meta-innovation.com>
|
||||
|
||||
|
|
|
@ -938,75 +938,33 @@ UTF8String_u(GSStr self)
|
|||
static inline BOOL
|
||||
boolValue_c(GSStr self)
|
||||
{
|
||||
if (self->_count == 0)
|
||||
{
|
||||
return NO;
|
||||
}
|
||||
else
|
||||
{
|
||||
unsigned len = self->_count < 10 ? self->_count : 9;
|
||||
unsigned c = self->_count;
|
||||
unsigned i;
|
||||
|
||||
if (len == 3
|
||||
&& (self->_contents.c[0] == 'Y' || self->_contents.c[0] == 'y')
|
||||
&& (self->_contents.c[1] == 'E' || self->_contents.c[1] == 'e')
|
||||
&& (self->_contents.c[2] == 'S' || self->_contents.c[2] == 's'))
|
||||
{
|
||||
return YES;
|
||||
}
|
||||
else if (len == 4
|
||||
&& (self->_contents.c[0] == 'T' || self->_contents.c[0] == 't')
|
||||
&& (self->_contents.c[1] == 'R' || self->_contents.c[1] == 'r')
|
||||
&& (self->_contents.c[2] == 'U' || self->_contents.c[2] == 'u')
|
||||
&& (self->_contents.c[3] == 'E' || self->_contents.c[3] == 'e'))
|
||||
{
|
||||
return YES;
|
||||
}
|
||||
else
|
||||
{
|
||||
unsigned char buf[len+1];
|
||||
|
||||
memcpy(buf, self->_contents.c, len);
|
||||
buf[len] = '\0';
|
||||
return atoi((const char*)buf);
|
||||
}
|
||||
for (i = 0; i < c; i++)
|
||||
{
|
||||
if (strchr("123456789yYtT", self->_contents.c[i]) != 0)
|
||||
{
|
||||
return YES;
|
||||
}
|
||||
}
|
||||
return NO;
|
||||
}
|
||||
|
||||
static inline BOOL
|
||||
boolValue_u(GSStr self)
|
||||
{
|
||||
if (self->_count == 0)
|
||||
{
|
||||
return NO;
|
||||
}
|
||||
else
|
||||
{
|
||||
unsigned int l = self->_count < 10 ? self->_count : 9;
|
||||
unsigned char buf[l+1];
|
||||
unsigned char *b = buf;
|
||||
unsigned c = self->_count;
|
||||
unsigned i;
|
||||
|
||||
GSFromUnicode(&b, &l, self->_contents.u, l, internalEncoding,
|
||||
0, GSUniTerminate);
|
||||
if (l == 3
|
||||
&& (buf[0] == 'Y' || buf[0] == 'y')
|
||||
&& (buf[1] == 'E' || buf[1] == 'e')
|
||||
&& (buf[2] == 'S' || buf[2] == 's'))
|
||||
{
|
||||
return YES;
|
||||
}
|
||||
else if (l == 4
|
||||
&& (buf[0] == 'T' || buf[0] == 't')
|
||||
&& (buf[1] == 'R' || buf[1] == 'r')
|
||||
&& (buf[2] == 'U' || buf[2] == 'u')
|
||||
&& (buf[3] == 'E' || buf[3] == 'e'))
|
||||
{
|
||||
return YES;
|
||||
}
|
||||
else
|
||||
{
|
||||
return atoi((const char*)buf);
|
||||
}
|
||||
for (i = 0; i < c; i++)
|
||||
{
|
||||
if (strchr("123456789yYtT", self->_contents.u[i]) != 0)
|
||||
{
|
||||
return YES;
|
||||
}
|
||||
}
|
||||
return NO;
|
||||
}
|
||||
|
||||
static inline BOOL
|
||||
|
|
|
@ -2615,21 +2615,26 @@ handle_printf_atsign (FILE *stream,
|
|||
// xxx Should 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.
|
||||
* Returns YES when scanning the receiver's text from left to right finds a
|
||||
* digit in the range 1-9 or a letter in the set ('Y', 'y', 'T', 't').<br />
|
||||
* Any trailing characters are ignored.<br />
|
||||
* Any leading whitespace or zeros or signs are also ignored.<br />
|
||||
* Returns NO if the above conditions are not met.
|
||||
*/
|
||||
- (BOOL) boolValue
|
||||
{
|
||||
if ([self caseInsensitiveCompare: @"YES"] == NSOrderedSame)
|
||||
static NSCharacterSet *yes = nil;
|
||||
|
||||
if (yes == nil)
|
||||
{
|
||||
yes = RETAIN([NSCharacterSet characterSetWithCharactersInString:
|
||||
@"123456789yYtT"]);
|
||||
}
|
||||
if ([self rangeOfCharacterFromSet: yes].length > 0)
|
||||
{
|
||||
return YES;
|
||||
}
|
||||
if ([self caseInsensitiveCompare: @"true"] == NSOrderedSame)
|
||||
{
|
||||
return YES;
|
||||
}
|
||||
return [self intValue] != 0 ? YES : NO;
|
||||
return NO;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue