added ToAnsiString,upgraded to_utf16/utf16_to functions at CodePage.cpp(Windows)

This commit is contained in:
HuYingzhuo(hugo/hyzboy) 2022-06-15 16:04:34 +08:00
parent fe59a592c8
commit 326060163f

View File

@ -26,7 +26,7 @@ namespace hgl
*dst=new u16char[len+1];
MultiByteToWideChar((UINT)cs.codepage,0,(char *)src,src_str_size,*dst,len);
*dst[len]=0;
(*dst)[len]=0;
return len;
}
@ -67,9 +67,12 @@ namespace hgl
if(len<=0)return(len);
*dst=new char[len];
*dst=new char[len+1];
return WideCharToMultiByte((UINT)cs.codepage,0,src,src_str_size,*dst,len,0,0);
WideCharToMultiByte((UINT)cs.codepage,0,src,src_str_size,*dst,len,0,0);
(*dst)[len]=0;
return len;
}
int utf8_to(const CharSet &cs,char **dst,const u8char *src,const int src_size)
@ -84,6 +87,16 @@ namespace hgl
delete[] u16str;
return(result);
}
AnsiString ToAnsiString(const CharSet &cs,const UTF16String &str)
{
int len;
u8char *u8_str;
len=utf16_to(cs,&u8_str,str.c_str(),str.Length());
return AnsiString::newOf(u8_str,len);
}
}//namespace hgl