Line data Source code
1 0 : /* 2 : 3 : NSScannerOOExtensions.m 4 : 5 : Oolite 6 : Copyright (C) 2004-2013 Giles C Williams and contributors 7 : 8 : This program is free software; you can redistribute it and/or 9 : modify it under the terms of the GNU General Public License 10 : as published by the Free Software Foundation; either version 2 11 : of the License, or (at your option) any later version. 12 : 13 : This program is distributed in the hope that it will be useful, 14 : but WITHOUT ANY WARRANTY; without even the implied warranty of 15 : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 : GNU General Public License for more details. 17 : 18 : You should have received a copy of the GNU General Public License 19 : along with this program; if not, write to the Free Software 20 : Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 21 : MA 02110-1301, USA. 22 : 23 : */ 24 : 25 : #import "NSScannerOOExtensions.h" 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