RE: NSScanner know-how
RE: NSScanner know-how
- Subject: RE: NSScanner know-how
- From: "Jonathan E. Jackel" <email@hidden>
- Date: Wed, 23 Jul 2003 18:36:58 -0400
You keep scanning for id_origin, round and round in a loop. The first time
through the scanner finds it and it works. The next time through it
doesn't. Since the first condition in your if() is false, and the three
conditions are conjunctive, I believe that C simply stops evaluating the
other conditions. It knows right away that the statement as a whole is
false, so what's the point of evaluating the rest? As a result, your
scanner never advances, so it never gets to the end, and you get stuck in an
endless loop.
Personally, I like to unpack my scanner code and actually assign the results
to a BOOL. E.g.:
BOOL okay;
okay = [scanner scanString:id_origin intoString:NULL];
NSLog(@"Scan location:%d", [scanner scanLocation]);
okay = [scanner scanUpToCharactersFromSet:semicolonSet intoString:&id_sql];
etc.
Makes debugging a lot easier, let me tell you.
Jonathan
>
-----Original Message-----
>
From: email@hidden
>
[mailto:email@hidden]On Behalf Of Sanri Parov
>
Sent: Wednesday, July 23, 2003 6:02 PM
>
To: email@hidden
>
Subject: NSScanner know-how
>
>
>
Hi everybody,
>
>
I'm in little trouble with NSScanner, just because it's not well
>
documented IMHO in the developer docs.
>
Given this puny little source text:
>
>
#id:15;
>
#customer:F.lli Remari;
>
#phone:123456789;
>
#cell:13456;
>
#fax:987987;
>
#id:16;
>
#customer:Zanovello Nicola;
>
#phone:456789;
>
#cell:;
>
#fax:12356;
>
>
I'd like to import the right-values to some variables.
>
Here's the source I've done by copying the example from the docs...
>
>
NSString* id_origin = @"#id:";
>
NSStrign* id_sql;
>
NSCharacterSet *semicolonSet;
>
NSScanner *scanner;
>
semicolonSet = [NSCharacterSet characterSetWithCharactersInString:@";"];
>
scanner = [NSScanner scannerWithString:stringa_da_file];
>
>
>
while ([scanner isAtEnd] == NO)
>
{
>
if([scanner scanString:id_origin intoString:NULL] && [scanner
>
scanUpToCharactersFromSet:semicolonSet intoString:&id_sql] && [scanner
>
scanString:@";" intoString:NULL])
>
NSLog(@"%@",id_sql);
>
}
>
>
>
.. but the whole routine hangs after having seen the first ID.
>
Maybe it's just because I'm very tired and sleepy, but I can't see the
>
point.
>
Any help is really appreciated.
>
>
--
>
Sanri Parov
>
_______________________________________________
>
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.