How to get libiconv on FreeBSD 10 convert utf-8 -> wchar_t ?

kora kora.jenkins at googlemail.com
Tue Oct 13 09:29:42 UTC 2015


Hi there,
I solved it.
I didn't notice that wchar_t is system dependent !

I wrote a helpermethod to return the correct wchar_t "tocode" / "fromcode"
input for the iconv_open().
Using it now works.


#define WCHAR_32_LE "UTF-32LE"
#define WCHAR_32_BE "UTF-32BE"
#define WCHAR_16_LE "UTF-16LE"
#define WCHAR_16_BE "UTF-16BE"

const char* systemWCharType(){
  if (NULL == mySystemsWCharType){
    int wCharSize = sizeof(wchar_t);
    int num = 1;
    if(*(char *)&num == 1){
      if (4 == wCharSize){
        mySystemsWCharType = WCHAR_32_LE;
      }
      else{
        mySystemsWCharType = WCHAR_16_LE;
      }
    }
    else{
      if (4 == wCharSize){
        mySystemsWCharType = WCHAR_32_BE;
      }
      else{
        mySystemsWCharType = WCHAR_16_BE;
      }
    }
  }
  return mySystemsWCharType;
}





Thanks for support

Kora



--
View this message in context: http://freebsd.1045724.n5.nabble.com/How-to-get-libiconv-on-FreeBSD-10-convert-utf-8-wchar-t-tp6042436p6044683.html
Sent from the freebsd-questions mailing list archive at Nabble.com.


More information about the freebsd-questions mailing list