From 3a38aa8c4ffc8b589a629244bf238d75dd2ac626 Mon Sep 17 00:00:00 2001 From: Matthias Benkard Date: Wed, 27 Aug 2008 14:52:19 +0200 Subject: MLKStream: Add -writeChar and -writeString. --- MLKStream.h | 20 ++++++++++++-------- 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 #include +#include @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) -- cgit v1.2.3