Re: NSScanner problem...
Re: NSScanner problem...
- Subject: Re: NSScanner problem...
- From: Jeff LaMarche <email@hidden>
- Date: Sat, 2 Aug 2003 21:30:32 -0400
Sorry - should have done a little more research before I wrote. I've
got it figured out now.
On Saturday, August 2, 2003, at 08:54 PM, Jeff LaMarche wrote:
I'm trying to use an NSScanner to process the contents of an NSString
line by line. The problem is that it seems to skip empty lines, which
is a problem since blank lines separate sections. Here's my code,
which is from a category on NSString - I'm trying to break out of the
loop when I get to an empty line because I only want the header:
-(NSString *)parseHeader
{
NSMutableString *ret = [NSMutableString stringWithString:@""];
NSScanner *scanner = [NSScanner scannerWithString:self];
NSCharacterSet *newlineSet = [NSCharacterSet
characterSetWithCharactersInString:@"\r\n"];
NSCharacterSet *whitespaceSet = [NSCharacterSet
whitespaceCharacterSet];
while ([scanner isAtEnd] == NO)
{
NSString *oneLine = nil;
[scanner scanUpToCharactersFromSet:newlineSet intoString:&oneLine];
oneLine = [oneLine stringByTrimmingCharactersInSet:whitespaceSet];
if ([oneLine isEqualTo:@""])
return ret;
[ret appendString:oneLine];
}
return ret;
}
So, if I have an NSString that looks like this:
one line of text.
A second line of text.
A third line of text.
A fourth line of text.
My loop never sees the blank line.. it just skips over if it as if it
didn't exist. I saw a reference on the mailing list to using the
setCharactersToBeSkipped method of NSScanner, like so:
[theScanner setCharactersToBeSkipped:[NSCharacterSet
emptyCharacterSet]];
but emptyCharacterSet is not a delivered class method and when I tried
to simulate the behavior like this:
[scanner setCharactersToBeSkipped:[NSCharacterSet
characterSetWithCharactersInString:@""]];
But got a SIGTRAP..
If anyone has any thoughts, I'd love to hear them, as I'm stumped and
am about to abandon NSScanner in favor of some other solution. I could
understand having the opposite problem if my string had CRLFs, but I
can't figure out why this would be happening.
Thanks as always,
Jeff
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.