add StringList to String function.

This commit is contained in:
2020-09-11 16:28:32 +08:00
parent 7cf856b4ee
commit c140850e37
2 changed files with 43 additions and 0 deletions

View File

@@ -49,6 +49,9 @@ namespace hgl
SetString(str,len);
}
/**
* 基于一块已经创建好的内存创建字符串类
*/
static String<T> newOf(T *str,const uint len)
{
StringInstance<T> *si=new StringInstance<T>();

View File

@@ -576,6 +576,46 @@ namespace hgl
return SplitToMultiStringList<T>(sl,slc,str.c_str(),str.Length());
}
/**
* 将一个字符串列表整合成一个字符串
* @param sl 要整合的字符串列表
* @param end_line 换行符
* @return 字符串
*/
template<typename T> String<T> ToString(const StringList<String<T>> &sl,const String<T> &end_line)
{
int total_chars=0;
const int line=sl.GetCount();
String<T> **sp=sl.GetDataList();
for(int i=0;i<line;i++)
{
total_chars+=(*sp)->Length();
++sp;
}
total_chars+=line*end_line.Length();
T *str=new T[total_chars+1];
T *tp=str;
sp=sl.GetDataList();
for(int i=0;i<line;i++)
{
hgl_typecpy(tp,(*sp)->c_str(),(*sp)->Length());
tp+=(*sp)->Length();
hgl_typecpy(tp,end_line.c_str(),end_line.Length());
tp+=end_line.Length();
++sp;
}
str[total_chars]=0;
return String<T>::newOf(str,total_chars);
}
using UTF8StringList=StringList< UTF8String>;
using UTF16StringList=StringList<UTF16String>;
using UTF32StringList=StringList<UTF32String>;