Skip to content

Instantly share code, notes, and snippets.

@Mon-Ouie
Created July 6, 2010 13:08
Show Gist options
  • Select an option

  • Save Mon-Ouie/465359 to your computer and use it in GitHub Desktop.

Select an option

Save Mon-Ouie/465359 to your computer and use it in GitHub Desktop.
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