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:
rfm 2009-08-24 07:07:36 +00:00
parent 0f39425f46
commit 608d011083
4 changed files with 57 additions and 19 deletions

View file

@ -1,3 +1,11 @@
2009-08-24 Richard Frith-Macdonald <rfm@gnu.org>
* Source/NSString.m:
* Source/GSString.m:
* Headers/Foundation/NSString.h:
Tweak boolValue behavior to better match OSX and document exact
behavior.
2009-08-23 Richard Frith-Macdonald <rfm@gnu.org>
* Source/win32/GSFileHandle.m: Fix for write in background on windows

View file

@ -709,6 +709,14 @@ typedef NSUInteger NSStringEncodingConversionOptions;
#endif
#if OS_API_VERSION(100500,GS_API_LATEST)
/**
* Returns YES when scanning the receiver's text from left to right
* finds an initial 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;
- (NSArray *) componentsSeparatedByCharactersInSet: (NSCharacterSet *)separator;
- (NSInteger) integerValue;

View file

@ -1005,10 +1005,16 @@ boolValue_c(GSStr self)
for (i = 0; i < c; i++)
{
if (strchr("123456789yYtT", self->_contents.c[i]) != 0)
char c = self->_contents.c[i];
if (strchr("123456789yYtT", c) != 0)
{
return YES;
}
if (!isspace(c) && c != '0' && c != '-' && c != '+')
{
break;
}
}
return NO;
}
@ -1021,10 +1027,20 @@ boolValue_u(GSStr self)
for (i = 0; i < c; i++)
{
if (strchr("123456789yYtT", self->_contents.u[i]) != 0)
unichar c = self->_contents.u[i];
if (c > 'y')
{
break;
}
if (strchr("123456789yYtT", c) != 0)
{
return YES;
}
if (!isspace(c) && c != '0' && c != '-' && c != '+')
{
break;
}
}
return NO;
}

View file

@ -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;
}