旧的恢复MergeFilename,新的Combine重写并测试

This commit is contained in:
hyzboy 2025-03-27 23:40:43 +08:00
parent 54f484c442
commit d09fe4326e
5 changed files with 47 additions and 65 deletions

View File

@ -60,7 +60,7 @@ namespace hgl
virtual EnumFileConfig *CreateSubConfig(struct EnumFileConfig *up_efc,const FileInfo &fi) virtual EnumFileConfig *CreateSubConfig(struct EnumFileConfig *up_efc,const FileInfo &fi)
{ {
const OSString full_sub_folder_name=Combine(up_efc->folder_name,fi.name); const OSString full_sub_folder_name=MergeFilename(up_efc->folder_name,fi.name);
return(new EnumFileConfig(up_efc,full_sub_folder_name)); return(new EnumFileConfig(up_efc,full_sub_folder_name));
} }

View File

@ -3,6 +3,7 @@
#include<hgl/type/StringList.h> #include<hgl/type/StringList.h>
#include<hgl/math/PrimaryMathematics.h> #include<hgl/math/PrimaryMathematics.h>
#include<initializer_list>
/** /**
* Maximum Path Length Limitation * Maximum Path Length Limitation
@ -73,21 +74,17 @@ namespace hgl
return String<T>::newOf(fullname,p-fullname); return String<T>::newOf(fullname,p-fullname);
} }
template<typename T,typename ...ARGS> template<typename T>
inline const String<T> Combine(const T spear_char,const T *str1,ARGS...args) inline const String<T> CombineFilename(const T spear_char,const std::initializer_list<const T *> &args)
{ {
const int count=sizeof...(ARGS); if(args.size()<=0)
return String<T>();
if(count<=0) int total=0;
return String<T>(str1); AutoDeleteArray<int> str_len(args.size());
int total_len=hgl::strlen(str1);
AutoDeleteArray<int> str_len[count+1];
str_len[0]=total_len;
{ {
int index=1; int index=0;
for(const T *str:args) for(const T *str:args)
{ {
str_len[index]=hgl::strlen(str); str_len[index]=hgl::strlen(str);
@ -99,56 +96,48 @@ namespace hgl
T *fullname=new T[total]; T *fullname=new T[total];
T *p=fullname; T *p=fullname;
hgl_cpy<T>(p,str1,str_len[0]);
p+=str_len[0];
{ {
int index=1; int index=0;
for(const T *str:args) for(const T *str:args)
{ {
hgl_cpy<T>(p,str,str_len[index]);
p+=(int)str_len[index];
*p=spear_char; *p=spear_char;
++p; ++p;
hgl_cpy<T>(p,str,str_len[index])
p+=str_len[index];
} }
fullename[total-1]=0; fullname[total-1]=0;
} }
return String<T>::newOf(fullname,total-1); return String<T>::newOf(fullname,total-1);
} }
template<typename ...ARGS> inline const String<char> Combine(const std::initializer_list<const char *> &args)
inline const String<char> Combine(const char *str1,ARGS...args)
{ {
return Combine<char>(HGL_DIRECTORY_SEPARATOR_RAWCHAR,str1,args...); return CombineFilename<char>(HGL_DIRECTORY_SEPARATOR_RAWCHAR,args);
} }
#ifdef HGL_SUPPORT_CHAR8_T #ifdef HGL_SUPPORT_CHAR8_T
template<typename ...ARGS> inline const String<char8_t> Combine(const std::initializer_list<const char8_t *> &args)
inline const String<char8_t> Combine(const char8_t *str1,ARGS...args)
{ {
return Combine<char8_t>(HGL_DIRECTORY_SEPARATOR_U8CHAR,str1,args...); return CombineFilename<char8_t>(HGL_DIRECTORY_SEPARATOR_U8CHAR,args);
} }
#endif//HGL_SUPPORT_CHAR8_T #endif//HGL_SUPPORT_CHAR8_T
#if HGL_OS == HGL_OS_Windows #if HGL_OS == HGL_OS_Windows
template<typename ...ARGS> inline const String<wchar_t> Combine(const std::initializer_list<const wchar_t *> &args)
inline const String<wchar_t> Combine(const wchar_t *str1,ARGS...args)
{ {
return Combine<wchar_t>(HGL_DIRECTORY_SEPARATOR_WCHAR,str1,args...); return CombineFilename<wchar_t>(HGL_DIRECTORY_SEPARATOR_WCHAR,args);
} }
#endif//HGL_OS == HGL_OS_Windows #endif//HGL_OS == HGL_OS_Windows
template<typename T,typename ...ARGS> template<typename T>
inline const String<T> Combine(const T spear_char,const String<T> &str1,ARGS...args) inline const String<T> CombineFilename(const T spear_char,const std::initializer_list<const String<T>> &args)
{ {
const int count=sizeof...(ARGS); if(args.size()<=0)
return String<T>();
if(count<=0) int total=0;
return str1;
int total_len=str1.Length()
for(const String<T> &str:args) for(const String<T> &str:args)
total+=str.Length()+1; total+=str.Length()+1;
@ -156,44 +145,37 @@ namespace hgl
T *fullname=new T[total]; T *fullname=new T[total];
T *p=fullname; T *p=fullname;
hgl_cpy<T>(p,str1.c_str(),str1.Length());
p+=str1.Length();
{ {
int index=1;
for(const String<T> &str:args) for(const String<T> &str:args)
{ {
hgl_cpy<T>(p,str.c_str(),str.Length());
p+=str.Length();
*p=spear_char; *p=spear_char;
++p; ++p;
hgl_cpy<T>(p,str.c_str(),str.Length())
p+=str1.Length();
} }
fullename[total-1]=0; fullname[total-1]=0;
} }
return String<T>::newOf(fullname,total-1); return String<T>::newOf(fullname,total-1);
} }
template<typename ...ARGS> inline const String<char> Combine(const std::initializer_list<const String<char>> &args)
inline const String<char> Combine(const String<char> &str1,ARGS...args)
{ {
return Combine<char>(HGL_DIRECTORY_SEPARATOR_RAWCHAR,str1,args...); return CombineFilename<char>(HGL_DIRECTORY_SEPARATOR_RAWCHAR,args);
} }
#ifdef HGL_SUPPORT_CHAR8_T #ifdef HGL_SUPPORT_CHAR8_T
template<typename ...ARGS> inline const String<char8_t> Combine(const std::initializer_list<const String<char8_t>> &args)
inline const String<char8_t> Combine(const String<char8_t> &str1,ARGS...args)
{ {
return Combine<char8_t>(HGL_DIRECTORY_SEPARATOR_U8CHAR,str1,args...); return CombineFilename<char8_t>(HGL_DIRECTORY_SEPARATOR_U8CHAR,args);
} }
#endif//HGL_SUPPORT_CHAR8_T #endif//HGL_SUPPORT_CHAR8_T
#if HGL_OS == HGL_OS_Windows #if HGL_OS == HGL_OS_Windows
template<typename ...ARGS> inline const String<wchar_t> Combine(const std::initializer_list<const String<wchar_t>> &args)
inline const String<wchar_t> Combine(const String<wchar_t> &str1,ARGS...args)
{ {
return Combine<wchar_t>(HGL_DIRECTORY_SEPARATOR_WCHAR,str1,args...); return CombineFilename<wchar_t>(HGL_DIRECTORY_SEPARATOR_WCHAR,args);
} }
#endif//HGL_OS == HGL_OS_Windows #endif//HGL_OS == HGL_OS_Windows
@ -248,7 +230,7 @@ namespace hgl
* *
*/ */
template<typename T> template<typename T>
inline String<T> Combine(const String<T> &pathname,const String<T> &filename,const T directory_separator_char,const T *directory_separator_str) inline String<T> MergeFilename(const String<T> &pathname,const String<T> &filename,const T directory_separator_char,const T *directory_separator_str)
{ {
String<T> fullname; String<T> fullname;
@ -493,16 +475,16 @@ namespace hgl
} }
#ifdef HGL_SUPPORT_CHAR8_T #ifdef HGL_SUPPORT_CHAR8_T
inline AnsiString Combine(const AnsiString &pathname,const AnsiString &filename) ///<组合路径名与文件名 inline AnsiString MergeFilename(const AnsiString &pathname,const AnsiString &filename) ///<组合路径名与文件名
{return Combine<char>(pathname,filename,HGL_DIRECTORY_SEPARATOR,HGL_DIRECTORY_SEPARATOR_RAWSTR);} {return MergeFilename<char>(pathname,filename,HGL_DIRECTORY_SEPARATOR,HGL_DIRECTORY_SEPARATOR_RAWSTR);}
#endif//HGL_SUPPORT_CHAR8_T #endif//HGL_SUPPORT_CHAR8_T
inline U8String Combine(const U8String &pathname,const U8String &filename) ///<组合路径名与文件名 inline U8String MergeFilename(const U8String &pathname,const U8String &filename) ///<组合路径名与文件名
{return Combine<u8char>(pathname,filename,HGL_DIRECTORY_SEPARATOR,HGL_DIRECTORY_SEPARATOR_U8STR);} {return MergeFilename<u8char>(pathname,filename,HGL_DIRECTORY_SEPARATOR,HGL_DIRECTORY_SEPARATOR_U8STR);}
#if HGL_OS == HGL_OS_Windows #if HGL_OS == HGL_OS_Windows
inline WString Combine(const WString &pathname,const WString &filename) ///<组合路径名与文件名 inline WString MergeFilename(const WString &pathname,const WString &filename) ///<组合路径名与文件名
{return Combine<wchar_t>(pathname,filename,HGL_DIRECTORY_SEPARATOR,HGL_DIRECTORY_SEPARATOR_STR);} {return MergeFilename<wchar_t>(pathname,filename,HGL_DIRECTORY_SEPARATOR,HGL_DIRECTORY_SEPARATOR_STR);}
#endif//HGL_OS == HGL_OS_Windows #endif//HGL_OS == HGL_OS_Windows
OSString FixFilename(const OSString &filename); ///<修正部分文件名问题 OSString FixFilename(const OSString &filename); ///<修正部分文件名问题

