#ifndef HGL_CODE_PAGE_INCLUDE #define HGL_CODE_PAGE_INCLUDE #include #include namespace hgl { struct CodePageAndCharSet { CharCodePage codepage; CharSetName charset; }; constexpr struct CodePageAndCharSet CodePage2CharSet[]= { {ccpNone, "us-ascii" }, {ccpGBK, "gbk" }, {ccpBig5, "big5" }, {ccpGB2312, "gb2312" }, {ccpGB18030, "gb18030" }, {ccpShiftJIS, "shift-jis" }, {ccpJISX, "iso-2022-jp" }, {ccpKorean, "ks_c_5601-1987"}, {ccpMacJanpan, "x-mac-japanese" }, {ccpMacTraditionalChinese, "x-mac-chinesetrad" }, {ccpMacSimplifiedChinese, "x-mac-chinesesimp" }, {ccpUTF7, "utf-7" }, {ccpUTF8, "utf-8" }, {ccpUTF16LE, "utf-16le" }, {ccpUTF16BE, "utf-16be" }, {ccpUTF32LE, "utf-32le" }, {ccpUTF32BE, "utf-32be" }, };//const struct constexpr int CharSetCount=sizeof(CodePage2CharSet)/sizeof(CodePageAndCharSet); inline const char *FindCharSet(CharCodePage ccp) { for(int i=0;i(str)+1,len); } inline u16char *u8_to_u16(const u8char *str) { int len; return u8_to_u16(str,hgl::strlen(str)+1,len); } inline UTF16String to_u16(const u8char *u8_str,int length) { int wlen; u16char *ws=u8_to_u16(u8_str,length,wlen); return UTF16String::newOf(ws,wlen); } inline UTF16String to_u16(const UTF8String &u8str) { return to_u16(u8str.c_str(),u8str.Length()); } inline UTF16String to_u16(const u8char *str) { int wlen; u16char *ws=u8_to_u16(str,strlen(str),wlen); return UTF16String::newOf(ws,wlen); } inline UTF8String to_u8(const u16char *wide_str,int length) { int ulen; u8char *us=u16_to_u8(wide_str,length,ulen); return UTF8String::newOf(us,ulen); } inline UTF8String to_u8(const UTF16String &ws) { return to_u8(ws.c_str(),ws.Length()); } #if HGL_OS == HGL_OS_Windows inline OSString ToOSString(const u8char *str){return to_u16(str);} inline OSString ToOSString(const UTF8String &str){return to_u16(str.c_str(), (int)(str.Length()));} inline UTF8String ToUTF8String(const os_char *str){return to_u8(str,strlen(str));} inline UTF8String ToUTF8String(const OSString &str){return to_u8(str);} #else inline OSString ToOSString(const char *str){return OSString(str);} inline OSString ToOSString(const UTF8String &str){return str;} inline UTF8String ToUTF8String(const os_char *str){return UTF8String(str);} inline UTF8String ToUTF8String(const OSString &str){return str;} #endif// const BOMFileHeader *ParseBOM(const void *input); bool BOM2CharSet(CharSet *cs,const BOMFileHeader *bom); }//namespace hgl #endif//HGL_CODE_PAGE_INCLUDE