diff options
author | Matthias Andreas Benkard <matthias@benkard.de> | 2008-07-01 17:40:34 +0200 |
---|---|---|
committer | Matthias Andreas Benkard <matthias@benkard.de> | 2008-07-01 17:40:34 +0200 |
commit | e97d47a664131b5c80f35265f33e82eefb04f1d0 (patch) | |
tree | ebf4e251add7474062fbf7cbba2696f1e64e6cc4 /MLKStream.m | |
parent | 2ce5b7ded1c689548e9becb6fb39284ea68a1941 (diff) |
Implement a raw version of LOAD.
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 |