From e97d47a664131b5c80f35265f33e82eefb04f1d0 Mon Sep 17 00:00:00 2001 From: Matthias Andreas Benkard Date: Tue, 1 Jul 2008 17:40:34 +0200 Subject: Implement a raw version of LOAD. --- MLKStream.m | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) (limited to 'MLKStream.m') 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 -- cgit v1.2.3