Permalink
Browse files

[Issue #177] fix the stuffs

  • Loading branch information...
1 parent 978f1cc commit 47aadc102109ede62c6a60cf9a6634ed86e1cb0b Jigish Patel committed Dec 4, 2012
Showing with 35 additions and 4 deletions.
  1. +1 −0 Slate/ScreenWrapper.m
  2. +4 −2 Slate/SlateConfig.m
  3. +20 −2 Slate/StringTokenizer.m
  4. +10 −0 SlateTests/TestStringTokenizer.m
@@ -86,6 +86,7 @@ + (void)updateScreenResolutions:(NSArray *)theScreens {
}
+ (void)updateStatics {
+ SlateLogger(@"-- updateStatics");
[ScreenWrapper updateLeftToRightToDefault];
[ScreenWrapper updateScreenResolutions];
}
View
@@ -50,8 +50,10 @@ @implementation SlateConfig
+ (SlateConfig *)getInstance {
@synchronized([SlateConfig class]) {
- if (!_instance)
+ if (!_instance) {
+ [ScreenWrapper updateStatics];
_instance = [[[SlateConfig class] alloc] init];
+ }
return _instance;
}
}
@@ -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]];
@@ -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) {
@@ -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]];
}
@@ -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) {
@@ -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]];
}
@@ -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.