Created
July 6, 2010 13:08
-
-
Save Mon-Ouie/465359 to your computer and use it in GitHub Desktop.
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
| NSMutableString *string = [[NSMutableString alloc] init]; | |
| int readBytes = 0; | |
| do { | |
| uint8_t buf[MPD_LINE_MAX + 1]; | |
| memset(buf, '\0', MPD_LINE_MAX + 1); | |
| readBytes = [input read:buf maxLength:MPD_LINE_MAX]; | |
| [string appendFormat:@"%s", buf]; | |
| NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; | |
| [string enumerateStringsMatchedByRegex:@"(.+)\n" usingBlock:^(int count, | |
| NSString * const cap[], | |
| NSRange const ranges[], | |
| volatile BOOL * const stop) { | |
| NSString *line = cap[0]; | |
| *stop = NO; | |
| if ([commands count] == 0 && ![self isParsing]) { | |
| [self disconnect]; | |
| [self performSelectorOnMainThread:@selector(unexpectedMessage) | |
| withObject:nil | |
| waitUntilDone:NO]; | |
| return; | |
| } | |
| if (![self isParsing]) { | |
| int command = [[commands objectAtIndex:0] intValue]; | |
| [commands removeObjectAtIndex:0]; | |
| self.parser = [[MPDParser alloc] initWithConnection:self | |
| command:command]; | |
| [parser release]; | |
| } | |
| [parser parseLine:line]; | |
| }]; | |
| [string replaceOccurrencesOfRegex:@"(.+)\n" withString:@""]; | |
| [pool drain]; | |
| } while(readBytes == MPD_LINE_MAX); | |
| [string release]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment