sanitizedArguments fixes

Various style fixes
Don't use the foreach loop as it might break on old gcc/objc runtimes
Release sanitizedArguments in dealloc
pull/7/head
Jean Raby 2013-01-14 16:58:19 -05:00
parent 55ccd0e83f
commit 8fc53ea1d7
1 changed files with 13 additions and 4 deletions

View File

@ -22,6 +22,7 @@
#import <Foundation/NSArray.h> #import <Foundation/NSArray.h>
#import <Foundation/NSCharacterSet.h> #import <Foundation/NSCharacterSet.h>
#import <Foundation/NSDictionary.h>
#import <Foundation/NSString.h> #import <Foundation/NSString.h>
#import <Foundation/NSUserDefaults.h> #import <Foundation/NSUserDefaults.h>
@ -76,15 +77,21 @@
- (void) setSanitizedArguments: (NSArray *) newArguments - (void) setSanitizedArguments: (NSArray *) newArguments
{ {
NSCharacterSet *whitespaces = [NSCharacterSet whitespaceCharacterSet];
NSString *argsString = [newArguments componentsJoinedByString:@" "]; NSString *argsString = [newArguments componentsJoinedByString:@" "];
NSDictionary *cliArguments; NSDictionary *cliArguments;
NSArray *keys;
int i;
argsString = [newArguments componentsJoinedByString:@" "];
/* Remove NSArgumentDomain -key value from the arguments */ /* Remove NSArgumentDomain -key value from the arguments */
cliArguments = [[NSUserDefaults standardUserDefaults] cliArguments = [[NSUserDefaults standardUserDefaults]
volatileDomainForName:NSArgumentDomain]; volatileDomainForName:NSArgumentDomain];
for (NSString *k in cliArguments) keys = [cliArguments allKeys];
for (i=0; i < [keys count]; i++)
{ {
NSString *k = [keys objectAtIndex: i];
NSString *v = [cliArguments objectForKey:k]; NSString *v = [cliArguments objectForKey:k];
NSString *argPair = [NSString stringWithFormat:@"-%@ %@", k, v]; NSString *argPair = [NSString stringWithFormat:@"-%@ %@", k, v];
argsString = [argsString stringByReplacingOccurrencesOfString: argPair argsString = [argsString stringByReplacingOccurrencesOfString: argPair
@ -93,7 +100,8 @@
if ([argsString length]) if ([argsString length])
{ {
/* dance to compact whitespace */ /* dance to compact whitespace */
NSArray *wordsWP = [argsString componentsSeparatedByCharactersInSet: whitespaces]; NSArray *wordsWP = [argsString componentsSeparatedByCharactersInSet:
[NSCharacterSet whitespaceCharacterSet]];
NSMutableArray *words = [NSMutableArray array]; NSMutableArray *words = [NSMutableArray array];
for (NSString *word in wordsWP) for (NSString *word in wordsWP)
{ {
@ -107,7 +115,7 @@
} }
else else
{ {
ASSIGN (sanitizedArguments, nil); DESTROY(sanitizedArguments);
} }
} }
@ -120,6 +128,7 @@
- (void) dealloc - (void) dealloc
{ {
[arguments release]; [arguments release];
[sanitizedArguments release];
[super dealloc]; [super dealloc];
} }