From 03f322c7152c8f10805a0b8a75bf517e88fdf427 Mon Sep 17 00:00:00 2001 From: axel Date: Thu, 10 May 2007 16:14:28 +1000 Subject: [PATCH] Use ucs4 or ucs2 as a fallback character set if wchar_t encoding is not supported by iconv darcs-hash:20070510061428-ac50b-ae9bfda1cc24bc29c2c492f902854440da319bfc.gz --- env_universal_common.c | 61 +++++++++++++++++++++++++++++++++++++++--- 1 file changed, 58 insertions(+), 3 deletions(-) diff --git a/env_universal_common.c b/env_universal_common.c index 5a6c49f98..df1dcb2d6 100644 --- a/env_universal_common.c +++ b/env_universal_common.c @@ -133,15 +133,70 @@ wchar_t *utf2wcs( const char *in ) wchar_t *out; - char *to_name[]= + /* + Try to convert to wchar_t. If that is not a valid character set, + try various names for ucs-4. We can't be sure that ucs-4 is + really the character set used by wchar_t, but it is the best + assumption we can make. + */ + char *to_name1[]= { - "wchar_t", "WCHAR_T", "wchar", "WCHAR", 0 + "wchar_t", "WCHAR_T", + "wchar", "WCHAR", + 0 } ; + char *to_name4[]= + { + "wchar_t", "WCHAR_T", + "wchar", "WCHAR", + "ucs-4", "UCS-4", + "ucs4", "UCS4", + "utf-32", "UTF-32", + "utf32", "UTF32", + 0 + } + ; + + char *to_name2[]= + { + "wchar_t", "WCHAR_T", + "wchar", "WCHAR", + "ucs-2", "UCS-2", + "ucs2", "UCS2", + "utf-16", "UTF-16", + "utf16", "UTF16", + 0 + } + ; + + char **to_name=0; + + switch (sizeof (wchar_t)) + { + + case 2: + to_name = to_name2; + break; + + case 4: + to_name = to_name4; + break; + + default: + to_name = to_name1; + break; + } + + + /* + The line protocol fish uses is always utf-8. + */ char *from_name[]= { - "utf-8", "UTF-8", "utf8", "UTF8", 0 + "utf-8", "UTF-8", + "utf8", "UTF8", 0 } ;