@@ -51,10 +51,156 @@ }; static uint16_t sutf16str[] = { 0xFFFE, 0x6600, 0xF600, 0xF600, 0x6200, 0xE400, 0x7200, 0x3CD8, 0x3ADC, 0 }; + +@interface SimpleString: OFString +{ + OFMutableString *_string; +} +@end + +@interface SimpleMutableString: OFMutableString +{ + OFMutableString *_string; +} +@end + +@implementation SimpleString +- init +{ + self = [super init]; + + @try { + _string = [[OFMutableString alloc] init]; + } @catch (id e) { + [self release]; + @throw e; + } + + return self; +} + +- initWithString: (OFString*)string +{ + self = [super init]; + + @try { + _string = [string mutableCopy]; + } @catch (id e) { + [self release]; + @throw e; + } + + return self; +} + +- initWithCString: (const char*)cString + encoding: (of_string_encoding_t)encoding + length: (size_t)length +{ + self = [super init]; + + @try { + _string = [[OFMutableString alloc] initWithCString: cString + encoding: encoding + length: length]; + } @catch (id e) { + [self release]; + @throw e; + } + + return self; +} + +- initWithUTF16String: (const of_char16_t*)UTF16String + length: (size_t)length + byteOrder: (of_byte_order_t)byteOrder +{ + self = [super init]; + + @try { + _string = [[OFMutableString alloc] + initWithUTF16String: UTF16String + length: length + byteOrder: byteOrder]; + } @catch (id e) { + [self release]; + @throw e; + } + + return self; +} + +- initWithUTF32String: (const of_char32_t*)UTF32String + length: (size_t)length + byteOrder: (of_byte_order_t)byteOrder +{ + self = [super init]; + + @try { + _string = [[OFMutableString alloc] + initWithUTF32String: UTF32String + length: length + byteOrder: byteOrder]; + } @catch (id e) { + [self release]; + @throw e; + } + + return self; +} + +- initWithFormat: (OFConstantString*)format + arguments: (va_list)arguments +{ + self = [super init]; + + @try { + _string = [[OFMutableString alloc] initWithFormat: format + arguments: arguments]; + } @catch (id e) { + [self release]; + @throw e; + } + + return self; +} + +- (void)dealloc +{ + [_string release]; + + [super dealloc]; +} + +- (of_unichar_t)characterAtIndex: (size_t)index +{ + return [_string characterAtIndex: index]; +} + +- (size_t)length +{ + return [_string length]; +} +@end + +@implementation SimpleMutableString ++ (void)initialize +{ + if (self == [SimpleMutableString class]) + [self inheritMethodsFromClass: [SimpleString class]]; +} + +- (void)replaceCharactersInRange: (of_range_t)range + withString: (OFString*)string +{ + [_string replaceCharactersInRange: range + withString: string]; +} +@end @interface EntityHandler: OFObject @end @implementation EntityHandler @@ -79,15 +225,14 @@ int i; const of_unichar_t *ua; const uint16_t *u16a; EntityHandler *h; #ifdef OF_HAVE_BLOCKS + __block int j; __block bool ok; #endif - module = [stringClass className]; - #define C(s) [stringClass stringWithString: s] s[0] = [mutableStringClass stringWithString: @"täs€"]; s[1] = [mutableStringClass string]; s[2] = [[s[0] copy] autorelease]; @@ -793,16 +938,15 @@ return @"bar"; return nil; }] isEqual: @"xbary"]) + j = 0; ok = true; [C(@"foo\nbar\nbaz") enumerateLinesUsingBlock: ^ (OFString *line, bool *stop) { - static int i = 0; - - switch (i) { + switch (j) { case 0: if (![line isEqual: @"foo"]) ok = false; break; case 1: @@ -815,11 +959,11 @@ break; default: ok = false; } - i++; + j++; }]; TEST(@"-[enumerateLinesUsingBlock:]", ok) #endif #undef C @@ -827,9 +971,14 @@ [pool drain]; } - (void)stringTests { - [self stringTestsWithClass: [OFString class] - mutableClass: [OFMutableString class]]; + module = @"OFString"; + [self stringTestsWithClass: [SimpleString class] + mutableClass: [SimpleMutableString class]]; + + module = @"OFString_UTF8"; + [self stringTestsWithClass: [OFString_UTF8 class] + mutableClass: [OFMutableString_UTF8 class]]; } @end