From 93a2713ba757763108355ba52018c47763f1cd44 Mon Sep 17 00:00:00 2001 From: hyzboy Date: Mon, 14 Sep 2020 19:51:30 +0800 Subject: [PATCH] append TrimFileExtName function. --- inc/hgl/filesystem/FileSystem.h | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/inc/hgl/filesystem/FileSystem.h b/inc/hgl/filesystem/FileSystem.h index bf34479..bf1089b 100644 --- a/inc/hgl/filesystem/FileSystem.h +++ b/inc/hgl/filesystem/FileSystem.h @@ -116,6 +116,28 @@ namespace hgl fullname.SubString(pos+1, end-(pos+1)); } + /** + * 清除完整文件名中的扩展名 + * @param fullname 完整文件名 + * @param include_dot 是否包括点也清除 + */ + template + inline String TrimFileExtName(const String &fullname,bool include_dot=false) + { + int end=fullname.FindChar(T('?')); //url的文件名,以?为结束 + + if(end==-1) + end=fullname.Length(); + + int pos=fullname.FindRightChar(fullname.Length()-end,T('.')); + + if(pos==-1) + return String(); + + return include_dot? fullname.SubString(0,pos): + fullname.SubString(0,pos+1); + } + /** * 截取路径最后一个名字 */