bool CharToWide(const char *Src,wchar *Dest,size_t DestSize) { bool RetCode=true; *Dest=0; // Set 'Dest' to zero just in case the conversion will fail. #ifdef _WIN_ALL if (MultiByteToWideChar(CP_ACP,0,Src,-1,Dest,(int)DestSize)==0) RetCode=false; #elif defined(_APPLE) UtfToWide(Src,Dest,DestSize); #elif defined(MBFUNCTIONS) size_t ResultingSize=mbstowcs(Dest,Src,DestSize); if (ResultingSize==(size_t)-1) RetCode=false; if (ResultingSize==0 && *Src!=0) RetCode=false; if ((!RetCode || *Dest==0 && *Src!=0) && DestSize>NM && strlen(Src)<NM) { /* Workaround for strange Linux Unicode functions bug. Some of wcstombs and mbstowcs implementations in some situations (we are yet to find out what it depends on) can return an empty string and success code if buffer size value is too large. */ return(CharToWide(Src,Dest,NM)); } #else if (UnicodeEnabled()) { #if defined(_EMX) && !defined(_DJGPP) int len=Min(strlen(Src)+1,DestSize-1); if (uni_toucs((char*)Src,len,(UniChar*)Dest,(size_t*)&DestSize)==-1 || DestSize>len) DestSize=0; RetCode=false; #endif } else for (int I=0;I<DestSize;I++) { Dest[I]=(wchar_t)Src[I]; if (Src[I]==0) break; } #endif // We tried to return the zero terminated string if conversion is failed, // but it does not work well. MultiByteToWideChar returns 'failed' code // even if we wanted to convert only a part of string and passed DestSize // smaller than required for fully converted string. Such call is the valid // behavior in RAR code and we do not expect the empty string in this case. return(RetCode); }
bool CharToWide(const char *Src,wchar *Dest,size_t DestSize) { bool RetCode=true; #ifdef _WIN_32 if (MultiByteToWideChar(CP_ACP,0,Src,-1,Dest,(int)DestSize)==0) RetCode=false; #else #ifdef _APPLE UtfToWide(Src,Dest,DestSize); #else #ifdef MBFUNCTIONS size_t ResultingSize=mbstowcs(Dest,Src,DestSize); if (ResultingSize==(size_t)-1) RetCode=false; if (ResultingSize==0 && *Src!=0) RetCode=false; if ((!RetCode || *Dest==0 && *Src!=0) && DestSize>NM && strlen(Src)<NM) { /* Workaround for strange Linux Unicode functions bug. Some of wcstombs and mbstowcs implementations in some situations (we are yet to find out what it depends on) can return an empty string and success code if buffer size value is too large. */ return(CharToWide(Src,Dest,NM)); } #else if (UnicodeEnabled()) { #if defined(_EMX) && !defined(_DJGPP) int len=Min(strlen(Src)+1,DestSize-1); if (uni_toucs((char*)Src,len,(UniChar*)Dest,(size_t*)&DestSize)==-1 || DestSize>len) DestSize=0; RetCode=false; #endif } else for (int I=0;I<DestSize;I++) { Dest[I]=(wchar_t)Src[I]; if (Src[I]==0) break; } #endif #endif #endif return(RetCode); }
bool CharToWide(const char *Src,wchar *Dest,int DestSize) { bool RetCode=true; #ifdef _WIN_32 if (MultiByteToWideChar(CP_ACP,0,Src,-1,Dest,DestSize)==0) RetCode=false; #else #ifdef _APPLE UtfToWide(Src,Dest,DestSize); #else #ifdef MBFUNCTIONS if (mbstowcs(Dest,Src,DestSize)==-1) RetCode=false; #else if (UnicodeEnabled()) { #if defined(_EMX) && !defined(_DJGPP) int len=Min(strlen(Src)+1,DestSize-1); if (uni_toucs((char*)Src,len,(UniChar*)Dest,(size_t*)&DestSize)==-1 || DestSize>len) DestSize=0; RetCode=false; #endif } else for (int I=0;I<DestSize;I++) { Dest[I]=(wchar_t)Src[I]; if (Src[I]==0) break; } #endif #endif #endif return(RetCode); }