Oolite 1.91.0.7645-241119-222d325
Loading...
Searching...
No Matches
NSScannerOOExtensions.m
Go to the documentation of this file.
1/*
2
3NSScannerOOExtensions.m
4
5Oolite
6Copyright (C) 2004-2013 Giles C Williams and contributors
7
8This program is free software; you can redistribute it and/or
9modify it under the terms of the GNU General Public License
10as published by the Free Software Foundation; either version 2
11of the License, or (at your option) any later version.
12
13This program is distributed in the hope that it will be useful,
14but WITHOUT ANY WARRANTY; without even the implied warranty of
15MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16GNU General Public License for more details.
17
18You should have received a copy of the GNU General Public License
19along with this program; if not, write to the Free Software
20Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
21MA 02110-1301, USA.
22
23*/
24
26
27
28@implementation NSScanner (OOExtensions)
29
30- (BOOL) ooliteScanCharactersFromSet:(NSCharacterSet *)set intoString:(NSString **)value
31{
32 NSUInteger currentLocation = [self scanLocation];
33 NSRange matchedRange = NSMakeRange( currentLocation, 0);
34 NSString *scanString = [self string];
35 NSUInteger scanLength = [scanString length];
36
37 while ((currentLocation < scanLength)&&([set characterIsMember:[scanString characterAtIndex:currentLocation]]))
38 {
39 currentLocation++;
40 }
41
42 [self setScanLocation:currentLocation];
43
44 matchedRange.length = currentLocation - matchedRange.location;
45
46 if (!matchedRange.length) return NO;
47
48 if (value != NULL)
49 {
50 *value = [scanString substringWithRange:matchedRange];
51 }
52
53 return YES;
54}
55
56
57- (BOOL) ooliteScanUpToCharactersFromSet:(NSCharacterSet *)set intoString:(NSString **)value
58{
59 NSUInteger currentLocation = [self scanLocation];
60 NSRange matchedRange = NSMakeRange( currentLocation, 0);
61 NSString *scanString = [self string];
62 NSUInteger scanLength = [scanString length];
63
64 while ((currentLocation < scanLength)&&(![set characterIsMember:[scanString characterAtIndex:currentLocation]]))
65 {
66 currentLocation++;
67 }
68
69 [self setScanLocation:currentLocation];
70
71 matchedRange.length = currentLocation - matchedRange.location;
72
73 if (!matchedRange.length) return NO;
74
75 if (value != NULL)
76 {
77 *value = [scanString substringWithRange:matchedRange];
78 }
79
80 return YES;
81}
82
83@end