mirror of
https://github.com/gnustep/libs-base.git
synced 2025-05-21 12:41:19 +00:00
OSX compatibility iprovement.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@28528 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
4e94a49ba8
commit
e7db98165f
4 changed files with 57 additions and 19 deletions
|
@ -2784,27 +2784,33 @@ handle_printf_atsign (FILE *stream,
|
|||
|
||||
// Getting Numeric Values
|
||||
|
||||
// xxx Should we use NSScanner here ?
|
||||
|
||||
/**
|
||||
* 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
|
||||
{
|
||||
static NSCharacterSet *yes = nil;
|
||||
unsigned length = [self length];
|
||||
|
||||
if (yes == nil)
|
||||
if (length > 0)
|
||||
{
|
||||
yes = RETAIN([NSCharacterSet characterSetWithCharactersInString:
|
||||
@"123456789yYtT"]);
|
||||
}
|
||||
if ([self rangeOfCharacterFromSet: yes].length > 0)
|
||||
{
|
||||
return YES;
|
||||
unsigned index;
|
||||
SEL sel = @selector(characterAtIndex:);
|
||||
unichar (*imp)() = (unichar (*)())[self methodForSelector: sel];
|
||||
|
||||
for (index = 0; index < length; index++)
|
||||
{
|
||||
unichar c = (*imp)(self, sel, index);
|
||||
|
||||
if (c > 'y')
|
||||
{
|
||||
break;
|
||||
}
|
||||
if (strchr("123456789yYtT", c) != 0)
|
||||
{
|
||||
return YES;
|
||||
}
|
||||
if (!isspace(c) && c != '0' && c != '-' && c != '+')
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return NO;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue