Character set mysteriously becomes null
Character set mysteriously becomes null
- Subject: Character set mysteriously becomes null
- From: Andrew Merenbach <email@hidden>
- Date: Thu, 19 Jul 2007 10:47:06 -0700
Hi, all,
I'm using the ExpressionEvaluator code (taken from BusyPalette) in my
project, along with ExpressionFormatter. I'm getting an exception,
though, and I've tracked it down to a character set being reset to nil.
At the top, there is the following code:
static NSCharacterSet *__numbersCharSet = nil; /* 0 to 9 */
and, in the implementation,
- initWithExpression:(NSString *)expression
{
if (nil != (self = [super init])) {
_expression = [expression copy];
_tokenPosition = 0;
_length = [_expression length];
if (!__numbersCharSet) {
__numbersCharSet = [NSCharacterSet
characterSetWithCharactersInString:@"01234567890.,"];
__mathOperations = [NSCharacterSet
characterSetWithCharactersInString:@"+-*/()"];
__whiteSpaceCharSet = [NSCharacterSet whitespaceCharacterSet];
[__numbersCharSet retain];
[__mathOperations retain];
}
}
return self;
}
When __numbersCharSet is called later, however, in -_nextToken, ...
while([__numbersCharSet characterIsMember:character]) {
buffer[i++] = character;
_tokenPosition++;
if (_tokenPosition >= _length) {
break;
}
character = [_expression characterAtIndex:_tokenPosition];
}
... I have tried logging it before the while loop-- NSLog
(@"__numbersCharSet = %@", __numbersCharSet) -- and it shows up as
(null)!
This seems to be a new occurrence--my code worked on older versions
of Mac OS X without difficulty.
Does anyone have any idea of what's going on?
Cheers,
Andrew
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden