Changeset 2310

Show
Ignore:
Timestamp:
02/13/05 21:58:30 (4 years ago)
Author:
timothy
Message:

Fixes a memory leak in scanCharactersFromSet.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/NSScannerAdditions.m

    r2305 r2310  
    1 // 
    2 //  NSScannerAdditions.m 
    3 //  Colloquy 
    4 // 
    51//  Created by Kevin Ballard on 2/12/05. 
    62//  Copyright 2005 Kevin Ballard. All rights reserved. 
    7 // 
    83 
    94#import "NSScannerAdditions.h" 
    105 
    116@implementation NSScanner (NSScannerAdditions) 
    12 - (BOOL)scanCharacterInto:(unichar *)unicharValue 
    13 
     7- (BOOL) scanCharacterInto:(unichar *) unicharValue { 
    148        if( ! [self isAtEnd] ) { 
    159                unsigned location = [self scanLocation]; 
    1610                *unicharValue = [[self string] characterAtIndex:location]; 
    17                 [self setScanLocation:location + 1]; 
     11                [self setScanLocation:( location + 1 )]; 
    1812                return YES; 
    1913        } 
     14 
    2015        return NO; 
    2116} 
    2217 
    23 - (BOOL)scanStringLength:(int)maxLength intoString:(NSString **)stringValue 
    24 
     18- (BOOL) scanStringLength:(int) maxLength intoString:(NSString **) stringValue { 
    2519        if( ! [self isAtEnd] ) { 
    2620                unsigned location = [self scanLocation]; 
     
    2822                int length = MIN( maxLength, [source length] - location ); 
    2923                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 )]; 
    3226                        return YES; 
    3327                } 
    3428        } 
     29 
    3530        return NO; 
    3631} 
    3732 
    38 - (BOOL)scanCharactersFromSet:(NSCharacterSet *)scanSet maxLength:(int)maxLength 
    39                                    intoString:(NSString **)stringValue 
    40 
     33- (BOOL) scanCharactersFromSet:(NSCharacterSet *) scanSet maxLength:(int) maxLength intoString:(NSString **) stringValue { 
    4134        if( ! [self isAtEnd] ) { 
    4235                unsigned location = [self scanLocation]; 
     
    4437                int length = MIN( maxLength, [source length] - location ); 
    4538                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 
    5047                        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 )]; 
    5350                                return YES; 
    5451                        } 
    5552                } 
    5653        } 
     54 
    5755        return NO; 
    5856}