diff --git a/inc/hgl/filesystem/Filename.h b/inc/hgl/filesystem/Filename.h index c9d1683..0b02f94 100644 --- a/inc/hgl/filesystem/Filename.h +++ b/inc/hgl/filesystem/Filename.h @@ -132,7 +132,7 @@ namespace hgl { if(filename.GetFirstChar()==directory_separator_char) //开头有分隔符 { - fullname.SetString(pathname.c_str(),pathname.Length()-1); //少取一个字符 + fullname.fromString(pathname.c_str(),pathname.Length()-1); //少取一个字符 } else { diff --git a/inc/hgl/type/String.h b/inc/hgl/type/String.h index c487b1a..1e58e29 100644 --- a/inc/hgl/type/String.h +++ b/inc/hgl/type/String.h @@ -1,8 +1,7 @@ -#ifndef HGL_TYPE_BASE_STRING_INCLUDE -#define HGL_TYPE_BASE_STRING_INCLUDE +#pragma once +#include #include -#include #include #include @@ -40,7 +39,7 @@ namespace hgl */ String(const T *str) { - SetString(str); + fromString(str); } /** @@ -50,7 +49,12 @@ namespace hgl */ String(const T *str,int len) { - SetString(str,len); + fromString(str,len); + } + + String(const StringView &sv) + { + fromString(sv.c_str(),sv.length()); } /** @@ -65,24 +69,6 @@ namespace hgl return String(si); } - String(io::InputStream *is,int len=0) - { - if(len<=0) - len=is->Available(); - - if(len<=0) - return; - - len/=sizeof(T); - - T *str=new T[len+1]; - - len=is->Read(str,len*sizeof(T)); - - str[len]=0; - SetInstance(str,len); - } - String(const char)=delete; static String charOf(const T &ch) @@ -273,7 +259,7 @@ namespace hgl * @param str 字符串内容,在len<0的情况下,需以0为结尾 * @param len 字符串长度,如果str以0为结尾,可以为负值,将启用自动计算长度 */ - void SetString(const T *str,int len=-1) + void fromString(const T *str,int len=-1) { if(!str||!*str||!len) //len=-1为自检测,为0不处理 { @@ -290,7 +276,7 @@ namespace hgl * @param str 字符串内容,在len<0的情况下,需以0为结尾 * @param len 字符串长度 */ - void SetInstance(T *str,const uint len) + void fromInstance(T *str,const uint len) { if(!str||!*str) { @@ -304,12 +290,12 @@ namespace hgl void Strcpy(const T *str,int len=-1) { - SetString(str,len); + fromString(str,len); } void StrcpyInstance(T *str,int len=-1) { - SetInstance(str,len); + fromInstance(str,len); } /** @@ -464,7 +450,7 @@ namespace hgl } else { - SetString(str,len); + fromString(str,len); return(true); } } @@ -1241,6 +1227,16 @@ namespace hgl SelfClass &operator += (const SelfClass &str){Strcat(str);return(*this);} SelfClass &operator << (const SelfClass &str){return(operator+=(str));} + operator StringView ()const + { + return StringView(c_str(),Length()); + } + + operator const StringView &()const + { + return StringView(c_str(),Length()); + } + static SelfClass ComboString(const T *str1,int len1,const T *str2,int len2) { if(!str1||len1<=0) @@ -1424,4 +1420,3 @@ namespace hgl hgl::strcat(dst,max_count,src.c_str(),src.Length()); } }//namespace hgl -#endif//HGL_TYPE_BASE_STRING_INCLUDE diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index e43ed8b..0e838f7 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -107,6 +107,7 @@ SOURCE_GROUP("Datatype\\Color\\Source Files" FILES ${COLOR_SOURCE_FILES}) ##Text-------------------------------------------------------- SET(STRING_HEADER_FILES ${TYPE_INCLUDE_PATH}/String.h + ${TYPE_INCLUDE_PATH}/StringView.h ${TYPE_INCLUDE_PATH}/StringInstance.h ${TYPE_INCLUDE_PATH}/StringList.h ${TYPE_INCLUDE_PATH}/SplitString.h diff --git a/src/Text/LoadString.cpp b/src/Text/LoadString.cpp index e766d8c..71220b3 100644 --- a/src/Text/LoadString.cpp +++ b/src/Text/LoadString.cpp @@ -17,7 +17,7 @@ namespace hgl if(size>=3&&data[0]==0xEF&&data[1]==0xBB&&data[2]==0xBF) //utf8 { - full_text.SetString((u8char *)(data+3),size-3); + full_text.fromString((u8char *)(data+3),size-3); char_count=size-3; } else @@ -75,7 +75,7 @@ namespace hgl char_count=to_utf8(cs,&str,(char *)data,size); #endif// - full_text.SetString(str,char_count); + full_text.fromString(str,char_count); delete[] str; } @@ -130,7 +130,7 @@ namespace hgl if((uchar *)str>=data&&(uchar *)str<=data+size) //如果str的地址在data的范围内 { - full_text.SetString(str,char_count); + full_text.fromString(str,char_count); } else { @@ -156,7 +156,7 @@ namespace hgl #endif// } - full_text.SetString(str,char_count); + full_text.fromString(str,char_count); delete[] str; }