Last active
October 8, 2015 17:38
-
-
Save Wevah/3365918 to your computer and use it in GitHub Desktop.
Pipe Parse
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import <Foundation/Foundation.h> | |
int main(int argc, char *argv[]) { | |
@autoreleasepool { | |
NSString *str = @"foo|bar|baz\\|quux"; | |
BOOL lastWasBackslash = NO; | |
NSMutableString *sub = [NSMutableString string]; | |
NSMutableArray *matches = [NSMutableArray array]; | |
for (NSUInteger idx; idx < [str length]; ++idx) { | |
unichar c = [str characterAtIndex:idx]; | |
NSLog(@"%C", c); | |
if (lastWasBackslash) { | |
[sub appendFormat:@"%C", c]; | |
lastWasBackslash = NO; | |
continue; | |
} | |
if (c == '\\') { | |
lastWasBackslash = YES; | |
continue; | |
} | |
if (c == '|') { | |
NSLog(@"pipe"); | |
[matches addObject:sub]; | |
sub = [NSMutableString string]; | |
} else { | |
[sub appendFormat:@"%C", c]; | |
} | |
} | |
[matches addObject:sub]; | |
NSLog(@"%@", matches); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment