Index: configure.ac ================================================================== --- configure.ac +++ configure.ac @@ -594,10 +594,31 @@ AC_DEFINE(OF_HAVE_UNICODE_TABLES, 1, [Whether to build with Unicode tables]) AC_SUBST(UNICODE_M, "unicode.m") ]) +ENCODINGS_SRCS="" +AC_DEFUN([ENCODING_FLAG], [ + AC_ARG_ENABLE($1, + AS_HELP_STRING([--disable-$1], + [Disables support for $3])) + AS_IF([test x"$enable_$2" != x"no"], [ + AC_DEFINE($4, 1, + [Whether we have support for $3]) + ENCODINGS_SRCS="$ENCODINGS_SRCS $2.m" + ]) +]) +ENCODING_FLAG(codepage-437, codepage_437, [Codepage 437], HAVE_CODEPAGE_437) +ENCODING_FLAG(codepage-850, codepage_850, [Codepage 850], HAVE_CODEPAGE_850) +ENCODING_FLAG(codepage-858, codepage_858, [Codepage 858], HAVE_CODEPAGE_858) +ENCODING_FLAG(iso-8859-2, iso_8859_2, [ISO 8859-2], HAVE_ISO_8859_2) +ENCODING_FLAG(iso-8859-15, iso_8859_15, [ISO 8859-15], HAVE_ISO_8859_15) +ENCODING_FLAG(mac-roman, mac_roman, [Mac Roman encoding], HAVE_MAC_ROMAN) +ENCODING_FLAG(windows-1251, windows_1251, [Windows-1251], HAVE_WINDOWS_1251) +ENCODING_FLAG(windows-1252, windows_1252, [Windows-1252], HAVE_WINDOWS_1252) +AC_SUBST(ENCODINGS_SRCS) + AC_CHECK_FUNCS(sigaction) AC_CHECK_FUNCS([arc4random random], break) AC_CHECK_LIB(dl, dlopen, LIBS="$LIBS -ldl") Index: extra.mk.in ================================================================== --- extra.mk.in +++ extra.mk.in @@ -9,10 +9,11 @@ OBJFW_BRIDGE_STATIC_LIB = @OBJFW_BRIDGE_STATIC_LIB@ AUTORELEASE_M = @AUTORELEASE_M@ BIN_PREFIX = @BIN_PREFIX@ BRIDGE = @BRIDGE@ +ENCODINGS_SRCS = @ENCODINGS_SRCS@ EXCEPTIONS_A = @EXCEPTIONS_A@ EXCEPTIONS_EXCEPTIONS_A = @EXCEPTIONS_EXCEPTIONS_A@ EXCEPTIONS_EXCEPTIONS_LIB_A = @EXCEPTIONS_EXCEPTIONS_LIB_A@ EXCEPTIONS_LIB_A = @EXCEPTIONS_LIB_A@ FORWARDING_A = @FORWARDING_A@ Index: src/Makefile ================================================================== --- src/Makefile +++ src/Makefile @@ -151,21 +151,14 @@ OFMutableSet_hashtable.m \ OFMutableString_UTF8.m \ OFSet_hashtable.m \ OFString_UTF8.m \ ${AUTORELEASE_M} \ - codepage_437.m \ - codepage_850.m \ - codepage_858.m \ ${FOUNDATION_COMPAT_M} \ ${INSTANCE_M} \ - iso_8859_15.m \ - iso_8859_2.m \ - mac_roman.m \ ${UNICODE_M} \ - windows_1251.m \ - windows_1252.m + ${ENCODINGS_SRCS} SRCS_FILES += OFSettings_INIFile.m SRCS_SOCKETS += ${OFKERNELEVENTOBSERVER_EPOLL_M} \ ${OFKERNELEVENTOBSERVER_KQUEUE_M} \ ${OFKERNELEVENTOBSERVER_POLL_M} \ ${OFKERNELEVENTOBSERVER_SELECT_M} \ Index: src/OFString.m ================================================================== --- src/OFString.m +++ src/OFString.m @@ -1113,10 +1113,11 @@ } cString[i] = '\0'; return length; +#ifdef HAVE_ISO_8859_2 case OF_STRING_ENCODING_ISO_8859_2: if (length + 1 > maxLength) @throw [OFOutOfRangeException exception]; if (!of_unicode_to_iso_8859_2(characters, @@ -1124,10 +1125,12 @@ @throw [OFInvalidEncodingException exception]; cString[length] = '\0'; return length; +#endif +#ifdef HAVE_ISO_8859_15 case OF_STRING_ENCODING_ISO_8859_15: if (length + 1 > maxLength) @throw [OFOutOfRangeException exception]; if (!of_unicode_to_iso_8859_15(characters, @@ -1135,10 +1138,12 @@ @throw [OFInvalidEncodingException exception]; cString[length] = '\0'; return length; +#endif +#ifdef HAVE_WINDOWS_1251 case OF_STRING_ENCODING_WINDOWS_1251: if (length + 1 > maxLength) @throw [OFOutOfRangeException exception]; if (!of_unicode_to_windows_1251(characters, @@ -1146,10 +1151,12 @@ @throw [OFInvalidEncodingException exception]; cString[length] = '\0'; return length; +#endif +#ifdef HAVE_WINDOWS_1252 case OF_STRING_ENCODING_WINDOWS_1252: if (length + 1 > maxLength) @throw [OFOutOfRangeException exception]; if (!of_unicode_to_windows_1252(characters, @@ -1157,10 +1164,12 @@ @throw [OFInvalidEncodingException exception]; cString[length] = '\0'; return length; +#endif +#ifdef HAVE_CODEPAGE_437 case OF_STRING_ENCODING_CODEPAGE_437: if (length + 1 > maxLength) @throw [OFOutOfRangeException exception]; if (!of_unicode_to_codepage_437(characters, @@ -1168,10 +1177,12 @@ @throw [OFInvalidEncodingException exception]; cString[length] = '\0'; return length; +#endif +#ifdef HAVE_CODEPAGE_850 case OF_STRING_ENCODING_CODEPAGE_850: if (length + 1 > maxLength) @throw [OFOutOfRangeException exception]; if (!of_unicode_to_codepage_850(characters, @@ -1179,10 +1190,12 @@ @throw [OFInvalidEncodingException exception]; cString[length] = '\0'; return length; +#endif +#ifdef HAVE_CODEPAGE_858 case OF_STRING_ENCODING_CODEPAGE_858: if (length + 1 > maxLength) @throw [OFOutOfRangeException exception]; if (!of_unicode_to_codepage_858(characters, @@ -1190,10 +1203,12 @@ @throw [OFInvalidEncodingException exception]; cString[length] = '\0'; return length; +#endif +#ifdef HAVE_MAC_ROMAN case OF_STRING_ENCODING_MAC_ROMAN: if (length + 1 > maxLength) @throw [OFOutOfRangeException exception]; if (!of_unicode_to_mac_roman(characters, @@ -1201,10 +1216,11 @@ @throw [OFInvalidEncodingException exception]; cString[length] = '\0'; return length; +#endif default: @throw [OFNotImplementedException exceptionWithSelector: _cmd object: self]; } } Index: src/OFString_UTF8.m ================================================================== --- src/OFString_UTF8.m +++ src/OFString_UTF8.m @@ -289,34 +289,50 @@ return self; } switch (encoding) { +#ifdef HAVE_ISO_8859_2 case OF_STRING_ENCODING_ISO_8859_2: table = of_iso_8859_2; break; +#endif +#ifdef HAVE_ISO_8859_15 case OF_STRING_ENCODING_ISO_8859_15: table = of_iso_8859_15; break; +#endif +#ifdef HAVE_WINDOWS_1251 case OF_STRING_ENCODING_WINDOWS_1251: table = of_windows_1251; break; +#endif +#ifdef HAVE_WINDOWS_1252 case OF_STRING_ENCODING_WINDOWS_1252: table = of_windows_1252; break; +#endif +#ifdef HAVE_CODEPAGE_437 case OF_STRING_ENCODING_CODEPAGE_437: table = of_codepage_437; break; +#endif +#ifdef HAVE_CODEPAGE_850 case OF_STRING_ENCODING_CODEPAGE_850: table = of_codepage_850; break; +#endif +#ifdef HAVE_CODEPAGE_858 case OF_STRING_ENCODING_CODEPAGE_858: table = of_codepage_858; break; +#endif +#ifdef HAVE_MAC_ROMAN case OF_STRING_ENCODING_MAC_ROMAN: table = of_mac_roman; break; +#endif default: @throw [OFInvalidEncodingException exception]; } j = 0; Index: tests/OFStringTests.m ================================================================== --- tests/OFStringTests.m +++ tests/OFStringTests.m @@ -231,27 +231,33 @@ TEST(@"Conversion of ISO 8859-1 to Unicode", [[OFString stringWithCString: "\xE4\xF6\xFC" encoding: OF_STRING_ENCODING_ISO_8859_1] isEqual: @"äöü"]) +#ifdef HAVE_ISO_8859_15 TEST(@"Conversion of ISO 8859-15 to Unicode", [[OFString stringWithCString: "\xA4\xA6\xA8\xB4\xB8\xBC\xBD\xBE" encoding: OF_STRING_ENCODING_ISO_8859_15] isEqual: @"€ŠšŽžŒœŸ"]) +#endif +#ifdef HAVE_WINDOWS_1252 TEST(@"Conversion of Windows 1252 to Unicode", [[OFString stringWithCString: "\x80\x82\x83\x84\x85\x86\x87\x88" "\x89\x8A\x8B\x8C\x8E\x91\x92\x93" "\x94\x95\x96\x97\x98\x99\x9A\x9B" "\x9C\x9E\x9F" encoding: OF_STRING_ENCODING_WINDOWS_1252] isEqual: @"€‚ƒ„…†‡ˆ‰Š‹ŒŽ‘’“”•–—˜™š›œžŸ"]) +#endif +#ifdef HAVE_CODEPAGE_437 TEST(@"Conversion of Codepage 437 to Unicode", [[OFString stringWithCString: "\xB0\xB1\xB2\xDB" encoding: OF_STRING_ENCODING_CODEPAGE_437] isEqual: @"░▒▓█"]) +#endif TEST(@"Conversion of Unicode to ASCII #1", !strcmp([@"This is a test" cStringWithEncoding: OF_STRING_ENCODING_ASCII], "This is a test")) @@ -265,53 +271,65 @@ EXPECT_EXCEPTION(@"Conversion of Unicode to ISO-8859-1 #2", OFInvalidEncodingException, [@"This is ä t€st" cStringWithEncoding: OF_STRING_ENCODING_ISO_8859_1]) +#ifdef HAVE_ISO_8859_15 TEST(@"Conversion of Unicode to ISO-8859-15 #1", !strcmp([@"This is ä t€st" cStringWithEncoding: OF_STRING_ENCODING_ISO_8859_15], "This is \xE4 t\xA4st")) EXPECT_EXCEPTION(@"Conversion of Unicode to ISO-8859-15 #2", OFInvalidEncodingException, [@"This is ä t€st…" cStringWithEncoding: OF_STRING_ENCODING_ISO_8859_15]) +#endif +#ifdef HAVE_WINDOWS_1252 TEST(@"Conversion of Unicode to Windows-1252 #1", !strcmp([@"This is ä t€st…" cStringWithEncoding: OF_STRING_ENCODING_WINDOWS_1252], "This is \xE4 t\x80st\x85")) EXPECT_EXCEPTION(@"Conversion of Unicode to Windows-1252 #2", OFInvalidEncodingException, [@"This is ä t€st…‼" cStringWithEncoding: OF_STRING_ENCODING_WINDOWS_1252]) +#endif +#ifdef HAVE_CODEPAGE_437 TEST(@"Conversion of Unicode to Codepage 437 #1", !strcmp([@"Tést strîng ░▒▓" cStringWithEncoding: OF_STRING_ENCODING_CODEPAGE_437], "T\x82st str\x8Cng \xB0\xB1\xB2")) EXPECT_EXCEPTION(@"Conversion of Unicode to Codepage 437 #2", OFInvalidEncodingException, [@"T€st strîng ░▒▓" cStringWithEncoding: OF_STRING_ENCODING_CODEPAGE_437]) +#endif TEST(@"Lossy conversion of Unicode to ASCII", !strcmp([@"This is a tést" lossyCStringWithEncoding: OF_STRING_ENCODING_ASCII], "This is a t?st")) TEST(@"Lossy conversion of Unicode to ISO-8859-1", !strcmp([@"This is ä t€st" lossyCStringWithEncoding: OF_STRING_ENCODING_ISO_8859_1], "This is \xE4 t?st")) +#ifdef HAVE_ISO_8859_15 TEST(@"Lossy conversion of Unicode to ISO-8859-15", !strcmp([@"This is ä t€st…" lossyCStringWithEncoding: OF_STRING_ENCODING_ISO_8859_15], "This is \xE4 t\xA4st?")) +#endif +#ifdef HAVE_WINDOWS_1252 TEST(@"Lossy conversion of Unicode to Windows-1252", !strcmp([@"This is ä t€st…‼" lossyCStringWithEncoding: OF_STRING_ENCODING_WINDOWS_1252], "This is \xE4 t\x80st\x85?")) +#endif +#ifdef HAVE_CODEPAGE_437 TEST(@"Lossy conversion of Unicode to Codepage 437", !strcmp([@"T€st strîng ░▒▓" lossyCStringWithEncoding: OF_STRING_ENCODING_CODEPAGE_437], "T?st str\x8Cng \xB0\xB1\xB2")) +#endif TEST(@"+[stringWithFormat:]", [(s[0] = [OFMutableString stringWithFormat: @"%@:%d", @"test", 123]) isEqual: @"test:123"]) Index: tests/TestsAppDelegate.m ================================================================== --- tests/TestsAppDelegate.m +++ tests/TestsAppDelegate.m @@ -403,11 +403,13 @@ [self SHA384HashTests]; [self SHA512HashTests]; [self HMACTests]; [self PBKDF2Tests]; [self scryptTests]; +# ifdef HAVE_CODEPAGE_437 [self INIFileTests]; +# endif #endif #ifdef OF_HAVE_SOCKETS [self TCPSocketTests]; [self UDPSocketTests]; [self kernelEventObserverTests];