[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[bugs #3301] NSScanner can't scan ']' properly ?
From: |
Richard Frith-Macdonald |
Subject: |
[bugs #3301] NSScanner can't scan ']' properly ? |
Date: |
Tue, 24 Aug 2004 06:27:14 -0400 |
User-agent: |
Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7.1) Gecko/20040802 Debian/1.7.1-5 |
This mail is an automated notification from the bugs tracker
of the project: GNUstep.
/**************************************************************************/
[bugs #3301] Latest Modifications:
Changes by:
Richard Frith-Macdonald <rfm@gnu.org>
'Date:
Tue 08/24/04 at 08:26 (GMT)
What | Removed | Added
---------------------------------------------------------------------------
Assigned to | CaS | None
/**************************************************************************/
[bugs #3301] Full Item Snapshot:
URL: <http://savannah.gnu.org/bugs/?func=detailitem&item_id=3301>
Project: GNUstep
Submitted by: Yen-Ju Chen
On: Tue 04/22/03 at 12:52
Category: Base/Foundation
Severity: 5 - Average
Item Group: Bug
Resolution: Invalid
Privacy: Public
Assigned to: None
Status: Declined
Summary: NSScanner can't scan ']' properly ?
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;
}
Follow-up Comments
------------------
-------------------------------------------------------
Date: Fri 04/25/03 at 06:35 By: Richard Frith-Macdonald <CaS>
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;
}
-------------------------------------------------------
Date: Tue 04/22/03 at 15:19 By: Richard Frith-Macdonald <CaS>
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;
}
For detailed info, follow this link:
<http://savannah.gnu.org/bugs/?func=detailitem&item_id=3301>
_______________________________________________
Message sent via/by Savannah
http://savannah.gnu.org/
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [bugs #3301] NSScanner can't scan ']' properly ?,
Richard Frith-Macdonald <=