@@ -103,10 +103,12 @@ size_t, bool); extern bool of_unicode_to_codepage_858(const of_unichar_t*, unsigned char*, size_t, bool); extern bool of_unicode_to_mac_roman(const of_unichar_t*, unsigned char*, size_t, bool); +extern bool of_unicode_to_koi8_r(const of_unichar_t*, unsigned char*, + size_t, bool); /* References for static linking */ void _references_to_categories_of_OFString(void) { @@ -162,10 +164,12 @@ else if ([string isEqual: @"cp858"] || [string isEqual: @"cp-858"] || [string isEqual: @"ibm858"] || [string isEqual: @"858"]) encoding = OF_STRING_ENCODING_CODEPAGE_858; else if ([string isEqual: @"macintosh"] || [string isEqual: @"mac"]) encoding = OF_STRING_ENCODING_MAC_ROMAN; + else if ([string isEqual: @"koi8-r"]) + encoding = OF_STRING_ENCODING_KOI8_R; else @throw [OFInvalidEncodingException exception]; objc_autoreleasePoolPop(pool); @@ -1217,10 +1221,23 @@ cString[length] = '\0'; return length; #endif +#ifdef HAVE_KOI8_R + case OF_STRING_ENCODING_KOI8_R: + if (length + 1 > maxLength) + @throw [OFOutOfRangeException exception]; + + if (!of_unicode_to_koi8_r(characters, + (unsigned char*)cString, length, lossy)) + @throw [OFInvalidEncodingException exception]; + + cString[length] = '\0'; + + return length; +#endif default: @throw [OFNotImplementedException exceptionWithSelector: _cmd object: self]; } } @@ -1279,10 +1296,11 @@ case OF_STRING_ENCODING_WINDOWS_1252: case OF_STRING_ENCODING_CODEPAGE_437: case OF_STRING_ENCODING_CODEPAGE_850: case OF_STRING_ENCODING_CODEPAGE_858: case OF_STRING_ENCODING_MAC_ROMAN: + case OF_STRING_ENCODING_KOI8_R: cString = [object allocMemoryWithSize: length + 1]; [self OF_getCString: cString maxLength: length + 1 encoding: encoding @@ -1348,10 +1366,11 @@ case OF_STRING_ENCODING_WINDOWS_1252: case OF_STRING_ENCODING_CODEPAGE_437: case OF_STRING_ENCODING_CODEPAGE_850: case OF_STRING_ENCODING_CODEPAGE_858: case OF_STRING_ENCODING_MAC_ROMAN: + case OF_STRING_ENCODING_KOI8_R: return [self length]; default: @throw [OFInvalidEncodingException exception]; } }