diff options
author | Matthias Benkard <mulk@minimulk.mst-plus> | 2008-08-27 14:52:19 +0200 |
---|---|---|
committer | Matthias Benkard <mulk@minimulk.mst-plus> | 2008-08-27 14:52:19 +0200 |
commit | 3a38aa8c4ffc8b589a629244bf238d75dd2ac626 (patch) | |
tree | ee619a9032cb830632f15648ced8d286401962fa | |
parent | 44bb85683c4356997aa8fc9c6fc8a05fd7101196 (diff) |
MLKStream: Add -writeChar and -writeString.
-rw-r--r-- | MLKStream.h | 20 | ||||
-rw-r--r-- | MLKStream.m | 38 |
2 files changed, 42 insertions, 16 deletions
diff --git a/MLKStream.h b/MLKStream.h index 737346c..a2536fd 100644 --- a/MLKStream.h +++ b/MLKStream.h @@ -31,17 +31,21 @@ unichar _cachedChar; } --(MLKStream *) init; --(MLKStream *) initWithInputStream:(NSInputStream *)input; --(MLKStream *) initWithOutputStream:(NSOutputStream *)output; --(MLKStream *) initWithInputStream:(NSInputStream *)input - outputStream:(NSOutputStream *)output; --(MLKStream *) initWithInputStream:(NSInputStream *)input - outputStream:(NSOutputStream *)output - encoding:(NSStringEncoding)encoding; +-(id) init; +-(id) initWithInputStream:(NSInputStream *)input; +-(id) initWithOutputStream:(NSOutputStream *)output; +-(id) initWithInputStream:(NSInputStream *)input + outputStream:(NSOutputStream *)output; +-(id) initWithInputStream:(NSInputStream *)input + outputStream:(NSOutputStream *)output + encoding:(NSStringEncoding)encoding; -(unichar) readChar; -(void) unreadChar:(unichar)ch; -(unichar) peekChar; -(BOOL) isEOF; + +-(void) writeChar:(unichar)ch; +//-(void) writeFormat:(NSString *)format, ...; +-(void) writeString:(NSString *)string; @end diff --git a/MLKStream.m b/MLKStream.m index 6448bdc..9d34edb 100644 --- a/MLKStream.m +++ b/MLKStream.m @@ -24,26 +24,27 @@ #include <unistd.h> #include <stdlib.h> +#include <string.h> @implementation MLKStream --(MLKStream *) init; +-(id) init; { return [self initWithInputStream:nil outputStream:nil]; } --(MLKStream *) initWithInputStream:(NSInputStream *)input; +-(id) initWithInputStream:(NSInputStream *)input; { return [self initWithInputStream:input outputStream:nil]; } --(MLKStream *) initWithOutputStream:(NSOutputStream *)output; +-(id) initWithOutputStream:(NSOutputStream *)output; { return [self initWithInputStream:nil outputStream:output]; } --(MLKStream *) initWithInputStream:(NSInputStream *)input - outputStream:(NSOutputStream *)output +-(id) initWithInputStream:(NSInputStream *)input + outputStream:(NSOutputStream *)output { return [self initWithInputStream:input outputStream:output @@ -51,9 +52,9 @@ } --(MLKStream *) initWithInputStream:(NSInputStream *)input - outputStream:(NSOutputStream *)output - encoding:(NSStringEncoding)encoding +-(id) initWithInputStream:(NSInputStream *)input + outputStream:(NSOutputStream *)output + encoding:(NSStringEncoding)encoding { self = [super init]; LASSIGN (_input, input); @@ -162,6 +163,27 @@ return eofp; } +-(void) writeChar:(unichar)ch +{ + const void *cstring = [[NSString stringWithFormat:@"%C", ch] cStringUsingEncoding:_encoding]; + [_output write:cstring maxLength:strlen(cstring)]; +} + +//-(void) writeFormat:(NSString *)format, ... +//{ +// NSString *string = ; +// [self writeString:string]; +//} + +-(void) writeString:(NSString *)string +{ + unichar ch; + int i; + + for (i = 0; i < [string length]; i++) + [self writeChar:[string characterAtIndex:i]]; +} + -(void) dealloc { if (_closeInputWhenDone) |