Index: src/OFMutableString.m ================================================================== --- src/OFMutableString.m +++ src/OFMutableString.m @@ -39,10 +39,13 @@ [self freeMemory: string]; len = strlen(str); switch (of_string_check_utf8(str, len)) { + case 0: + is_utf8 = NO; + break; case 1: is_utf8 = YES; break; case -1: string = NULL; @@ -132,11 +135,16 @@ return self; } - appendString: (OFString*)str { - return [self appendCStringWithoutUTF8Checking: [str cString]]; + [self appendCStringWithoutUTF8Checking: [str cString]]; + + if (str->is_utf8) + is_utf8 = YES; + + return self; } - appendWithFormat: (OFString*)fmt, ... { id ret; Index: src/OFString.m ================================================================== --- src/OFString.m +++ src/OFString.m @@ -457,14 +457,33 @@ return self; } - initWithString: (OFString*)str { + Class c; + self = [super init]; - string = strdup([str cString]); + string = (char*)[str cString]; length = [str cStringLength]; + + switch (of_string_check_utf8(string, length)) { + case 1: + is_utf8 = YES; + break; + case -1: + c = isa; + [self dealloc]; + @throw [OFInvalidEncodingException newWithClass: c]; + } + + if ((string = strdup(string)) == NULL) { + c = isa; + [self dealloc]; + @throw [OFOutOfMemoryException newWithClass: c + size: length + 1]; + } @try { [self addMemoryToPool: string]; } @catch (OFException *e) { /* Index: src/OFXMLParser.m ================================================================== --- src/OFXMLParser.m +++ src/OFXMLParser.m @@ -510,10 +510,11 @@ OFString *ret; last = 0; in_entity = NO; ret = [OFMutableString string]; + ret->is_utf8 = is_utf8; for (i = 0; i < length; i++) { if (!in_entity && string[i] == '&') { [ret appendCStringWithoutUTF8Checking: string + last length: i - last]; @@ -523,19 +524,24 @@ } else if (in_entity && string[i] == ';') { char *entity = string + last; size_t len = i - last; if (len == 2 && !memcmp(entity, "lt", 2)) - [ret appendString: @"<"]; + [ret appendCStringWithoutUTF8Checking: "<" + length: 1]; else if (len == 2 && !memcmp(entity, "gt", 2)) - [ret appendString: @">"]; + [ret appendCStringWithoutUTF8Checking: ">" + length: 1]; else if (len == 4 && !memcmp(entity, "quot", 4)) - [ret appendString: @"\""]; + [ret appendCStringWithoutUTF8Checking: "\"" + length: 1]; else if (len == 4 && !memcmp(entity, "apos", 4)) - [ret appendString: @"'"]; + [ret appendCStringWithoutUTF8Checking: "'" + length: 1]; else if (len == 3 && !memcmp(entity, "amp", 3)) - [ret appendString: @"&"]; + [ret appendCStringWithoutUTF8Checking: "&" + length: 1]; else if (entity[0] == '#') { OFAutoreleasePool *pool; OFString *tmp; pool = [[OFAutoreleasePool alloc] init];