View File

@ -397,7 +397,7 @@ namespace hgl
for(const OSString *pn:paths) for(const OSString *pn:paths)
{ {
full_filename=Combine(*pn,filename); full_filename=MergeFilename(*pn,filename);
exist=FileExist(full_filename); exist=FileExist(full_filename);
@ -431,7 +431,7 @@ namespace hgl
{ {
for(const OSString *fn:filenames) for(const OSString *fn:filenames)
{ {
full_filename=Combine(*pn,*fn); full_filename=MergeFilename(*pn,*fn);
exist=FileExist(full_filename); exist=FileExist(full_filename);

View File

@ -41,12 +41,12 @@ namespace hgl
if(!GetLocalAppdataPath(local_app_data_path)) if(!GetLocalAppdataPath(local_app_data_path))
return(false); return(false);
cmgdk_path=filesystem::Combine(local_app_data_path,OS_TEXT(".cmgdk")); cmgdk_path=filesystem::MergeFilename(local_app_data_path,OS_TEXT(".cmgdk"));
if(!filesystem::MakePath(cmgdk_path)) if(!filesystem::MakePath(cmgdk_path))
return(false); return(false);
fn=filesystem::Combine(cmgdk_path,project_code); fn=filesystem::MergeFilename(cmgdk_path,project_code);
for(uint i=0;i<=0xFFFF;i++) for(uint i=0;i<=0xFFFF;i++)
{ {

View File

@ -15,7 +15,7 @@ namespace hgl
{ {
AddFindPath(pn); AddFindPath(pn);
pn=Combine(pn,OS_TEXT("Plug-ins")); pn=MergeFilename(pn,OS_TEXT("Plug-ins"));
AddFindPath(pn); AddFindPath(pn);
} }
@ -23,7 +23,7 @@ namespace hgl
{ {
AddFindPath(pn); AddFindPath(pn);
pn=Combine(pn,OS_TEXT("Plug-ins")); pn=MergeFilename(pn,OS_TEXT("Plug-ins"));
AddFindPath(pn); AddFindPath(pn);
} }
} }
@ -105,7 +105,7 @@ namespace hgl
for(uint i=0;i<fp_count;i++) for(uint i=0;i<fp_count;i++)
{ {
pi_fullfilename=Combine(findpath[i],pi_filename); pi_fullfilename=MergeFilename(findpath[i],pi_filename);
if(!FileExist(pi_fullfilename))continue; if(!FileExist(pi_fullfilename))continue;