Last active
August 29, 2015 14:06
-
-
Save planetexpress69/7c5e6082765528f3e2a7 to your computer and use it in GitHub Desktop.
Extracting some stuff...
This file contains 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
- (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:®exError]; | |
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