diff options
Diffstat (limited to 'MLKStream.m')
-rw-r--r-- | MLKStream.m | 31 |
1 files changed, 26 insertions, 5 deletions
diff --git a/MLKStream.m b/MLKStream.m index c80e6ff..fa36232 100644 --- a/MLKStream.m +++ b/MLKStream.m @@ -81,15 +81,16 @@ NSString *tmpstr; ssize_t bytes_read; - buffer = realloc (buffer, i+1); - bytes_read = [_input read:(buffer+i) maxLength:1]; - // NSLog (@"%d bytes read", bytes_read); - if (!bytes_read) + if (![_input hasBytesAvailable]) { [NSException raise:@"MLKStreamError" format:@"Tried to read beyond end of file."]; } + buffer = realloc (buffer, i+1); + bytes_read = [_input read:(buffer+i) maxLength:1]; + // NSLog (@"%d bytes read", bytes_read); + tmpstr = [[NSString alloc] initWithBytesNoCopy:buffer length:(i+1) encoding:_encoding @@ -115,8 +116,28 @@ _cachedChar = ch; } +-(unichar) peekChar +{ + unichar ch = [self readChar]; + [self unreadChar:ch]; + return ch; +} + -(BOOL) isEOF { - return ![_input hasBytesAvailable]; + NS_DURING + { + [self peekChar]; + } + NS_HANDLER + { + if ([[localException name] isEqual:@"MLKStreamError"]) + NS_VALUERETURN (YES, BOOL); + else + [localException raise]; + } + NS_ENDHANDLER; + + return NO; } @end |