Skip to content

Commit

Permalink
[Issue #177] fix the stuffs
Browse files Browse the repository at this point in the history
  • Loading branch information
Jigish Patel committed Dec 4, 2012
1 parent 978f1cc commit 47aadc1
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 4 deletions.
1 change: 1 addition & 0 deletions Slate/ScreenWrapper.m
Expand Up @@ -86,6 +86,7 @@ + (void)updateScreenResolutions:(NSArray *)theScreens {
}

+ (void)updateStatics {
SlateLogger(@"-- updateStatics");
[ScreenWrapper updateLeftToRightToDefault];
[ScreenWrapper updateScreenResolutions];
}
Expand Down
6 changes: 4 additions & 2 deletions Slate/SlateConfig.m
Expand Up @@ -50,8 +50,10 @@ @implementation SlateConfig

+ (SlateConfig *)getInstance {
@synchronized([SlateConfig class]) {
if (!_instance)
if (!_instance) {
[ScreenWrapper updateStatics];
_instance = [[[SlateConfig class] alloc] init];
}
return _instance;
}
}
Expand Down Expand Up @@ -312,7 +314,7 @@ - (BOOL)append:(NSString *)configString {
// alias <name> <value>
@try {
[self addAlias:line];
SlateLogger(@" LoadingL: %@",line);
SlateLogger(@" LoadingA: %@",line);
} @catch (NSException *ex) {
SlateLogger(@" ERROR %@",[ex name]);
NSAlert *alert = [SlateConfig warningAlertWithKeyEquivalents: [NSArray arrayWithObjects:@"Quit", @"Skip", nil]];
Expand Down
22 changes: 20 additions & 2 deletions Slate/StringTokenizer.m
Expand Up @@ -51,6 +51,7 @@ + (void)tokenize:(NSString *)s into:(NSMutableArray *)array {
+ (void)tokenize:(NSString *)s into:(NSMutableArray *)array quoteChars:(NSCharacterSet *)quotes {
NSMutableString *token = [[NSMutableString alloc] initWithCapacity:10];
BOOL quoteSeen = NO;
char quoteChar = '.';
for (NSInteger i = 0; i < [s length]; i++) {
if ([self isSpaceChar:[s characterAtIndex:i]]) {
if (![token isEqualToString:@""] && !quoteSeen) {
Expand All @@ -60,7 +61,15 @@ + (void)tokenize:(NSString *)s into:(NSMutableArray *)array quoteChars:(NSCharac
[token appendFormat:@"%C", [s characterAtIndex:i]];
}
} else if ([self isQuoteChar:[s characterAtIndex:i] quoteChars:quotes]) {
quoteSeen = !quoteSeen;
if (!quoteSeen) {
quoteSeen = !quoteSeen;
quoteChar = [s characterAtIndex:i];
} else if (quoteSeen && [s characterAtIndex:i] == quoteChar) {
quoteSeen = !quoteSeen;
quoteChar = '.';
} else {
[token appendFormat:@"%C", [s characterAtIndex:i]];
}
} else {
[token appendFormat:@"%C", [s characterAtIndex:i]];
}
Expand Down Expand Up @@ -104,6 +113,7 @@ + (void)tokenize:(NSString *)s into:(NSMutableArray *)array maxTokens:(NSInteger
NSInteger numTokens = 0;
NSMutableString *token = [[NSMutableString alloc] initWithCapacity:10];
BOOL quoteSeen = NO;
unichar quoteChar = '.';
for (NSInteger i = 0; i < [s length]; i++) {
if ([self isSpaceChar:[s characterAtIndex:i]]) {
if (![token isEqualToString:@""] && numTokens < (maxTokens-1) && !quoteSeen) {
Expand All @@ -116,7 +126,15 @@ + (void)tokenize:(NSString *)s into:(NSMutableArray *)array maxTokens:(NSInteger
} else if (numTokens >= (maxTokens-1)) {
[token appendFormat:@"%C", [s characterAtIndex:i]];
} else if ([self isQuoteChar:[s characterAtIndex:i] quoteChars:quotes]) {
quoteSeen = !quoteSeen;
if (!quoteSeen) {
quoteSeen = !quoteSeen;
quoteChar = [s characterAtIndex:i];
} else if (quoteSeen && [s characterAtIndex:i] == quoteChar) {
quoteSeen = !quoteSeen;
quoteChar = '.';
} else {
[token appendFormat:@"%C", [s characterAtIndex:i]];
}
} else {
[token appendFormat:@"%C", [s characterAtIndex:i]];
}
Expand Down
10 changes: 10 additions & 0 deletions SlateTests/TestStringTokenizer.m
Expand Up @@ -129,6 +129,16 @@ - (void)testTokenizeIntoMaxTokensQuoteChars {
STAssertTrue([arr count] == 2, @"shit should work");
STAssertTrue([[arr objectAtIndex:0] isEqualToString:@"hi"], @"work damnit");
STAssertTrue([[arr objectAtIndex:1] isEqualToString:@"tokenize\t\t me"], @"wtf");
arr = [NSMutableArray array];
[StringTokenizer tokenize:@"hi 'tokenize\t\t \"me\"'" into:arr maxTokens:100 quoteChars:cs];
STAssertTrue([arr count] == 2, @"shit should work");
STAssertTrue([[arr objectAtIndex:0] isEqualToString:@"hi"], @"work damnit");
STAssertTrue([[arr objectAtIndex:1] isEqualToString:@"tokenize\t\t \"me\""], @"wtf");
arr = [NSMutableArray array];
[StringTokenizer tokenize:@"hi 'tokenize\t\t \"me\"'" into:arr quoteChars:cs];
STAssertTrue([arr count] == 2, @"shit should work");
STAssertTrue([[arr objectAtIndex:0] isEqualToString:@"hi"], @"work damnit");
STAssertTrue([[arr objectAtIndex:1] isEqualToString:@"tokenize\t\t \"me\""], @"wtf");
}

@end

0 comments on commit 47aadc1

Please sign in to comment.