• 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
Did I find a NSScanner bug, or am I doing this all wrong?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Did I find a NSScanner bug, or am I doing this all wrong?


  • Subject: Did I find a NSScanner bug, or am I doing this all wrong?
  • From: Britt Durbrow <email@hidden>
  • Date: Sun, 21 Sep 2008 23:15:05 -0700

Hi --

I'm getting some really odd behavior out of NSScanner; it seems to be choking on character sets that only have whitespace in them.

This doesn't work:

#import <Foundation/Foundation.h>

int main (int argc, const char * argv[])
{
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];

NSString *test=@" ooxxdk";
NSCharacterSet *whiteSpaceCharSet=[NSCharacterSet characterSetWithCharactersInString:@"\t\r\n "];

NSScanner *scanner=[NSScanner scannerWithString:test];


NSLog(@"location before: %d", [scanner scanLocation]);
BOOL result=[scanner scanCharactersFromSet:whiteSpaceCharSet intoString:nil];
NSLog(@"location after: %d", [scanner scanLocation]);
NSLog(@"result returned: %d",result);

[pool drain];
return 0;
}


... it logs this:
2008-09-21 22:58:28.399 foo[804:10b] location before: 0
2008-09-21 22:58:28.401 foo[804:10b] location after: 0
2008-09-21 22:58:28.401 foo[804:10b] result returned: 0

I expected it to log something like this:
2008-09-21 23:01:31.357 foo[844:10b] location before: 0
2008-09-21 23:01:31.359 foo[844:10b] location after: 3
2008-09-21 23:01:31.360 foo[844:10b] result returned: 1


But, changing it like so:

NSString *test=@" aooxxdk";
NSCharacterSet *whiteSpaceCharSet=[[NSCharacterSet characterSetWithCharactersInString:@"\t\r\n a"] retain];


does work... logging this:

2008-09-21 23:01:31.357 foo[844:10b] location before: 0
2008-09-21 23:01:31.359 foo[844:10b] location after: 4
2008-09-21 23:01:31.360 foo[844:10b] result returned: 1

I get similar results swapping tabs and/or cr's for the leading spaces on the test string; as well as using the standard [NSCharacterSet whitespaceAndNewlineCharacterSet].

Anybody have any ideas why this isn't working?


_______________________________________________

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


  • Follow-Ups:
    • Re: Did I find a NSScanner bug, or am I doing this all wrong?
      • From: "Stephen J. Butler" <email@hidden>
  • Prev by Date: Re: Listening for changes in a table
  • Next by Date: Re: Programmatically inserting text into NSTextView and scrolling
  • Previous by thread: Re: Programmatically inserting text into NSTextView and scrolling
  • Next by thread: Re: Did I find a NSScanner bug, or am I doing this all wrong?
  • Index(es):
    • Date
    • Thread