• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Infinite loop in NSScanner
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Follow-Ups:
    • Re: Infinite loop in NSScanner
      • From: Prachi Gauriar <email@hidden>
  • Prev by Date: Re: Null result from NSArray objectAtIndex (Solved)
  • Next by Date: To Framework or to Dylib?
  • Previous by thread: Re: Null result from NSArray objectAtIndex (Solved)
  • Next by thread: Re: Infinite loop in NSScanner
  • Index(es):
    • Date
    • Thread