#ifndef HGL_CODE_PAGE_INCLUDE #define HGL_CODE_PAGE_INCLUDE #include #include namespace hgl { struct CodePageAndCharSet { CharCodePage codepage; CharSetName charset; }; constexpr struct CodePageAndCharSet CodePage2CharSet[]= { {CharCodePage::NONE, "us-ascii" }, {CharCodePage::GBK, "gbk" }, {CharCodePage::Big5, "big5" }, {CharCodePage::GB2312, "gb2312" }, {CharCodePage::GB18030, "gb18030" }, {CharCodePage::ShiftJIS, "shift-jis" }, {CharCodePage::JISX, "iso-2022-jp" }, {CharCodePage::Korean, "ks_c_5601-1987"}, {CharCodePage::MacJanpan, "x-mac-japanese" }, {CharCodePage::MacTraditionalChinese, "x-mac-chinesetrad" }, {CharCodePage::MacSimplifiedChinese, "x-mac-chinesesimp" }, {CharCodePage::ISO_8859_1, "iso-8859-1"}, {CharCodePage::ISO_8859_2, "iso-8859-2"}, {CharCodePage::ISO_8859_3, "iso-8859-3"}, {CharCodePage::ISO_8859_4, "iso-8859-4"}, {CharCodePage::ISO_8859_5, "iso-8859-5"}, {CharCodePage::ISO_8859_6, "iso-8859-6"}, {CharCodePage::ISO_8859_7, "iso-8859-7"}, {CharCodePage::ISO_8859_8, "iso-8859-8"}, {CharCodePage::ISO_8859_9, "iso-8859-9"}, {CharCodePage::ISO_8859_13, "iso-8859-13"}, {CharCodePage::ISO_8859_15, "iso-8859-15"}, {CharCodePage::UTF7, "utf-7" }, {CharCodePage::UTF8, "utf-8" }, {CharCodePage::UTF16LE, "utf-16le" }, {CharCodePage::UTF16BE, "utf-16be" }, {CharCodePage::UTF32LE, "utf-32le" }, {CharCodePage::UTF32BE, "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,hgl::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