@@ -26,10 +26,12 @@ #import "OFAutoreleasePool.h" #import "OFExceptions.h" #import "OFMacros.h" #import "asprintf.h" + +#import "encodings/iso_8859_15.h" /* References for static linking */ void _references_to_categories_of_OFString() { _OFHashing_reference = 1; @@ -247,42 +249,72 @@ switch (of_string_check_utf8(str, length)) { case 1: is_utf8 = YES; break; case -1: + /* + * We can't use [super dealloc] on OS X here. + * Compiler bug? Anyway, [self dealloc] will do here as + * we don't reimplement dealloc. + */ c = isa; - [super dealloc]; + [self dealloc]; @throw [OFInvalidEncodingException newWithClass: c]; } memcpy(string, str, length); string[length] = 0; break; case OF_STRING_ENCODING_ISO_8859_1: - for (i = j = 0; i < length; i++) { + case OF_STRING_ENCODING_ISO_8859_15: + for (i = j = 0; i < len; i++) { if ((uint8_t)str[i] < 0x80) string[j++] = str[i]; else { - /* - * ISO 8859-1 can only have 2 bytes when encoded - * as UTF-8, nevertheless, let's be on the safe - * side. - */ char buf[4]; + uint32_t chr; + size_t chr_bytes; + + switch (encoding) { + case OF_STRING_ENCODING_ISO_8859_1: + chr = (uint8_t)str[i]; + break; + case OF_STRING_ENCODING_ISO_8859_15: + chr = iso_8859_15_to_unicode[ + (uint8_t)str[i]]; + break; + default: + /* + * We can't use [super dealloc] on OS X + * here. Compiler bug? Anyway, + * [self dealloc] will do here as we + * don't reimplement dealloc. + */ + c = isa; + [self dealloc]; + @throw [OFInvalidEncodingException + newWithClass: c]; + } is_utf8 = YES; + chr_bytes = of_string_unicode_to_utf8(chr, buf); - if (of_string_unicode_to_utf8( - (uint8_t)str[i], buf) == 0) { + if (chr_bytes == 0) { + /* + * We can't use [super dealloc] on OS X + * here. Compiler bug? Anyway, + * [self dealloc] will do here as we + * don't reimplement dealloc. + */ c = isa; - [super dealloc]; + [self dealloc]; @throw [OFInvalidEncodingException newWithClass: c]; } - length++; + length += chr_bytes - 1; @try { string = [self resizeMemory: string toSize: length + 1]; } @catch (OFException *e) { @@ -294,21 +326,26 @@ */ [self dealloc]; @throw e; } - string[j++] = buf[0]; - string[j++] = buf[1]; + memcpy(string + j, buf, chr_bytes); + j += chr_bytes; } } string[length] = 0; break; default: + /* + * We can't use [super dealloc] on OS X here. + * Compiler bug? Anyway, [self dealloc] will do here as we + * don't reimplement dealloc. + */ c = isa; - [super dealloc]; + [self dealloc]; @throw [OFInvalidEncodingException newWithClass: c]; } return self; }