@@ -35,11 +35,11 @@ apply_table(id self, Class isa, char **string, unsigned int *length, BOOL is_utf8, const of_unichar_t* const table[], const size_t table_size) { of_unichar_t c, tc; of_unichar_t *ustr; - size_t ulen, nlen; + size_t ulen, nlen, clen; size_t i, j, d; char *nstr; if (!is_utf8) { assert(table_size >= 1); @@ -56,17 +56,18 @@ ulen = [self length]; ustr = [self allocMemoryForNItems: [self length] withSize: ulen]; + i = 0; j = 0; nlen = 0; - for (i = 0; i < *length; i++) { - c = of_string_utf8_to_unicode(*string + i, *length - i); + while (i < *length) { + clen = of_string_utf8_to_unicode(*string + i, *length - i, &c); - if (c == OF_INVALID_UNICHAR || c > 0x10FFFF) { + if (clen == 0 || c > 0x10FFFF) { [self freeMemory: ustr]; @throw [OFInvalidEncodingException newWithClass: isa]; } if (c >> 8 < table_size) { @@ -87,21 +88,11 @@ else { [self freeMemory: ustr]; @throw [OFInvalidEncodingException newWithClass: isa]; } - if (c < 0x80); - else if (c < 0x800) - i++; - else if (c < 0x10000) - i += 2; - else if (c < 0x110000) - i += 3; - else { - [self freeMemory: ustr]; - @throw [OFInvalidEncodingException newWithClass: isa]; - } + i += clen; } @try { nstr = [self allocMemoryWithSize: nlen + 1]; } @catch (OFException *e) {