Infinite loop in NSScanner
Infinite loop in NSScanner
- Subject: Infinite loop in NSScanner
- From: "Mike R. Manzano" <email@hidden>
- Date: Wed, 23 Mar 2005 14:37:31 -0800
Why does an input string containing a comma or semicolon cause this to
go into an infinite loop, yet works when only spaces are used to
delimit keywords?
NSString* keywords = @"this is,a test" ;
// Separate out the keywords
NSScanner* scanner = [ NSScanner scannerWithString:keywords ] ;
[ scanner setCaseSensitive:NO ] ;
NSMutableCharacterSet* whitespaceSet =
[ [ [ NSMutableCharacterSet alloc] init ] autorelease ] ;
[ whitespaceSet formUnionWithCharacterSet:[
NSCharacterSet whitespaceAndNewlineCharacterSet ] ] ;
// Add commas and other punctuation to the character set
[ whitespaceSet addCharactersInString:@",;" ] ;
// Scan for life forms
NSMutableArray* keywordArray = [ NSMutableArray array ] ;
NSString* scanString = nil ;
while( ![scanner isAtEnd] )
{
// Pull out a token delimited by whitespace or new line
[ scanner
scanUpToCharactersFromSet:whitespaceSet
intoString:&scanString ] ;
// Add it to the array
[ keywordArray addObject:scanString ] ;
NSLog( @"*" ) ;
} // while the scanner ain't done
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden