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