Index: src/OFMutableString_UTF8.m ================================================================== --- src/OFMutableString_UTF8.m +++ src/OFMutableString_UTF8.m @@ -213,11 +213,11 @@ if (index > _s->cStringLength) @throw [OFOutOfRangeException exception]; /* Shortcut if old and new character both are ASCII */ - if (!(character & 0x80) && !(_s->cString[index] & 0x80)) { + if (character < 0x80 && !(_s->cString[index] & 0x80)) { _s->hashed = false; _s->cString[index] = character; return; } @@ -244,11 +244,11 @@ _s->cStringLength -= lenOld; _s->cStringLength += lenNew; _s->cString[_s->cStringLength] = '\0'; - if (character & 0x80) + if (character >= 0x80) _s->isUTF8 = true; } else if (lenNew < (size_t)lenOld) { memmove(_s->cString + index + lenNew, _s->cString + index + lenOld, _s->cStringLength - index - lenOld); @@ -255,10 +255,13 @@ memcpy(_s->cString + index, buffer, lenNew); _s->cStringLength -= lenOld; _s->cStringLength += lenNew; _s->cString[_s->cStringLength] = '\0'; + + if (character >= 0x80) + _s->isUTF8 = true; @try { _s->cString = [self resizeMemory: _s->cString size: _s->cStringLength + 1]; @@ -344,14 +347,16 @@ if (encoding == OF_STRING_ENCODING_UTF_8) [self appendUTF8String: cString length: cStringLength]; else { void *pool = objc_autoreleasePoolPush(); + [self appendString: [OFString stringWithCString: cString encoding: encoding length: cStringLength]]; + objc_autoreleasePoolPop(pool); } } - (void)appendString: (OFString*)string @@ -640,10 +645,17 @@ _s->cString = [self resizeMemory: _s->cString size: newCStringLength + 1]; _s->cStringLength = newCStringLength; _s->length = newLength; + + if ([replacement isKindOfClass: [OFString_UTF8 class]] || + [replacement isKindOfClass: [OFMutableString_UTF8 class]]) { + if (((OFString_UTF8*)replacement)->_s->isUTF8) + _s->isUTF8 = true; + } else + _s->isUTF8 = true; } - (void)replaceOccurrencesOfString: (OFString*)string withString: (OFString*)replacement options: (int)options @@ -720,10 +732,17 @@ [self freeMemory: _s->cString]; _s->hashed = false; _s->cString = newCString; _s->cStringLength = newCStringLength; _s->length = newLength; + + if ([replacement isKindOfClass: [OFString_UTF8 class]] || + [replacement isKindOfClass: [OFMutableString_UTF8 class]]) { + if (((OFString_UTF8*)replacement)->_s->isUTF8) + _s->isUTF8 = true; + } else + _s->isUTF8 = true; } - (void)deleteLeadingWhitespaces { size_t i;