bug-gnustep
[Top][All Lists]
Advanced

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

Re: Bug in NSScanner ?


From: Richard Frith-Macdonald
Subject: Re: Bug in NSScanner ?
Date: Wed, 19 Feb 2003 10:41:52 +0000


On Wednesday, February 19, 2003, at 09:51  am, Manuel Guesdon wrote:

Hi,

I can't understand why this fail

NSString* str=@"( 1.3.6.1.4.1.4980.1.3.3 NAME 'oxyInetDomain' DESC 'Oxymium Inet Domain' SUP oxyTop AUXILIARY MUST dc MAY ( admContact $ admincontact $ billingContact $ cn $ domainCreationDate $ labeledURL $ mailRelayedBy $ managerEMail $ nic $ nichandle $ registrant $ soa $ techContact $ domaindescription $ oxymiumReferenceDisplay $ associatedServices $ associatedrootentity $ associatedmanagemententity $ associatedrootcompany $ associatedmanagemententityrights $ associatedrootentityrights $ associatedrootcompanyrights $ parkmessage $ logoURL ) )";
      NSScanner *aScanner = [NSScanner scannerWithString:str];

      if (0)     // If 1, it works !
        {
          BOOL upTo1=[aScanner scanUpToString:@"MUST "
                               intoString:NULL];
          NSLog(@"upTo1=%d",upTo1);
          if (upTo1)
            {
              BOOL scan1=[aScanner scanString:@"MUST "
                                   intoString:NULL];
              NSLog(@"scan1=%d",scan1);
              if (scan1)
                {
                  NSString* must=nil;
                  [aScanner scanUpToString:@" "
                            intoString:&must];
                }
            };
        };
      NSLog(@"scanLocation=%u",[aScanner scanLocation]);
NSLog(@"scan=[%@]",[[aScanner string] substringFromIndex:[aScanner scanLocation]]);
      BOOL upTo2=[aScanner scanUpToString:@"MAY "
                          intoString:NULL];
      NSLog(@"upTo2=%d",upTo2);
      if (upTo2)
        {
          BOOL scan2=[aScanner scanString:@"MAY "
                          intoString:NULL];
          NSLog(@"scan2=%d",scan2);
        };


I try to scan str for differents components. If I scan directly up to MAY, it works. If I scan for must and next scan
for may, it doesn't works.
May be my code is wrong but I can't see why :-)

After you scan the word 'MUST', you then tell the scanner to scan up to a space .... but a space is in the set of characters to be skipped, and the MacOS-X documentation of -charactersToBeSkipped says that behavior in this case is undefined. In fact the GNUstep behavior is well-defined ... characters from this set are always skipped before scanning starts, even if you are scanning for something thsst is in the set. The scan location is at a space (which is skipped) then everything up to the next space is scanned, leaving the scan location at the space immediately before 'MAY'

Next you say to scan up to 'MAY' ... so the space at the scan location is skipped, then the scanner encounters 'MAY', so no characters are scanned and the method returns NO.

You use this return status to decide whether to scan in 'MAY', and because it is NO you don't scan it in.

So ... it's all working as documented ... and I believe this is also how MacOS-X works.





reply via email to

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