use "fromString/fromInstance“ instead of "SetString/SetInstance" in String<>

This commit is contained in:
hyzboy 2024-12-24 22:25:31 +08:00
parent dbbd145f03
commit 18efd0d6a6
4 changed files with 30 additions and 34 deletions

View File

@ -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
{

View File

@ -1,8 +1,7 @@
#ifndef HGL_TYPE_BASE_STRING_INCLUDE
#define HGL_TYPE_BASE_STRING_INCLUDE
#pragma once
#include<hgl/type/StringView.h>
#include<hgl/type/StringInstance.h>
#include<hgl/io/InputStream.h>
#include<hgl/Comparator.h>
#include<hgl/type/Smart.h>
@ -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<T> &sv)
{
fromString(sv.c_str(),sv.length());
}
/**
@ -65,24 +69,6 @@ namespace hgl
return String<T>(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<T> charOf(const T &ch)
@ -273,7 +259,7 @@ namespace hgl
* @param str len<00
* @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<00
* @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<T> ()const
{
return StringView<T>(c_str(),Length());
}
operator const StringView<T> &()const
{
return StringView<T>(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

View File

@ -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

View File

@ -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;
}