Changeset 2310
- Timestamp:
- 02/13/05 21:58:30 (4 years ago)
- Files:
-
- trunk/NSScannerAdditions.m (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/NSScannerAdditions.m
r2305 r2310 1 //2 // NSScannerAdditions.m3 // Colloquy4 //5 1 // Created by Kevin Ballard on 2/12/05. 6 2 // Copyright 2005 Kevin Ballard. All rights reserved. 7 //8 3 9 4 #import "NSScannerAdditions.h" 10 5 11 6 @implementation NSScanner (NSScannerAdditions) 12 - (BOOL)scanCharacterInto:(unichar *)unicharValue 13 { 7 - (BOOL) scanCharacterInto:(unichar *) unicharValue { 14 8 if( ! [self isAtEnd] ) { 15 9 unsigned location = [self scanLocation]; 16 10 *unicharValue = [[self string] characterAtIndex:location]; 17 [self setScanLocation: location + 1];11 [self setScanLocation:( location + 1 )]; 18 12 return YES; 19 13 } 14 20 15 return NO; 21 16 } 22 17 23 - (BOOL)scanStringLength:(int)maxLength intoString:(NSString **)stringValue 24 { 18 - (BOOL) scanStringLength:(int) maxLength intoString:(NSString **) stringValue { 25 19 if( ! [self isAtEnd] ) { 26 20 unsigned location = [self scanLocation]; … … 28 22 int length = MIN( maxLength, [source length] - location ); 29 23 if( length > 0 ) { 30 *stringValue = [[self string] substringWithRange:NSMakeRange( location, length)];31 [self setScanLocation: location+length];24 *stringValue = [[self string] substringWithRange:NSMakeRange( location, length )]; 25 [self setScanLocation:( location + length )]; 32 26 return YES; 33 27 } 34 28 } 29 35 30 return NO; 36 31 } 37 32 38 - (BOOL)scanCharactersFromSet:(NSCharacterSet *)scanSet maxLength:(int)maxLength 39 intoString:(NSString **)stringValue 40 { 33 - (BOOL) scanCharactersFromSet:(NSCharacterSet *) scanSet maxLength:(int) maxLength intoString:(NSString **) stringValue { 41 34 if( ! [self isAtEnd] ) { 42 35 unsigned location = [self scanLocation]; … … 44 37 int length = MIN( maxLength, [source length] - location ); 45 38 if( length > 0 ) { 46 unichar *chars = calloc( length, sizeof(unichar) ); 47 [source getCharacters:chars range:NSMakeRange(location, length)]; 48 unsigned i; 49 for( i = 0; i < length && [scanSet characterIsMember:chars[i]]; i++) ; 39 unichar *chars = calloc( length, sizeof( unichar ) ); 40 [source getCharacters:chars range:NSMakeRange( location, length )]; 41 42 unsigned i = 0; 43 for( i = 0; i < length && [scanSet characterIsMember:chars[i]]; i++ ); 44 45 free( chars ); 46 50 47 if( i > 0 ) { 51 *stringValue = [source substringWithRange:NSMakeRange( location, i)];52 [self setScanLocation: location+i];48 *stringValue = [source substringWithRange:NSMakeRange( location, i )]; 49 [self setScanLocation:( location + i )]; 53 50 return YES; 54 51 } 55 52 } 56 53 } 54 57 55 return NO; 58 56 }
