修正因char/u8char分离造成的各种强制类型转换错误

This commit is contained in:
hyzboy 2020-07-11 16:45:24 +08:00
parent 72f641c7a7
commit 353bdef68b
3 changed files with 71 additions and 71 deletions

View File

@ -203,7 +203,7 @@ namespace hgl
{ {
int wlen; int wlen;
u16char *ws=u8_to_u16(str,strlen(str),wlen); u16char *ws=u8_to_u16(str,hgl::strlen(str),wlen);
return UTF16String::newOf(ws,wlen); return UTF16String::newOf(ws,wlen);
} }

View File

@ -7,7 +7,7 @@
#if HGL_OS == HGL_OS_Windows #if HGL_OS == HGL_OS_Windows
inline hgl::OSString std_to_os(const std::string &str) inline hgl::OSString std_to_os(const std::string &str)
{ {
return hgl::to_u16((u8char *)str.c_str(),(int)(str.length())); return hgl::to_u16((hgl::u8char *)str.c_str(),(int)(str.length()));
} }
inline std::string to_std(const hgl::OSString &str) inline std::string to_std(const hgl::OSString &str)
@ -30,5 +30,5 @@ inline std::string to_std(const hgl::OSString &str)
inline hgl::UTF8String std_to_u8(const std::string &str) inline hgl::UTF8String std_to_u8(const std::string &str)
{ {
return hgl::UTF8String((u8char *)str.c_str(),int(str.size())); return hgl::UTF8String((hgl::u8char *)str.c_str(),int(str.size()));
} }

View File

