Skip to content

Instantly share code, notes, and snippets.

@planetexpress69
Last active August 29, 2015 14:06
Show Gist options
  • Save planetexpress69/7c5e6082765528f3e2a7 to your computer and use it in GitHub Desktop.
Save planetexpress69/7c5e6082765528f3e2a7 to your computer and use it in GitHub Desktop.
Extracting some stuff...
- (NSDictionary *)extract:(NSString *)sPayload
{
NSError *regexError = nil;
NSString *sPattern = @"MACRO_NET_WORK_TYPE_[0-9A-Z _]{1,}=[ ]{1,}'[0-9]{1,}'";
NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:sPattern
options:NSRegularExpressionCaseInsensitive
error:&regexError];
if (sPayload == nil) {
NSLog(@"Gimme some real food...");
return nil;
}
if (regexError) {
NSLog(@"Error initializing regex...");
return nil;
}
NSArray *aHaystack = [sPayload componentsSeparatedByString:@"\n"];
NSMutableDictionary *dResult = [NSMutableDictionary new];
for (NSString *sLine in aHaystack) {
NSTextCheckingResult *match = [regex firstMatchInString:sLine options:0 range:NSMakeRange(0, [sLine length])];
if (match) {
NSString *sGotcha = [sLine substringWithRange:[match rangeAtIndex:0]];
NSArray *aSplittedGotcha = [sGotcha componentsSeparatedByString:@"="];
[dResult setObject:[NSNumber numberWithInt:[[[aSplittedGotcha[1] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]] stringByReplacingOccurrencesOfString:@"'" withString:@""]intValue]]
forKey:[aSplittedGotcha[0]stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]]];
}
}
return dResult.allKeys.count > 0 ? dResult : nil;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment