Merge branch 'master' of https://github.com/hyzboy/CMCore into HEAD

This commit is contained in:
HuYingzhuo(hugo/hyzboy) 2022-06-25 21:41:43 +08:00
commit 5a88a6072c
19 changed files with 504 additions and 221 deletions

View File

@ -7,52 +7,59 @@ namespace hgl
{ {
struct CodePageAndCharSet struct CodePageAndCharSet
{ {
CharCodePage codepage; uint16 codepage;
CharSetName charset; CharSetName charset;
}; };
#define HGL_CODE_PAGE_AND_CHAR_SET(codepage,charset) {uint16(CharCodePage::codepage),charset}
constexpr struct CodePageAndCharSet CodePage2CharSet[]= constexpr struct CodePageAndCharSet CodePage2CharSet[]=
{ {
{CharCodePage::NONE, "us-ascii" },
{CharCodePage::GBK, "gbk" }, HGL_CODE_PAGE_AND_CHAR_SET(NONE, "us-ascii" ),
{CharCodePage::Big5, "big5" }, HGL_CODE_PAGE_AND_CHAR_SET(IBM437, "IBM437" ),
{CharCodePage::GB2312, "gb2312" },
{CharCodePage::GB18030, "gb18030" },
{CharCodePage::ShiftJIS, "shift-jis" }, HGL_CODE_PAGE_AND_CHAR_SET(GBK, "gbk" ),
{CharCodePage::JISX, "iso-2022-jp" }, HGL_CODE_PAGE_AND_CHAR_SET(Big5, "big5" ),
HGL_CODE_PAGE_AND_CHAR_SET(GB2312, "gb2312" ),
HGL_CODE_PAGE_AND_CHAR_SET(GB18030, "gb18030" ),
{CharCodePage::Korean, "ks_c_5601-1987"}, 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" ),
{CharCodePage::MacJanpan, "x-mac-japanese" }, HGL_CODE_PAGE_AND_CHAR_SET(Korean, "ks_c_5601-1987"),
{CharCodePage::MacTraditionalChinese, "x-mac-chinesetrad" },
{CharCodePage::MacSimplifiedChinese, "x-mac-chinesesimp" },
{CharCodePage::ISO_8859_1, "iso-8859-1"}, HGL_CODE_PAGE_AND_CHAR_SET(MacJanpan, "x-mac-japanese" ),
{CharCodePage::ISO_8859_2, "iso-8859-2"}, HGL_CODE_PAGE_AND_CHAR_SET(MacTraditionalChinese, "x-mac-chinesetrad" ),
{CharCodePage::ISO_8859_3, "iso-8859-3"}, HGL_CODE_PAGE_AND_CHAR_SET(MacSimplifiedChinese, "x-mac-chinesesimp" ),
{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" }, HGL_CODE_PAGE_AND_CHAR_SET(ISO_8859_1, "iso-8859-1"),
{CharCodePage::UTF8, "utf-8" }, 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"),
{CharCodePage::UTF16LE, "utf-16le" }, HGL_CODE_PAGE_AND_CHAR_SET(UTF7, "utf-7" ),
{CharCodePage::UTF16BE, "utf-16be" }, HGL_CODE_PAGE_AND_CHAR_SET(UTF8, "utf-8" ),
{CharCodePage::UTF32LE, "utf-32le" },
{CharCodePage::UTF32BE, "utf-32be" }, 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 };//const struct
constexpr int CharSetCount=sizeof(CodePage2CharSet)/sizeof(CodePageAndCharSet); constexpr int CharSetCount=sizeof(CodePage2CharSet)/sizeof(CodePageAndCharSet);
inline const char *FindCharSet(CharCodePage ccp) inline const char *FindCharSet(uint16 ccp)
{ {
for(int i=0;i<CharSetCount;i++) for(int i=0;i<CharSetCount;i++)
if(CodePage2CharSet[i].codepage==ccp) if(CodePage2CharSet[i].codepage==ccp)
@ -63,84 +70,88 @@ namespace hgl
constexpr struct CodePageAndCharSet CodeSet2CharPage[]= constexpr struct CodePageAndCharSet CodeSet2CharPage[]=
{ {
{CharCodePage::NONE, "us-ascii" }, HGL_CODE_PAGE_AND_CHAR_SET(NONE, "us-ascii" ),
HGL_CODE_PAGE_AND_CHAR_SET(IBM437, "IBM437" ),
{CharCodePage::GBK, "gbk" }, HGL_CODE_PAGE_AND_CHAR_SET(GBK, "gbk" ),
{CharCodePage::Big5, "big5" }, HGL_CODE_PAGE_AND_CHAR_SET(Big5, "big5" ),
{CharCodePage::Big5, "bigfive" }, HGL_CODE_PAGE_AND_CHAR_SET(Big5, "bigfive" ),
{CharCodePage::GB2312, "gb2312" }, HGL_CODE_PAGE_AND_CHAR_SET(GB2312, "gb2312" ),
{CharCodePage::GB18030, "gb18030" }, HGL_CODE_PAGE_AND_CHAR_SET(GB18030, "gb18030" ),
{CharCodePage::ShiftJIS, "shift_jis" }, HGL_CODE_PAGE_AND_CHAR_SET(ShiftJIS, "shift_jis" ),
{CharCodePage::JISX, "iso-2022-jp" }, 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" ),
{CharCodePage::Korean, "ks_c_5601-1987"}, HGL_CODE_PAGE_AND_CHAR_SET(Korean, "ks_c_5601-1987"),
{CharCodePage::MacJanpan, "x-mac-japanese" }, HGL_CODE_PAGE_AND_CHAR_SET(MacJanpan, "x-mac-japanese" ),
{CharCodePage::MacTraditionalChinese, "x-mac-chinesetrad" }, HGL_CODE_PAGE_AND_CHAR_SET(MacTraditionalChinese, "x-mac-chinesetrad" ),
{CharCodePage::MacSimplifiedChinese, "x-mac-chinesesimp" }, HGL_CODE_PAGE_AND_CHAR_SET(MacSimplifiedChinese, "x-mac-chinesesimp" ),
{CharCodePage::ISO_8859_1, "iso-8859-1"}, HGL_CODE_PAGE_AND_CHAR_SET(ISO_8859_1, "iso-8859-1"),
{CharCodePage::ISO_8859_2, "iso-8859-2"}, HGL_CODE_PAGE_AND_CHAR_SET(ISO_8859_2, "iso-8859-2"),
{CharCodePage::ISO_8859_3, "iso-8859-3"}, HGL_CODE_PAGE_AND_CHAR_SET(ISO_8859_3, "iso-8859-3"),
{CharCodePage::ISO_8859_4, "iso-8859-4"}, HGL_CODE_PAGE_AND_CHAR_SET(ISO_8859_4, "iso-8859-4"),
{CharCodePage::ISO_8859_5, "iso-8859-5"}, HGL_CODE_PAGE_AND_CHAR_SET(ISO_8859_5, "iso-8859-5"),
{CharCodePage::ISO_8859_6, "iso-8859-6"}, HGL_CODE_PAGE_AND_CHAR_SET(ISO_8859_6, "iso-8859-6"),
{CharCodePage::ISO_8859_7, "iso-8859-7"}, HGL_CODE_PAGE_AND_CHAR_SET(ISO_8859_7, "iso-8859-7"),
{CharCodePage::ISO_8859_8, "iso-8859-8"}, HGL_CODE_PAGE_AND_CHAR_SET(ISO_8859_8, "iso-8859-8"),
{CharCodePage::ISO_8859_9, "iso-8859-9"}, HGL_CODE_PAGE_AND_CHAR_SET(ISO_8859_9, "iso-8859-9"),
{CharCodePage::ISO_8859_13, "iso-8859-13"}, HGL_CODE_PAGE_AND_CHAR_SET(ISO_8859_13, "iso-8859-13"),
{CharCodePage::ISO_8859_15, "iso-8859-15"}, HGL_CODE_PAGE_AND_CHAR_SET(ISO_8859_15, "iso-8859-15"),
{CharCodePage::UTF7, "utf-7" }, HGL_CODE_PAGE_AND_CHAR_SET(UTF7, "utf-7" ),
{CharCodePage::UTF8, "utf-8" }, HGL_CODE_PAGE_AND_CHAR_SET(UTF8, "utf-8" ),
{CharCodePage::UTF16LE, "utf-16le" }, HGL_CODE_PAGE_AND_CHAR_SET(UTF16LE, "utf-16le" ),
{CharCodePage::UTF16BE, "utf-16be" }, HGL_CODE_PAGE_AND_CHAR_SET(UTF16BE, "utf-16be" ),
{CharCodePage::UTF32LE, "utf-32le" }, HGL_CODE_PAGE_AND_CHAR_SET(UTF32LE, "utf-32le" ),
{CharCodePage::UTF32BE, "utf-32be" }, HGL_CODE_PAGE_AND_CHAR_SET(UTF32BE, "utf-32be" ),
{CharCodePage::UTF16LE, "utf-16" }, HGL_CODE_PAGE_AND_CHAR_SET(UTF16LE, "utf-16" ),
{CharCodePage::UTF16BE, "unicodeFFFE"}, HGL_CODE_PAGE_AND_CHAR_SET(UTF16BE, "unicodeFFFE"),
{CharCodePage::UTF16LE, "ucs-2le" }, HGL_CODE_PAGE_AND_CHAR_SET(UTF16LE, "ucs-2le" ),
{CharCodePage::UTF16BE, "ucs-2be" }, HGL_CODE_PAGE_AND_CHAR_SET(UTF16BE, "ucs-2be" ),
{CharCodePage::UTF32LE, "ucs-4le" }, HGL_CODE_PAGE_AND_CHAR_SET(UTF32LE, "ucs-4le" ),
{CharCodePage::UTF32BE, "ucs-4be" } HGL_CODE_PAGE_AND_CHAR_SET(UTF32BE, "ucs-4be" )
};//const struct CharSet Characters };//const struct CharSet Characters
constexpr int CharPageCount=sizeof(CodeSet2CharPage)/sizeof(CodePageAndCharSet); constexpr int CharPageCount=sizeof(CodeSet2CharPage)/sizeof(CodePageAndCharSet);
inline CharCodePage FindCodePage(const u8char *char_set) inline uint16 FindCodePage(const u8char *char_set)
{ {
for(int i=0;i<CharPageCount;i++) for(int i=0;i<CharPageCount;i++)
if(!charset_cmp(CodePage2CharSet[i].charset,char_set)) if(!charset_cmp(CodePage2CharSet[i].charset,char_set))
return CodePage2CharSet[i].codepage; return CodePage2CharSet[i].codepage;
return CharCodePage::NONE; return (uint16)CharCodePage::NONE;
} }
struct CharSet struct CharSet
{ {
CharCodePage codepage; uint16 codepage;
CharSetName charset; CharSetName charset;
public: public:
CharSet() CharSet()
{ {
codepage=CharCodePage::NONE; codepage=0;
hgl::strcpy(charset,CHAR_SET_NAME_MAX_LENGTH,"us-ascii"); hgl::strcpy(charset,CHAR_SET_NAME_MAX_LENGTH,"us-ascii");
} }
CharSet(CharCodePage ccp,const char *cs) CharSet(uint16 ccp,const char *cs)
{ {
codepage=ccp; codepage=ccp;
hgl::strcpy(charset,CHAR_SET_NAME_MAX_LENGTH,cs); hgl::strcpy(charset,CHAR_SET_NAME_MAX_LENGTH,cs);
} }
CharSet(CharCodePage); CharSet(uint16);
CharSet(const u8char *); CharSet(const u8char *);
CharSet(const CodePageAndCharSet &cs) CharSet(const CodePageAndCharSet &cs)
@ -153,7 +164,7 @@ namespace hgl
CompOperator(const CharSet &,_Comp) CompOperator(const CharSet &,_Comp)
};//struct CharacterSet };//struct CharacterSet
inline CharSet::CharSet(CharCodePage ccp) inline CharSet::CharSet(uint16 ccp)
{ {
codepage=ccp; codepage=ccp;
hgl::strcpy(charset,CHAR_SET_NAME_MAX_LENGTH,FindCharSet(ccp)); hgl::strcpy(charset,CHAR_SET_NAME_MAX_LENGTH,FindCharSet(ccp));
@ -178,15 +189,35 @@ namespace hgl
#endif// #endif//
/** /**
* 使 u16char * * utf16字符串后的长度
* @param charset * @param charset
* @param dst u16char *delete[] * @param src
* @param src_size ,-1
* @return
*/
int get_utf16_length(const CharSet &charset,const void *src,const int src_size=-1);
/**
* 使utf16字符串
* @param charset
* @param dst utf16字符串缓冲区delete[]
* @param src * @param src
* @param src_size ,-1 * @param src_size ,-1
* @return * @return
*/ */
int to_utf16(const CharSet &charset,u16char **dst,const void *src,const int src_size=-1); int to_utf16(const CharSet &charset,u16char **dst,const void *src,const int src_size=-1);
/**
* 使utf16字符串
* @param charset
* @param dst utf16字符串缓冲区
* @param dst_size
* @param src
* @param src_size ,-1
* @return
*/
int to_utf16(const CharSet &charset,u16char *dst,const int dst_size,const void *src,const int src_size=-1);
int to_utf8(const CharSet &charset,u8char **dst,const void *src,const int src_size=-1); int to_utf8(const CharSet &charset,u8char **dst,const void *src,const int src_size=-1);
/** /**
@ -254,8 +285,15 @@ namespace hgl
{ {
return to_u8(ws.c_str(),ws.Length()); return to_u8(ws.c_str(),ws.Length());
} }
#if HGL_OS == HGL_OS_Windows #if HGL_OS == HGL_OS_Windows
AnsiString ToAnsiString(const CharSet &cs,const UTF16String &str);
inline AnsiString ToAnsiString(const UTF16String &str)
{
const CharSet cs((uint16)0);
return ToAnsiString(cs,str);
}
inline OSString ToOSString(const u8char *str){return to_u16(str);} 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 OSString ToOSString(const UTF8String &str){return to_u16(str.c_str(), (int)(str.Length()));}

View File

@ -16,6 +16,8 @@ namespace hgl
{ {
NONE=0, ///<起始定义,无意义 NONE=0, ///<起始定义,无意义
IBM437 =437, ///<OEM United States (dos)
//中文 //中文
GBK =936, ///<中国GBK标准中文 GBK =936, ///<中国GBK标准中文
Big5 =950, ///<中国台湾Big5标准繁体中文 Big5 =950, ///<中国台湾Big5标准繁体中文
@ -24,6 +26,9 @@ namespace hgl
//日文 //日文
ShiftJIS =932, ///<日文ShiftJIS ShiftJIS =932, ///<日文ShiftJIS
EUC_JP =20932, ///<日文JIS 0208-1990 and 0212-1990
ISO2022JP =50220, ///<ISO 2022 Japanese with no halfwidth Katakana; Japanese (JIS)
csISO2022JP =50221, ///<ISO 2022 Japanese with halfwidth Katakana; Japanese (JIS-Allow 1 byte Kana)
JISX =50222, ///<日文JIS X/ISO 2022 JISX =50222, ///<日文JIS X/ISO 2022
//韩文 //韩文
@ -105,7 +110,7 @@ namespace hgl
ByteOrderMask bom; ///<字节序枚举 ByteOrderMask bom; ///<字节序枚举
const CharSetName *char_set;///<字符集名称 const CharSetName *char_set;///<字符集名称
CharCodePage code_page; ///<代码页 uint16 code_page; ///<代码页
}; };
/** /**
@ -113,11 +118,11 @@ namespace hgl
*/ */
constexpr BOMFileHeader BOMData[size_t(ByteOrderMask::RANGE_SIZE)]= constexpr BOMFileHeader BOMData[size_t(ByteOrderMask::RANGE_SIZE)]=
{ {
{3,{0xEF,0xBB,0xBF} ,ByteOrderMask::UTF8, &utf8_charset ,CharCodePage::UTF8 }, {3,{0xEF,0xBB,0xBF} ,ByteOrderMask::UTF8, &utf8_charset ,(uint16)CharCodePage::UTF8 },
{2,{0xFF,0xFE} ,ByteOrderMask::UTF16LE,&utf16le_charset ,CharCodePage::UTF16LE }, {2,{0xFF,0xFE} ,ByteOrderMask::UTF16LE,&utf16le_charset ,(uint16)CharCodePage::UTF16LE },
{2,{0xFE,0xFF} ,ByteOrderMask::UTF16BE,&utf16be_charset ,CharCodePage::UTF16BE }, {2,{0xFE,0xFF} ,ByteOrderMask::UTF16BE,&utf16be_charset ,(uint16)CharCodePage::UTF16BE },
{4,{0xFF,0xFE,0x00,0x00},ByteOrderMask::UTF32LE,&utf32le_charset ,CharCodePage::UTF32LE }, {4,{0xFF,0xFE,0x00,0x00},ByteOrderMask::UTF32LE,&utf32le_charset ,(uint16)CharCodePage::UTF32LE },
{4,{0x00,0x00,0xFE,0xFF},ByteOrderMask::UTF32BE,&utf32be_charset ,CharCodePage::UTF32BE } {4,{0x00,0x00,0xFE,0xFF},ByteOrderMask::UTF32BE,&utf32be_charset ,(uint16)CharCodePage::UTF32BE }
}; };
inline ByteOrderMask CheckBOM(const void *data) inline ByteOrderMask CheckBOM(const void *data)

View File

@ -5,13 +5,15 @@
#include<math.h> #include<math.h>
namespace hgl namespace hgl
{ {
#define HGL_OFFICAL_WEB "www.hyzgame.com" #define HGL_OFFICAL_WEB "www.hyzgame.com"
#define HGL_OFFICAL_WEB_U8 u8"www.hyzgame.com" #define HGL_OFFICAL_WEB_U8 U8_TEXT("www.hyzgame.com")
#define HGL_OFFICAL_WEB_URL "http://www.hyzgame.com" #define HGL_OFFICAL_WEB_OS OS_TEXT("www.hyzgame.com")
#define HGL_OFFICAL_WEB_URL_u8 u8"http://www.hyzgame.com" #define HGL_OFFICAL_WEB_URL "http://www.hyzgame.com"
#define HGL_OFFICAL_WEB_URL_u8 U8_TEXT("http://www.hyzgame.com")
#define HGL_OFFICAL_WEB_URL_OS OS_TEXT("http://www.hyzgame.com")
#define HGL_COPYRIGHT_STRING "(C)Copyright 2022 www.hyzgame.com" #define HGL_COPYRIGHT_STRING "(C)Copyright 2022 www.hyzgame.com"
#define HGL_COPYRIGHT_STRING_U8 u8"(C)Copyright 2022 www.hyzgame.com" #define HGL_COPYRIGHT_STRING_U8 U8_TEXT("(C)Copyright 2022 www.hyzgame.com")
#define HGL_COPYRIGHT_STRING_OS OS_TEXT("(C)Copyright 2022 www.hyzgame.com") #define HGL_COPYRIGHT_STRING_OS OS_TEXT("(C)Copyright 2022 www.hyzgame.com")
#define ENUM_CLASS_RANGE(begin,end) BEGIN_RANGE=begin,END_RANGE=end,RANGE_SIZE=(END_RANGE-BEGIN_RANGE)+1 #define ENUM_CLASS_RANGE(begin,end) BEGIN_RANGE=begin,END_RANGE=end,RANGE_SIZE=(END_RANGE-BEGIN_RANGE)+1

97
inc/hgl/URI.h Normal file
View File

@ -0,0 +1,97 @@
#ifndef HGL_URI_INCLUDE
#define HGL_URI_INCLUDE
#include<hgl/type/String.h>
namespace hgl
{
const uint16 GetSchemePort(const char *scheme);
/**
* <br>
* <p>/</p>
*
* <p>example 1:
* http:// www.hyzgame.com / index .php
* ------- --------------- ----- ---
* scheme path main_name ext_name
*
* scheme: http
* path: www.hyzgame.com
* main_name: index
* ext_name: php
* </p>
*
* <p> example 2:
* file:// C:/windows/system32/1234.dll
*
* scheme: file
* driver: C
* path: Windows\System32
* main_name: 1234
* ext_name: dll
* fullname: C:\windows\system32\1234.dll
* </p>
*
* <p> example 3:
* C:\windows\system32\1234.dll
*
* scheme:
* driver: C
* path: Windows\System32
* main_name: 1234
* ext_name: dll
* fullname: C:\windows\system32\1234.dll
* </p>
*/
class URI
{
public:
enum class SchemeType
{
Unknow=0,
LocalFile, ///<本地文件系统
ArachivesFile, ///<档案文件(压缩包/tar/ISO镜像之类)
Device, ///<设备虚拟文件
Network, ///<网络
};
protected:
OSString origin_name;
OSString scheme_name; ///<协议名称(如http,ftp之类)
SchemeType scheme_type; ///<协议
UTF8String network_host; ///<网络主机(IP或网址)
uint16 network_port; ///<网络协议默认端口
OSString fullname; ///<完整文件名
OSString path_name; ///<路径名
OSString main_name; ///<主名称
OSString ext_name; ///<文件扩展名
UTF8String url;
public:
URI(const OSString &);
URI(const OSString &scheme,const OSString &path,const OSString &filename);
~URI()=default;
const bool isFile();
const bool isDevice();
const bool isNetwork();
public:
const OSString &path();
const OSString &main();
const OSString &ext();
const OSString &full();
const UTF8String &URL();
};//class Filename
}//namespace hgl
#endif//HGL_URI_INCLUDE

View File

@ -2,6 +2,7 @@
#define HGL_FILESYSTEM_FILENAME_INCLUDE #define HGL_FILESYSTEM_FILENAME_INCLUDE
#include<hgl/type/StringList.h> #include<hgl/type/StringList.h>
#include<hgl/math/PrimaryMathematics.h>
/** /**
* Maximum Path Length Limitation * Maximum Path Length Limitation
@ -68,7 +69,7 @@ namespace hgl
{ {
int str_len[count]; int str_len[count];
for(int i=0;i<count;++) for(int i=0;i<count;i++)
str_len=strlen(str_list[i]); str_len=strlen(str_list[i]);
return ComboFilename(str_list,str_len,count,spear_char); return ComboFilename(str_list,str_len,count,spear_char);

View File

@ -24,14 +24,19 @@ namespace hgl
llLog //记录一下 llLog //记录一下
};//enum LogLevel };//enum LogLevel
bool InitLogger(const OSString &app_name);
void Log(LogLevel level,const u16char *str,int size);
void Log(LogLevel level,const u8char *str,int size);
inline void Log(LogLevel ll,const UTF16String &str) inline void Log(LogLevel ll,const UTF16String &str)
{ {
std::wcout<<str.c_str()<<std::endl; Log(ll,str.c_str(),str.Length());
} }
inline void Log(LogLevel ll,const UTF8String &str) inline void Log(LogLevel ll,const UTF8String &str)
{ {
std::cout<<(char *)str.c_str()<<std::endl; Log(ll,str.c_str(),str.Length());
} }
#ifdef HGL_SUPPORT_CHAR8_T #ifdef HGL_SUPPORT_CHAR8_T

View File

@ -1,9 +1,9 @@
#ifndef HGL_Primary_Mathematics_INCLUDE #ifndef HGL_Primary_Mathematics_INCLUDE
#define HGL_Primary_Mathematics_INCLUDE #define HGL_Primary_Mathematics_INCLUDE
namespace hgl namespace hgl
{ {
/** /**
* *
*/ */
template<typename T> template<typename T>
const T sum(const T *data,const int count) const T sum(const T *data,const int count)
@ -20,7 +20,7 @@ namespace hgl
} }
/** /**
* *
*/ */
template<typename R,typename T> template<typename R,typename T>
const R sum(const T *data,const int count) const R sum(const T *data,const int count)

View File

@ -9,15 +9,8 @@ namespace hgl
#define DEF_RGB_U8_TO_F(r,g,b) {float(r)/255.0f,float(g)/255.0f,float(b)/255.0f} #define DEF_RGB_U8_TO_F(r,g,b) {float(r)/255.0f,float(g)/255.0f,float(b)/255.0f}
#define DEF_RGBA_U8_TO_F(r,g,b,a) {float(r)/255.0f,float(g)/255.0f,float(b)/255.0f,float(a)/255.0f} #define DEF_RGBA_U8_TO_F(r,g,b,a) {float(r)/255.0f,float(g)/255.0f,float(b)/255.0f,float(a)/255.0f}
inline constexpr uint8 RGB2Lum(const uint8 red,const uint8 green,const uint8 blue) #define HEXColor3(value) (0x##value>>16),((0x##value&0xFF00)>>8),(0x##value&0xFF)
{ #define HEXColor3f(value) float(0x##value>>16)/255.0f,float((0x##value&0xFF00)>>8)/255.0f,float(0x##value&0xFF)/255.0f
return float(red)*0.299+float(green)*0.587+float(blue)*0.114;
}
inline constexpr float RGB2Lumf(const float red,const float green,const float blue)
{
return red*0.299+green*0.587+blue*0.114;
}
const Color3f GetSpectralColor(const double l); ///<根据光谱值获取对应的RGB值 const Color3f GetSpectralColor(const double l); ///<根据光谱值获取对应的RGB值

View File

@ -2,96 +2,113 @@
#define HGL_COLOR_SPACE_INCLUDE #define HGL_COLOR_SPACE_INCLUDE
#include<math.h> #include<math.h>
#include<hgl/TypeFunc.h>
namespace hgl namespace hgl
{ {
namespace graph enum class ColorSpace
{ {
enum class ColorSpace Linear=0,
{ sRGB,
Linear=0, YCbCr,
sRGB,
YCbCr,
ENUM_CLASS_RANGE(Linear,YCbCr) ENUM_CLASS_RANGE(Linear,YCbCr)
};//enum class ColorSpace };//enum class ColorSpace
constexpr double GAMMA =2.4f; constexpr double GAMMA =2.4f;
constexpr double INV_GAMMA =1.0f/GAMMA; constexpr double INV_GAMMA =1.0f/GAMMA;
constexpr double SRGB_ALPHA =0.055f; constexpr double SRGB_ALPHA =0.055f;
template<typename T> template<typename T>
inline constexpr T sRGB2Linear(const T &in) inline constexpr T sRGB2Linear(const T &in,const T &gamma=GAMMA,const T &srgb_alpha=SRGB_ALPHA)
{ {
if(in<=0.4045) if(in<=0.4045)
return (double)in/12.92; return (double)in/12.92;
else else
return pow((double(in)+SRGB_ALPHA)/(1.0f+SRGB_ALPHA),GAMMA); return pow((double(in)+srgb_alpha)/(1.0f+srgb_alpha),gamma);
} }
template<typename T> template<typename T>
inline constexpr T Linear2sRGB(const T &in) inline constexpr T Linear2sRGB(const T &in,const T &inv_gamma=INV_GAMMA,const T &srgb_alpha=SRGB_ALPHA)
{ {
if(in<=0.0031308f) if(in<=0.0031308f)
return double(in)*12.92f; return double(in)*12.92f;
else else
return pow(double(in),INV_GAMMA)*(1.0f+SRGB_ALPHA)-SRGB_ALPHA; return pow(double(in),inv_gamma)*(1.0f+srgb_alpha)-srgb_alpha;
} }
template<typename T> template<typename T>
inline constexpr T sRGB2LinearCheaper(const T &in) inline constexpr T sRGB2LinearCheaper(const T &in,const T &gamma=GAMMA)
{ {
return (T)pow(double(in),GAMMA); return (T)pow(double(in),gamma);
} }
template<typename T> template<typename T>
inline constexpr T Linear2sRGBCheaper(const T &in) inline constexpr T Linear2sRGBCheaper(const T &in,const T &inv_gamma=INV_GAMMA)
{ {
return (T)pow((double)in,INV_GAMMA); return (T)pow((double)in,inv_gamma);
} }
template<typename T> template<typename T>
inline constexpr T sRGB2LinearCheapest(const T &in) inline constexpr T sRGB2LinearCheapest(const T &in)
{ {
return in*in; return in*in;
} }
template<typename T> template<typename T>
inline void sRGB2LinearFast(T &x,T &y,T &z,const T &r,const T &g,const T &b) inline void sRGB2LinearFast(T &x,T &y,T &z,const T &r,const T &g,const T &b)
{ {
x=0.4124f*r+0.3576f*g+0.1805f*b; x=0.4124f*r+0.3576f*g+0.1805f*b;
y=0.2126f*r+0.7152f*g+0.0722f*b; y=0.2126f*r+0.7152f*g+0.0722f*b;
z=0.0193f*r+0.1192f*g+0.9505f*b; z=0.0193f*r+0.1192f*g+0.9505f*b;
} }
template<typename T> template<typename T>
inline void Linear2sRGBFast(T &r,T &g,T &b,const T &x,const T &y,const T &z) inline void Linear2sRGBFast(T &r,T &g,T &b,const T &x,const T &y,const T &z)
{ {
r= 3.2406f*x-1.5373f*y-0.4986f*z; r= 3.2406f*x-1.5373f*y-0.4986f*z;
g=-0.9689f*x+1.8758f*y+0.0416f*z; g=-0.9689f*x+1.8758f*y+0.0416f*z;
b= 0.0557f*x-0.2040f*y+1.0570f*z; b= 0.0557f*x-0.2040f*y+1.0570f*z;
} }
template<typename T> template<typename T>
inline constexpr T Clamp(const T &value,const T &min_value,const T &max_value) inline constexpr T Clamp(const T &value,const T &min_value,const T &max_value)
{ {
if(value<min_value)return min_value; if(value<min_value)return min_value;
if(value>max_value)return max_value; if(value>max_value)return max_value;
return value; return value;
} }
template<typename T> template<typename T>
inline constexpr T Clamp(const T &value) inline constexpr T Clamp(const T &value)
{ {
return Clamp<T>(value,T(0),T(1)); return Clamp<T>(value,T(0),T(1));
} }
template<> inline constexpr uint8 Clamp<uint8>(const uint8 &value) template<typename T>
{ inline constexpr T RGB2Lum(const T &r,const T &g,const T &b)
return Clamp<uint8>(value,0,255); {
} return 0.299f*r+0.587f*g+0.114f*b;
}//namespace graph }
template<typename T>
inline constexpr T RGB2Cb(const T &r,const T &g,const T &b)
{
return -0.168736f*r-0.331264f*g+0.5f*b;
}
template<typename T>
inline constexpr T RGB2Cr(const T &r,const T &g,const T &b)
{
return 0.5f*r-0.418688f*g-0.081312f*b;
}
template<typename T>
inline void RGB2YCbCr(T &y,T &cb,T &cr,const T &r,const T &g,const T &b)
{
y =RGB2Lum(r,g,b);
cb=RGB2Cb(r,g,b);
cr=RGB2Cr(r,g,b);
}
}//namespace hgl }//namespace hgl
#endif//HGL_COLOR_SPACE_INCLUDE #endif//HGL_COLOR_SPACE_INCLUDE

View File

@ -165,7 +165,12 @@ namespace hgl
T &operator[](int n) T &operator[](int n)
{ {
return buf+n; return buf[n];
}
const T &operator[](int n)const
{
return buf[n];
} }
};//template<typename T> class MemBlock };//template<typename T> class MemBlock

View File

@ -251,7 +251,7 @@ namespace hgl
if(!new_items) if(!new_items)
return(false); return(false);
items=new_items; this->items=new_items;
} }
return(true); return(true);

View File

@ -15,7 +15,7 @@ namespace hgl
List<T> data_list; List<T> data_list;
bool FindPos(const T &,int &)const; ///<查找数据如果插入后,会所在的位置,返回是否存在这个数据 bool FindPos(const T &,int &)const; ///<查找数据如果插入后,会所在的位置,返回是否存在这个数据
int FindPos(const T &flag)const{int pos;return FindPos(flag,pos)?return(pos):-1;} ///<查找数据如果插入后,会所在的位置 int FindPos(const T &flag)const{int pos;return FindPos(flag,pos)?pos:-1;} ///<查找数据如果插入后,会所在的位置
public: //属性 public: //属性

View File

@ -4,31 +4,61 @@
#include<hgl/type/String.h> #include<hgl/type/String.h>
#include<hgl/CodePage.h> #include<hgl/CodePage.h>
#if HGL_OS == HGL_OS_Windows namespace hgl
inline hgl::OSString std_to_os(const std::string &str)
{ {
return hgl::to_u16((hgl::u8char *)str.c_str(),(int)(str.length())); #if HGL_OS == HGL_OS_Windows
} inline hgl::OSString ToOSString(const std::string &str)
{
return hgl::to_u16((hgl::u8char *)str.c_str(),(int)(str.length()));
}
inline std::string to_std(const hgl::OSString &str) inline hgl::OSString ToOSString(const std::wstring &str)
{ {
hgl::UTF8String u8_str=hgl::to_u8(str); return hgl::OSString(str.c_str(),(int)str.length());
}
return std::string((char *)u8_str.c_str(),str.Length()); inline hgl::UTF8String ToUTF8String(const std::wstring &str)
} {
#else return hgl::to_u8(str.c_str(),(int)str.length());
inline hgl::OSString std_to_os(const std::string &str) }
{
return hgl::OSString(str.c_str(),str.size());
}
inline std::string to_std(const hgl::OSString &str) inline std::string ToStdString(const hgl::OSString &str)
{ {
return std::string(str.c_str(),str.Length()); hgl::UTF8String u8_str=hgl::to_u8(str);
}
#endif//
inline hgl::UTF8String std_to_u8(const std::string &str) return std::string((char *)u8_str.c_str(),str.Length());
{ }
return hgl::UTF8String((hgl::u8char *)str.c_str(),int(str.size()));
inline std::wstring ToStdWString(const hgl::OSString &str)
{
return std::wstring(str.c_str(),str.Length());
}
#else
inline hgl::OSString ToOSString(const std::string &str)
{
return hgl::OSString(str.c_str(),str.size());
}
inline hgl::OSString ToOSString(const std::wstring &str)
{
return hgl::to_u8(str.c_str(),str.size());
}
inline std::string ToStdString(const hgl::OSString &str)
{
return std::string(str.c_str(),str.Length());
}
inline std::wstring ToStdWString(const OSString &str)
{
hgl::WideString w_str=hgl::to_wide<sizeof(wchar_t)>(str);
return std::wstring(w_str.c_str(),w_str.Length());
}
#endif//
inline hgl::UTF8String ToUTF8String(const std::string &str)
{
return hgl::UTF8String((hgl::u8char *)str.c_str(),int(str.size()));
}
} }

View File

@ -44,7 +44,7 @@ namespace hgl
} }
/** /**
* C指针风格字符串设置当前字符串内容(str需要delete[]) * C指针风格字符串设置当前字符串内容(str会被复制一份delete[])
* @param str len<00 * @param str len<00
* @param len str以0为结尾 * @param len str以0为结尾
*/ */

View File

@ -19,7 +19,7 @@ file(GLOB TYPE_TEMPLATE_HEADER ${TYPE_INCLUDE_PATH}/*.h)
SET(TYPE_SOURCE_FILES Type/Collection.cpp) SET(TYPE_SOURCE_FILES Type/Collection.cpp)
SOURCE_GROUP("DataType\\Collection" FILES ${TYPE_INCLUDE_PATH}/Collection.h SOURCE_GROUP("DataType\\Collection" FILES ${TYPE_INCLUDE_PATH}/Collection.h
${COLLECTION_SOURCE}) ${COLLECTION_SOURCE})
SET(SYSTEM_INFO_SOURCE ${CORE_PLATFORM_INCLUDE_PATH}/SystemInfo.h SET(SYSTEM_INFO_SOURCE ${CORE_PLATFORM_INCLUDE_PATH}/SystemInfo.h
@ -145,12 +145,11 @@ SET(IO_SOURCE_FILES ${IO_BASE_FILES}
SET(FILESYSTEM_INCLUDE_PATH ${CMCORE_ROOT_INCLUDE_PATH}/hgl/filesystem) SET(FILESYSTEM_INCLUDE_PATH ${CMCORE_ROOT_INCLUDE_PATH}/hgl/filesystem)
SET(FILESYSTEM_HEADER_FILES ${FILESYSTEM_INCLUDE_PATH}/EnumFile.h SET(FILESYSTEM_HEADER_FILES ${FILESYSTEM_INCLUDE_PATH}/EnumFile.h
${FILESYSTEM_INCLUDE_PATH}/EnumVolume.h ${FILESYSTEM_INCLUDE_PATH}/EnumVolume.h
${FILESYSTEM_INCLUDE_PATH}/Filename.h ${FILESYSTEM_INCLUDE_PATH}/FileSystem.h)
${FILESYSTEM_INCLUDE_PATH}/FileSystem.h)
SET(FILESYSTEM_SOURCE_FILES FileSystem/FileSystem.cpp SET(FILESYSTEM_SOURCE_FILES FileSystem/FileSystem.cpp
FileSystem/EnumFile.cpp) FileSystem/EnumFile.cpp)
SOURCE_GROUP("FileSystem" FILES ${FILESYSTEM_HEADER_FILES} ${FILESYSTEM_SOURCE_FILES}) SOURCE_GROUP("FileSystem" FILES ${FILESYSTEM_HEADER_FILES} ${FILESYSTEM_SOURCE_FILES})

View File

@ -1,5 +1,6 @@
#include<hgl/type/Color3f.h> #include<hgl/type/Color3f.h>
#include<hgl/type/Color.h> #include<hgl/type/Color.h>
#include<hgl/type/ColorSpace.h>
namespace hgl namespace hgl
{ {
void Color3f::Clamp() void Color3f::Clamp()
@ -16,8 +17,8 @@ namespace hgl
*/ */
void Color3f::To(float nr,float ng,float nb,float pos) void Color3f::To(float nr,float ng,float nb,float pos)
{ {
if(pos==0)return; if(pos<=0)return;
if(pos==1) if(pos>=1)
{ {
r=nr; r=nr;
g=ng; g=ng;
@ -29,7 +30,7 @@ namespace hgl
g+=(ng-g)*pos; g+=(ng-g)*pos;
b+=(nb-b)*pos; b+=(nb-b)*pos;
} }
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
void Color3f::Grey(float v1,float v2,float v3) void Color3f::Grey(float v1,float v2,float v3)
{ {
float lum=RGB2Lum(v1,v2,v3); float lum=RGB2Lum(v1,v2,v3);

View File

@ -1,5 +1,6 @@
#include<hgl/type/Color4f.h> #include<hgl/type/Color4f.h>
#include<hgl/type/Color.h> #include<hgl/type/Color.h>
#include<hgl/type/ColorSpace.h>
namespace hgl namespace hgl
{ {
void Color4f::Clamp() void Color4f::Clamp()
@ -17,8 +18,8 @@ namespace hgl
*/ */
void Color4f::To(float nr,float ng,float nb,float pos) void Color4f::To(float nr,float ng,float nb,float pos)
{ {
if(pos==0)return; if(pos<=0)return;
if(pos==1) if(pos>=1)
{ {
r=nr; r=nr;
g=ng; g=ng;

View File

@ -4,9 +4,9 @@ namespace hgl
{ {
CharSet DefaultCharSet(); CharSet DefaultCharSet();
CharSet UTF8CharSet (CharCodePage::UTF8, utf8_charset ); CharSet UTF8CharSet ((uint16)CharCodePage::UTF8, utf8_charset );
CharSet UTF16LECharSet (CharCodePage::UTF16LE,utf16le_charset ); CharSet UTF16LECharSet ((uint16)CharCodePage::UTF16LE,utf16le_charset );
CharSet UTF16BECharSet (CharCodePage::UTF16BE,utf16be_charset ); CharSet UTF16BECharSet ((uint16)CharCodePage::UTF16BE,utf16be_charset );
int u16_to_u8(u8char *dst,int dst_size,const u16char *src,const int src_size) int u16_to_u8(u8char *dst,int dst_size,const u16char *src,const int src_size)
{ {

89
src/URI.cpp Normal file
View File

@ -0,0 +1,89 @@
#include<hgl/URI.h>
namespace hgl
{
namespace
{
// https://en.wikipedia.org/wiki/List_of_TCP_and_UDP_port_numbers
struct SchemePort
{
uint16 port;
char scheme[16];
};
const SchemePort SchemePortList[]=
{
{7, "echo"},
{21, "ftp"},
{22, "ssh"},
{23, "telnet"},
{25, "smtp"},
{53, "dns"},
{69, "tftp"},
{80, "http"},
{80, "ws"},
{110, "pop3"},
{119, "nntp"},
{123, "ntp"},
{143, "imap"},
{161, "snmp"},
{162, "snmptrap"},
{194, "irc"},
{199, "smux"},
{389, "ldap"},
{443, "https"},
{443, "wss"},
{445, "smb"},
{465, "smtps"},
{548, "afp"}, //Apple File Services
{554, "rtsp"},
{636, "ldaps"},
{853, "dnss"},
{873, "rsync"},
{993, "imaps"},
{5060, "sip"},
{5061, "sips"},
{5222, "xmpp"}
};
}
const uint16 GetSchemePort(const char *scheme)
{
for(const SchemePort &sp:SchemePortList)
if(strcmp(scheme,sp.scheme)==0)
return sp.port;
return 0;
}
URI::URI(const OSString &fn)
{
origin_name=fn;
scheme_type=SchemeType::Unknow;
}
URI::URI(const OSString &scheme,const OSString &path,const OSString &filename)
{
scheme_name=scheme;
if(scheme=="file")
scheme_type=SchemeType::LocalFile;
else
}
const bool URI::isFile()
{
if(scheme_type==SchemeType::Unknow)
{
}
if(scheme_type==SchemeType::LocalFile)
return(true);
return(false);
}
}//namespace hgl