@ -46,7 +46,7 @@ namespace hgl
* https://unicode.org/Public/emoji/12.0/emoji-data.txt * https://unicode.org/Public/emoji/12.0/emoji-data.txt
*/ */
template<typename T> template<typename T>
bool isemoji(const T ch) const bool isemoji(const T ch)
{ {
if(ch==0x23)return(true); //# if(ch==0x23)return(true); //#
if(ch==0x2A)return(true); //* if(ch==0x2A)return(true); //*
@ -62,7 +62,7 @@ namespace hgl
* *
*/ */
template<typename T> template<typename T>
bool islower(const T ch) const bool islower(const T ch)
{ {
return(ch>='a'&&ch<='z'); return(ch>='a'&&ch<='z');
} }
@ -71,7 +71,7 @@ namespace hgl
* *
*/ */
template<typename T> template<typename T>
bool isupper(const T ch) const bool isupper(const T ch)
{ {
return(ch>='A'&&ch<='Z'); return(ch>='A'&&ch<='Z');
} }
@ -80,7 +80,7 @@ namespace hgl
* *
*/ */
template<typename T> template<typename T>
bool isalpha(const T ch) const bool isalpha(const T ch)
{ {
return(islower(ch)||isupper(ch)); return(islower(ch)||isupper(ch));
} }
@ -89,7 +89,7 @@ namespace hgl
* 10 * 10
*/ */
template<typename T> template<typename T>
bool isdigit(const T ch) const bool isdigit(const T ch)
{ {
return(ch>='0'&&ch<='9'); return(ch>='0'&&ch<='9');
} }
@ -98,7 +98,7 @@ namespace hgl
* 10 * 10
*/ */
template<typename T> template<typename T>
bool isfloat(const T ch) const bool isfloat(const T ch)
{ {
return isdigit(ch) return isdigit(ch)
||ch=='-' ||ch=='-'
@ -109,7 +109,7 @@ namespace hgl
} }
template<typename T> template<typename T>
bool isinteger(const T ch) const bool isinteger(const T ch)
{ {
return isdigit(ch) return isdigit(ch)
||ch=='-' ||ch=='-'
@ -120,7 +120,7 @@ namespace hgl
* 16(0-9,A-F) * 16(0-9,A-F)
*/ */
template<typename T> template<typename T>
bool isxdigit(const T ch) const bool isxdigit(const T ch)
{ {
return((ch>='0'&&ch<='9') return((ch>='0'&&ch<='9')
||(ch>='a'&&ch<='f') ||(ch>='a'&&ch<='f')
@ -133,7 +133,7 @@ namespace hgl
* @param length * @param length
*/ */
template<typename T> template<typename T>
bool isxdigit(const T *str,int length) const bool isxdigit(const T *str,int length)
{ {
if(!str||length<=0) if(!str||length<=0)
return(false); return(false);
@ -154,7 +154,7 @@ namespace hgl
* (' ','\t','\r','\f','\v','\n') * (' ','\t','\r','\f','\v','\n')
*/ */
template<typename T> template<typename T>
bool isspace(const T ch) const bool isspace(const T ch)
{ {
return(ch==0 return(ch==0
||ch==' ' //半角空格 ||ch==' ' //半角空格
@ -170,7 +170,7 @@ namespace hgl
* *
*/ */
template<typename T> template<typename T>
bool isalnum(const T ch) const bool isalnum(const T ch)
{ {
return(isalpha(ch)||isdigit(ch)); return(isalpha(ch)||isdigit(ch));
} }
@ -179,7 +179,7 @@ namespace hgl
* (线) * (线)
*/ */
template<typename T> template<typename T>
bool iscodechar(const T ch) const bool iscodechar(const T ch)
{ {
return(isalnum(ch)||ch=='_'); return(isalnum(ch)||ch=='_');
} }
@ -188,7 +188,7 @@ namespace hgl
* BASE64编码字符 * BASE64编码字符
*/ */
template<typename T> template<typename T>
bool isbase64(const T c) const bool isbase64(const T c)
{ {
return (c == 43 || // + return (c == 43 || // +
(c >= 47 && c <= 57) || // /-9 (c >= 47 && c <= 57) || // /-9
@ -200,7 +200,7 @@ namespace hgl
* *
*/ */
template<typename T> template<typename T>
T tolower(const T ch) const T tolower(const T ch)
{ {
if(ch>='A'&&ch<='Z') if(ch>='A'&&ch<='Z')
return ch+('a'-'A'); return ch+('a'-'A');
@ -212,7 +212,7 @@ namespace hgl
* *
*/ */
template<typename T> template<typename T>
T toupper(const T ch) const T toupper(const T ch)
{ {
if(ch>='a'&&ch<='z') if(ch>='a'&&ch<='z')
return ch+('A'-'a'); return ch+('A'-'a');
@ -224,7 +224,7 @@ namespace hgl
* () * ()
*/ */
template<typename S,typename D> template<typename S,typename D>
int chricmp(S src,D dst) const int chricmp(S src,D dst)
{ {
return tolower(src)-tolower(dst); return tolower(src)-tolower(dst);
} }
@ -235,7 +235,7 @@ namespace hgl
* @return * @return
*/ */
template<typename T> template<typename T>
int strlen(const T *str) const int strlen(const T *str)
{ {
if(str&&*str) if(str&&*str)
{ {
@ -257,7 +257,7 @@ namespace hgl
* @return * @return
*/ */
template<typename T> template<typename T>
int strlen(const T *str,uint max_len) const int strlen(const T *str,uint max_len)
{ {
if(str&&*str) if(str&&*str)
{ {
@ -284,7 +284,7 @@ namespace hgl
* @return (<0) * @return (<0)
*/ */
template<typename T> template<typename T>
int strcpy(T *dst,int count,const T *src) const int strcpy(T *dst,int count,const T *src)
{ {
if(!dst)return(-1); if(!dst)return(-1);
@ -329,7 +329,7 @@ namespace hgl
* @return (<0) * @return (<0)
*/ */
template<typename T> template<typename T>
int strcpy(T *dst,int dst_count,const T *src,int count) const int strcpy(T *dst,int dst_count,const T *src,int count)
{ {
if(!dst)return(-1); if(!dst)return(-1);
@ -524,7 +524,7 @@ namespace hgl
* @return (<0) * @return (<0)
*/ */
template<typename T> template<typename T>
int strcat(T *dst,int max_count,const T *src,int count) const int strcat(T *dst,int max_count,const T *src,int count)
{ {
if(!dst||!src||!(*src)||count<=0)return(-1); if(!dst||!src||!(*src)||count<=0)return(-1);
@ -800,7 +800,7 @@ namespace hgl
* @return +1 src > dst * @return +1 src > dst
*/ */
template<typename S,typename D> template<typename S,typename D>
int strcmp(S *src,D *dst) const int strcmp(S *src,D *dst)
{ {
if(!src) if(!src)
{ {
@ -830,7 +830,7 @@ namespace hgl
* @return +1 src > dst * @return +1 src > dst
*/ */
template<typename S,typename D> template<typename S,typename D>
int strcmp(S *src,int src_size,D *dst,int dst_size) const int strcmp(S *src,int src_size,D *dst,int dst_size)
{ {
if(!src) if(!src)
{ {
@ -880,7 +880,7 @@ namespace hgl
* @return +1 src > dst * @return +1 src > dst
*/ */
template<typename S,typename D> template<typename S,typename D>
int strcmp(S *src,D *dst,int count) const int strcmp(S *src,D *dst,int count)
{ {
if(count<=0)return(0); if(count<=0)return(0);
@ -913,7 +913,7 @@ namespace hgl
* @return +1 src > dst * @return +1 src > dst
*/ */
template<typename S,typename D> template<typename S,typename D>
int stricmp(S *src,D *dst) const int stricmp(S *src,D *dst)
{ {
if(!src) if(!src)
{ {
@ -950,7 +950,7 @@ namespace hgl
* @return +1 src > dst * @return +1 src > dst
*/ */
template<typename S,typename D> template<typename S,typename D>
int stricmp(S *src,int src_size,D *dst,int dst_size) const int stricmp(S *src,int src_size,D *dst,int dst_size)
{ {
if(!src) if(!src)
{ {
@ -1009,7 +1009,7 @@ namespace hgl
* @return +1 src > dst * @return +1 src > dst
*/ */
template<typename S,typename D> template<typename S,typename D>
int stricmp(S *src,D *dst,int count) const int stricmp(S *src,D *dst,int count)
{ {
if(!src) if(!src)
{ {
@ -1043,7 +1043,7 @@ namespace hgl
* , * ,
*/ */
template<typename S,typename D> template<typename S,typename D>
int charset_cmp(S *src,D *dst) const int charset_cmp(S *src,D *dst)
{ {
if(!src) if(!src)
{ {
@ -1235,7 +1235,7 @@ namespace hgl
* @return * @return
*/ */
template<typename T> template<typename T>
int replace(T *str,const T tch,const T sch) const int replace(T *str,const T tch,const T sch)
{ {
if(!str) if(!str)
return(0); return(0);
@ -1354,7 +1354,7 @@ namespace hgl
* *
*/ */
template<typename T> template<typename T>
uint lower_cpy(T *target,const T *source) const uint lower_cpy(T *target,const T *source)
{ {
if(!target||!source)return 0; if(!target||!source)return 0;
uint count=0; uint count=0;
@ -1379,7 +1379,7 @@ namespace hgl
* *
*/ */
template<typename T> template<typename T>
uint upper_cpy(T *target,const T *source) const uint upper_cpy(T *target,const T *source)
{ {
if(!target||!source)return 0; if(!target||!source)return 0;
uint count=0; uint count=0;
@ -1404,7 +1404,7 @@ namespace hgl
* *
*/ */
template<typename T> template<typename T>
uint lower_cpy(T *target,const T *source,int source_max) const uint lower_cpy(T *target,const T *source,int source_max)
{ {
if(!target||!source)return 0; if(!target||!source)return 0;
uint count=0; uint count=0;
@ -1431,7 +1431,7 @@ namespace hgl
* *
*/ */
template<typename T> template<typename T>
uint upper_cpy(T *target,const T *source,int source_max) const uint upper_cpy(T *target,const T *source,int source_max)
{ {
if(!target||!source)return 0; if(!target||!source)return 0;
uint count=0; uint count=0;
@ -1457,7 +1457,7 @@ namespace hgl
* *
*/ */
template<typename T> template<typename T>
uint lower_clip_cpy(T *target,const T *source) const uint lower_clip_cpy(T *target,const T *source)
{ {
if(!target||!source)return 0; if(!target||!source)return 0;
uint count=0; uint count=0;
@ -1487,7 +1487,7 @@ namespace hgl
* *
*/ */
template<typename T> template<typename T>
uint upper_clip_cpy(T *target,const T *source) const uint upper_clip_cpy(T *target,const T *source)
{ {
if(!target||!source)return 0; if(!target||!source)return 0;
uint count=0; uint count=0;
@ -1516,7 +1516,7 @@ namespace hgl
* *
*/ */
template<typename T> template<typename T>
uint lower_clip_cpy(T *target,const T *source,int source_max) const uint lower_clip_cpy(T *target,const T *source,int source_max)
{ {
if(!target||!source)return 0; if(!target||!source)return 0;
uint count=0; uint count=0;
@ -1547,7 +1547,7 @@ namespace hgl
* *
*/ */
template<typename T> template<typename T>
uint upper_clip_cpy(T *target,const T *source,int source_max) const uint upper_clip_cpy(T *target,const T *source,int source_max)
{ {
if(!target||!source)return 0; if(!target||!source)return 0;
uint count=0; uint count=0;
@ -1580,7 +1580,7 @@ namespace hgl
* @return * @return
*/ */
template<typename T> template<typename T>
int stat_char(T *str,T ch) const int stat_char(T *str,T ch)
{ {
if(!str)return(0); if(!str)return(0);
@ -1601,7 +1601,7 @@ namespace hgl
* *
*/ */
template<typename T> template<typename T>
int stat_line(T *str) const int stat_line(T *str)
{ {
if(!str)return(0); if(!str)return(0);
@ -1612,7 +1612,7 @@ namespace hgl
} }
template<typename R,typename S> template<typename R,typename S>
bool stoi(S *str,R &result) const bool stoi(S *str,R &result)
{ {
if(!str) if(!str)
{ {
@ -1647,7 +1647,7 @@ namespace hgl
} }
template<typename R,typename S> template<typename R,typename S>
bool stoi(S *str,int size,R &result) const bool stoi(S *str,int size,R &result)
{ {
if(!str||size<=0) if(!str||size<=0)
{ {
@ -1687,7 +1687,7 @@ namespace hgl
} }
template<typename R,typename S> template<typename R,typename S>
bool stou(S *str,R &result) const bool stou(S *str,R &result)
{ {
if(!str) if(!str)
{ {
@ -1709,7 +1709,7 @@ namespace hgl
} }
template<typename R,typename S> template<typename R,typename S>
bool stou(S *str,int size,R &result) const bool stou(S *str,int size,R &result)
{ {
if(!str||size<=0) if(!str||size<=0)
{ {
@ -1732,7 +1732,7 @@ namespace hgl
} }
template<typename R,typename S> template<typename R,typename S>
bool xtou(S *str,R &result) const bool xtou(S *str,R &result)
{ {
if(!str) if(!str)
{ {
@ -1762,7 +1762,7 @@ namespace hgl
} }
template<typename R,typename S> template<typename R,typename S>
bool xtou(S *str,int size,R &result) const bool xtou(S *str,int size,R &result)
{ {
if(!str||size<=0) if(!str||size<=0)
{ {
@ -1793,7 +1793,7 @@ namespace hgl
} }
template<typename R,typename S> template<typename R,typename S>
bool stof(S *str,R &result) const bool stof(S *str,R &result)
{ {
if(!str) if(!str)
{ {
@ -1850,7 +1850,7 @@ namespace hgl
} }
template<typename R,typename S> template<typename R,typename S>
bool stof(S *str,int size,R &result) const bool stof(S *str,int size,R &result)
{ {
if(!str||size<=0) if(!str||size<=0)
{ {
@ -1917,7 +1917,7 @@ namespace hgl
* ("1.0123e-10") * ("1.0123e-10")
*/ */
template<typename R,typename S> template<typename R,typename S>
bool etof(S *str,R &result) const bool etof(S *str,R &result)
{ {
double temp; double temp;
@ -1957,7 +1957,7 @@ namespace hgl
* @return * @return
*/ */
template<typename T> template<typename T>
bool stob(T *str,bool &value) const bool stob(T *str,bool &value)
{ {
if(!str) if(!str)
{ {
@ -1988,7 +1988,7 @@ namespace hgl
* @return * @return
*/ */
template<typename T,typename I> template<typename T,typename I>
int itos_rl(T *str,int size,const I num) const int itos_rl(T *str,int size,const I num)
{ {
if(!str||size<=0)return(-1); if(!str||size<=0)return(-1);
@ -2227,7 +2227,7 @@ namespace hgl
* @return * @return
*/ */
template<typename T,typename V> template<typename T,typename V>
bool int_to_size(T *str,int size,V value) const bool int_to_size(T *str,int size,V value)
{ {
const T name[]={'K','M','G','T','P','E','Z','Y','B',0}; const T name[]={'K','M','G','T','P','E','Z','Y','B',0};
@ -2262,7 +2262,7 @@ namespace hgl
} }
template<typename T> template<typename T>
int find_str_array(int count,const T **str_array,const T *str) const int find_str_array(int count,const T **str_array,const T *str)
{ {
for(int i=1;i<count;i++) for(int i=1;i<count;i++)
if(stricmp<T>(str_array[i],str)==0)return(i); if(stricmp<T>(str_array[i],str)==0)return(i);
@ -2280,7 +2280,7 @@ namespace hgl
* @return * @return
*/ */
template<typename T,typename I,bool (*IS_FUNC)(const T &),bool (*STOV)(const T *str,I &)> template<typename T,typename I,bool (*IS_FUNC)(const T &),bool (*STOV)(const T *str,I &)>
int parse_number_array(const T *str,I *result,int max_count,const T end_char=0,const T **end_pointer=0) const int parse_number_array(const T *str,I *result,int max_count,const T end_char=0,const T **end_pointer=0)
{ {
if(!str||!result||max_count<=0)return(-1); if(!str||!result||max_count<=0)return(-1);
@ -2337,10 +2337,10 @@ namespace hgl
return(count); return(count);
} }
template<typename T,typename I> inline int parse_float_array(const T *str,I *result,int max_count,const T end_char=0,const T **end_pointer=0){return parse_number_array<T,I,hgl::isfloat, hgl::etof>(str,result,max_count,end_char,end_pointer);} template<typename T,typename I> inline const int parse_float_array(const T *str,I *result,int max_count,const T end_char=0,const T **end_pointer=0){return parse_number_array<T,I,hgl::isfloat, hgl::etof>(str,result,max_count,end_char,end_pointer);}
template<typename T,typename I> inline int parse_int_array (const T *str,I *result,int max_count,const T end_char=0,const T **end_pointer=0){return parse_number_array<T,I,hgl::isinteger, hgl::stoi>(str,result,max_count,end_char,end_pointer);} template<typename T,typename I> inline const int parse_int_array (const T *str,I *result,int max_count,const T end_char=0,const T **end_pointer=0){return parse_number_array<T,I,hgl::isinteger, hgl::stoi>(str,result,max_count,end_char,end_pointer);}
template<typename T,typename I> inline int parse_uint_array (const T *str,I *result,int max_count,const T end_char=0,const T **end_pointer=0){return parse_number_array<T,I,hgl::isdigit, hgl::stou>(str,result,max_count,end_char,end_pointer);} template<typename T,typename I> inline const int parse_uint_array (const T *str,I *result,int max_count,const T end_char=0,const T **end_pointer=0){return parse_number_array<T,I,hgl::isdigit, hgl::stou>(str,result,max_count,end_char,end_pointer);}
template<typename T,typename I> inline int parse_xint_array (const T *str,I *result,int max_count,const T end_char=0,const T **end_pointer=0){return parse_number_array<T,I,hgl::isxdigit, hgl::xtou>(str,result,max_count,end_char,end_pointer);} template<typename T,typename I> inline const int parse_xint_array (const T *str,I *result,int max_count,const T end_char=0,const T **end_pointer=0){return parse_number_array<T,I,hgl::isxdigit, hgl::xtou>(str,result,max_count,end_char,end_pointer);}
/** /**
* ,"1,2,3""1 2 3" * ,"1,2,3""1 2 3"
@ -2351,7 +2351,7 @@ namespace hgl
* @return -1 * @return -1
*/ */
template<typename T,typename I,typename SET,bool (*IS_FUNC)(const T &),bool (*STOV)(const T *str,I &)> template<typename T,typename I,typename SET,bool (*IS_FUNC)(const T &),bool (*STOV)(const T *str,I &)>
int parse_number_array(const T *str,const int str_len,SET &result_list) const int parse_number_array(const T *str,const int str_len,SET &result_list)
{ {
if(!str||str_len<=0)return(-1); if(!str||str_len<=0)return(-1);
@ -2397,10 +2397,10 @@ namespace hgl
return(count); return(count);
} }
template<typename T,typename I,typename SET> inline int parse_float_array (const T *str,const int len,SET &result_list){return parse_number_array<T,I,SET,hgl::isfloat, hgl::etof>(str,len,result_list);} template<typename T,typename I,typename SET> inline const int parse_float_array (const T *str,const int len,SET &result_list){return parse_number_array<T,I,SET,hgl::isfloat, hgl::etof>(str,len,result_list);}
template<typename T,typename I,typename SET> inline int parse_int_array (const T *str,const int len,SET &result_list){return parse_number_array<T,I,SET,hgl::isinteger, hgl::stoi>(str,len,result_list);} template<typename T,typename I,typename SET> inline const int parse_int_array (const T *str,const int len,SET &result_list){return parse_number_array<T,I,SET,hgl::isinteger, hgl::stoi>(str,len,result_list);}
template<typename T,typename I,typename SET> inline int parse_uint_array (const T *str,const int len,SET &result_list){return parse_number_array<T,I,SET,hgl::isdigit, hgl::stou>(str,len,result_list);} template<typename T,typename I,typename SET> inline const int parse_uint_array (const T *str,const int len,SET &result_list){return parse_number_array<T,I,SET,hgl::isdigit, hgl::stou>(str,len,result_list);}
template<typename T,typename I,typename SET> inline int parse_xint_array (const T *str,const int len,SET &result_list){return parse_number_array<T,I,SET,hgl::isxdigit, hgl::xtou>(str,len,result_list);} template<typename T,typename I,typename SET> inline const int parse_xint_array (const T *str,const int len,SET &result_list){return parse_number_array<T,I,SET,hgl::isxdigit, hgl::xtou>(str,len,result_list);}
/** /**
* *
@ -2412,7 +2412,7 @@ namespace hgl
* @return -1 * @return -1
*/ */
template<typename T,typename S> template<typename T,typename S>
int split_string(const T *str,const int str_len,const T &sc,S &result_list) const int split_string(const T *str,const int str_len,const T &sc,S &result_list)
{ {
if(!str||!(*str))return(-1); if(!str||!(*str))return(-1);
if(str_len<=0)return(-1); if(str_len<=0)return(-1);
@ -2457,7 +2457,7 @@ namespace hgl
* @param str * @param str
* @return ,-1 * @return ,-1
*/ */
template<typename T> int string_to_enum(const T **list,const T *str) template<typename T> const int string_to_enum(const T **list,const T *str)
{ {
if(!str||!list)return(-1); if(!str||!list)return(-1);
@ -2477,7 +2477,7 @@ namespace hgl
/** /**
* 使线使 * 使线使
*/ */
template<typename T> bool check_codestr(const T *str) template<typename T> const bool check_codestr(const T *str)
{ {
if(!str)return(false); if(!str)return(false);
@ -2499,7 +2499,7 @@ namespace hgl
/** /**
* 使 * 使
*/ */
template<typename T> bool check_error_char(const T *str) template<typename T> const bool check_error_char(const T *str)
{ {
if(!str)return(false); if(!str)return(false);
@ -2553,7 +2553,7 @@ namespace hgl
* @param num * @param num
* @return * @return
*/ */
inline int parse_dec_number_char(const int ch) inline const int parse_dec_number_char(const int ch)
{ {
if(ch>='0'&&ch<='9') if(ch>='0'&&ch<='9')
return ch-'0'; return ch-'0';
@ -2567,7 +2567,7 @@ namespace hgl
* @return * @return
*/ */
template<uint NUM,typename T> template<uint NUM,typename T>
inline int parse_number_char(const T ch) inline const int parse_number_char(const T ch)
{ {
if(ch>='0'&&ch<='9') if(ch>='0'&&ch<='9')
return ch-'0'; return ch-'0';