diff options
author | axel <axel@liljencrantz.se> | 2007-05-10 16:14:28 +1000 |
---|---|---|
committer | axel <axel@liljencrantz.se> | 2007-05-10 16:14:28 +1000 |
commit | 03f322c7152c8f10805a0b8a75bf517e88fdf427 (patch) | |
tree | d6cf212a5332263ea1e23401848c2fbef7a4ffb4 /env_universal_common.c | |
parent | a72d8777526b19905227c32afdd54f6f7b1d222f (diff) |
Use ucs4 or ucs2 as a fallback character set if wchar_t encoding is not supported by iconv
darcs-hash:20070510061428-ac50b-ae9bfda1cc24bc29c2c492f902854440da319bfc.gz
Diffstat (limited to 'env_universal_common.c')
-rw-r--r-- | env_universal_common.c | 61 |
1 files changed, 58 insertions, 3 deletions
diff --git a/env_universal_common.c b/env_universal_common.c index 5a6c49f9..df1dcb2d 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 } ; |