场景:
1. 很多情况下需要通过文件夹和文件名拼接文件路径字符串,每次都需要判断是否需要添加路径分隔符seperator很麻烦,所以可以写一个通用函数.
2. 大多数情况下都是windows使用wstring,mac使用string,所以用模版实现最通用.
3. Cocoa里的NSString有这个方法是相同的作用,stringByAppendingPathComponent.
函数:
template<class T>
T AppendPathComponent(const T& source,const T& component)
{
int length = source.length();
int last = (length)?(length-1):0;
if(source[last] == 0x5C || source[last] == 0x2F)
{
return source+component;
}else
{
T path(source);
path.resize(length+1);
path[length] = 0x2F;
path.append(component);
return path;
}
}
inline char* Unicode2Ansi(const wchar_t* unicode)
{
i