mirror of
https://github.com/gnustep/libs-base.git
synced 2025-05-31 16:50:58 +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
9168f3c85d
commit
4d082e85fa
3 changed files with 34 additions and 69 deletions
|
@ -9,6 +9,8 @@
|
||||||
* Source/Additions/Unicode.m: add lockign for nl_langinfo
|
* Source/Additions/Unicode.m: add lockign for nl_langinfo
|
||||||
* Source/Additions/GSMime.m: New method to parse headers
|
* Source/Additions/GSMime.m: New method to parse headers
|
||||||
* Headers/Additions/GNUstepBase/GSMime.h: ditto
|
* 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>
|
2008-02-19 Nicola Pero <nicola.pero@meta-innovation.com>
|
||||||
|
|
||||||
|
|
|
@ -938,75 +938,33 @@ UTF8String_u(GSStr self)
|
||||||
static inline BOOL
|
static inline BOOL
|
||||||
boolValue_c(GSStr self)
|
boolValue_c(GSStr self)
|
||||||
{
|
{
|
||||||
if (self->_count == 0)
|
unsigned c = self->_count;
|
||||||
{
|
unsigned i;
|
||||||
return NO;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
unsigned len = self->_count < 10 ? self->_count : 9;
|
|
||||||
|
|
||||||
if (len == 3
|
for (i = 0; i < c; i++)
|
||||||
&& (self->_contents.c[0] == 'Y' || self->_contents.c[0] == 'y')
|
{
|
||||||
&& (self->_contents.c[1] == 'E' || self->_contents.c[1] == 'e')
|
if (strchr("123456789yYtT", self->_contents.c[i]) != 0)
|
||||||
&& (self->_contents.c[2] == 'S' || self->_contents.c[2] == 's'))
|
{
|
||||||
{
|
return YES;
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
return NO;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline BOOL
|
static inline BOOL
|
||||||
boolValue_u(GSStr self)
|
boolValue_u(GSStr self)
|
||||||
{
|
{
|
||||||
if (self->_count == 0)
|
unsigned c = self->_count;
|
||||||
{
|
unsigned i;
|
||||||
return NO;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
unsigned int l = self->_count < 10 ? self->_count : 9;
|
|
||||||
unsigned char buf[l+1];
|
|
||||||
unsigned char *b = buf;
|
|
||||||
|
|
||||||
GSFromUnicode(&b, &l, self->_contents.u, l, internalEncoding,
|
for (i = 0; i < c; i++)
|
||||||
0, GSUniTerminate);
|
{
|
||||||
if (l == 3
|
if (strchr("123456789yYtT", self->_contents.u[i]) != 0)
|
||||||
&& (buf[0] == 'Y' || buf[0] == 'y')
|
{
|
||||||
&& (buf[1] == 'E' || buf[1] == 'e')
|
return YES;
|
||||||
&& (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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
return NO;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline BOOL
|
static inline BOOL
|
||||||
|
|
|
@ -2615,21 +2615,26 @@ handle_printf_atsign (FILE *stream,
|
||||||
// xxx Should we use NSScanner here ?
|
// xxx Should we use NSScanner here ?
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* If the string consists of the words 'true' or 'yes' (case insensitive)
|
* Returns YES when scanning the receiver's text from left to right finds a
|
||||||
* or begins with a non-zero numeric value, return YES, otherwise return
|
* digit in the range 1-9 or a letter in the set ('Y', 'y', 'T', 't').<br />
|
||||||
* NO.
|
* 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
|
- (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;
|
return YES;
|
||||||
}
|
}
|
||||||
if ([self caseInsensitiveCompare: @"true"] == NSOrderedSame)
|
return NO;
|
||||||
{
|
|
||||||
return YES;
|
|
||||||
}
|
|
||||||
return [self intValue] != 0 ? YES : NO;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue