Oolite
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@implementation NSScanner (OOExtensions)
28
29- (BOOL)ooliteScanCharactersFromSet:(NSCharacterSet*)set intoString:(NSString**)value
30{
31 NSUInteger currentLocation = [self scanLocation];
32 NSRange matchedRange = NSMakeRange(currentLocation, 0);
33 NSString* scanString = [self string];
34 NSUInteger scanLength = [scanString length];
35
36 while ((currentLocation < scanLength) && ([set characterIsMember:[scanString characterAtIndex:currentLocation]])) {
37 currentLocation++;
38 }
39
40 [self setScanLocation:currentLocation];
41
42 matchedRange.length = currentLocation - matchedRange.location;
43
44 if (!matchedRange.length)
45 return NO;
46
47 if (value != NULL) {
48 *value = [scanString substringWithRange:matchedRange];
49 }
50
51 return YES;
52}
53
54- (BOOL)ooliteScanUpToCharactersFromSet:(NSCharacterSet*)set intoString:(NSString**)value
55{
56 NSUInteger currentLocation = [self scanLocation];
57 NSRange matchedRange = NSMakeRange(currentLocation, 0);
58 NSString* scanString = [self string];
59 NSUInteger scanLength = [scanString length];
60
61 while ((currentLocation < scanLength) && (![set characterIsMember:[scanString characterAtIndex:currentLocation]])) {
62 currentLocation++;
63 }
64
65 [self setScanLocation:currentLocation];
66
67 matchedRange.length = currentLocation - matchedRange.location;
68
69 if (!matchedRange.length)
70 return NO;
71
72 if (value != NULL) {
73 *value = [scanString substringWithRange:matchedRange];
74 }
75
76 return YES;
77}
78
79@end