bugGNUstep - Bugs: bug #3301, NSScanner can't scan ']' properly ?

 
 

You are not allowed to post comments on this tracker with your current authentication level.

bug #3301: NSScanner can't scan ']' properly ?

Submitted by:  -Deleted Account- <yjchen>
Submitted on:  Tue 22 Apr 2003 12:52:34 PM UTC  
 
Category: Base/FoundationSeverity: 3 - Normal
Item Group: BugStatus: Invalid
Privacy: PublicAssigned to: None
Open/Closed: Closed

Fri 25 Apr 2003 06:35:45 AM UTC, comment #2:

Not a bug in NSScanner, which is performing correctly and as documented. I did commit a small change to the documentation in CVS in the hope of clarifying, but it was already quite clear.

Here is an example of how the code should have been written if the idea was to count the number of ocurrances of a a string in a file.

#include <Foundation/Foundation.h>

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

NSString *string = [NSString stringWithContentsOfFile: @"NSMatrix.m"];
NSScanner *scanner = [NSScanner scannerWithString: string];
NSString *ch = @"[";
unsigned total = 0;

[scanner scanUpToString: ch intoString: NULL];
while ([scanner scanString: ch intoString: NULL] == YES)
{
total++;
[scanner scanUpToString: ch intoString: NULL];
}

NSLog(@"total %d", total);

RELEASE(pool);
return 0;
}

Richard Frith-Macdonald <CaS>
Project Member
Tue 22 Apr 2003 03:19:00 PM UTC, comment #1:

Not a bug in NSScanner, which is performing correctly and as documented. I did commit a small change to the documentation in CVS in the hope of clarifying, but it was already quite clear.

Here is an example of how the code should have been written if the idea was to count the number of ocurrances of a a string in a file.

#include <Foundation/Foundation.h>

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

NSString *string = [NSString stringWithContentsOfFile: @"NSMatrix.m"];
NSScanner *scanner = [NSScanner scannerWithString: string];
NSString *ch = @"[";
unsigned total = 0;

[scanner scanUpToString: ch intoString: NULL];
while ([scanner scanString: ch intoString: NULL] == YES)
{
total++;
[scanner scanUpToString: ch intoString: NULL];
}

NSLog(@"total %d", total);

RELEASE(pool);
return 0;
}

Richard Frith-Macdonald <CaS>
Project Member
Tue 22 Apr 2003 12:52:34 PM UTC, original submission:

I try to use NSScanner to count the number of '{', '}', '[', ']', '\n', etc.,
and the result is unexpected.
It happens specially for ']' and ')'.
Below is a test code.
Did I do something wrong ?
I also try scanString rather than scanUpToString, and it got worse.
Is there any limitation for NSScanner, such as special character ?

Thanx.

Yen-Ju

#include <AppKit/AppKit.h>

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

NSString *string = [NSString stringWithContentsOfFile: @"NSMatrix.m"];
NSScanner *scanner = [NSScanner scannerWithString: string];
NSString *ch = @"[";
BOOL result = YES;
unsigned location = 0;
unsigned total = 0;

while(result)
{
[scanner setScanLocation: location];
result = [scanner scanUpToString: ch intoString: NULL];
location = [scanner scanLocation];
if (location >= [string length])
break;
location++;
total++
}

NSLog(@"total %d", total);

RELEASE(pool);
return 0;
}

-Deleted Account- <yjchen>

 

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

CC list is empty

 

Do you think this task is very important?
If so, you can click here to add your encouragement to it.
This task has 0 encouragements so far.

Only logged-in users can vote.

 

Please enter the title of George Orwell's famous dystopian book (it's a date):

 

 

Follow 5 latest changes.

Date Changed By Updated Field Previous Value => Replaced By
Sun 22 May 2005 11:17:16 PM UTCFredKieferOpen/ClosedDeclined=>Closed
Tue 24 Aug 2004 08:26:27 AM UTCCaSAssigned toCaS=>None
Fri 16 May 2003 09:17:45 AM UTCCaSStatusNone=>(Error - Not Found)
Tue 22 Apr 2003 03:19:00 PM UTCCaSAssigned toNone=>NA
  Open/ClosedOpen=>(Error - Not Found)

Back to the top


Powered by Savane 3.1-cleanup1