From 4e1f76fae58a7e0db111ec68e616e6ea3222f726 Mon Sep 17 00:00:00 2001 From: gcontini <1121667+gcontini@users.noreply.github.com> Date: 周日, 13 10月 2019 16:17:06 +0800 Subject: [PATCH] fix windows tests --- src/library/base/FileUtils.cpp | 19 +++++++++++++++++++ 1 files changed, 19 insertions(+), 0 deletions(-) diff --git a/src/library/base/FileUtils.cpp b/src/library/base/FileUtils.cpp index 55e4fdd..ff79406 100644 --- a/src/library/base/FileUtils.cpp +++ b/src/library/base/FileUtils.cpp @@ -42,4 +42,23 @@ throw(errno); } +string remove_extension(const string& path) { + if (path == "." || path == "..") { + return path; + } + size_t dotpos = path.find_last_of("."); + //no dot + if (dotpos == string::npos) { + return path; + } + //find the last path separator + size_t pathsep_pos = path.find_last_of("\\/"); + if (pathsep_pos == string::npos) { + return (dotpos == 0 ? path : path.substr(0, dotpos)); + } else if(pathsep_pos >= dotpos +1) { + return path; + } + return path.substr(0, dotpos); +} + } -- Gitblit v1.9.1