bug-gnustep
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Bug #3301] NSScanner can't scan ']' properly ?


From: nobody
Subject: [Bug #3301] NSScanner can't scan ']' properly ?
Date: Tue, 22 Apr 2003 11:19:01 -0400

=================== BUG #3301: LATEST MODIFICATIONS ==================
http://savannah.gnu.org/bugs/?func=detailbug&bug_id=3301&group_id=99

Changes by: Richard Frith-Macdonald <rfm@gnu.org>
Date: Tue 04/22/2003 at 15:19 (GMT)

            What     | Removed                   | Added
---------------------------------------------------------------------------
         Assigned to | None                      | CaS
              Status | Open                      | Declined


------------------ Additional Follow-up Comments ----------------------------
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; 
} 




=================== BUG #3301: FULL BUG SNAPSHOT ===================


Submitted by: yjchen                  Project: GNUstep                      
Submitted on: Tue 04/22/2003 at 12:52
Category:  Base/Foundation            Severity:  5 - Major                  
Bug Group:  Bug                       Resolution:  None                     
Assigned to:  CaS                     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: Tue 04/22/2003 at 15:19       By: 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; 
} 



CC list is empty


No files currently attached


For detailed info, follow this link:
http://savannah.gnu.org/bugs/?func=detailbug&bug_id=3301&group_id=99




reply via email to

[Prev in Thread] Current Thread [Next in Thread]