Merge pull request #590 from fcharlie/master
fix split_by_extenstion parse error extenstion
This commit is contained in:
commit
dd0b7b2d13
@ -118,17 +118,18 @@ public:
|
|||||||
//
|
//
|
||||||
// "my_folder/.mylog" => ("my_folder/.mylog")
|
// "my_folder/.mylog" => ("my_folder/.mylog")
|
||||||
// "my_folder/.mylog.txt" => ("my_folder/.mylog", ".txt")
|
// "my_folder/.mylog.txt" => ("my_folder/.mylog", ".txt")
|
||||||
|
|
||||||
static std::tuple<filename_t, filename_t> split_by_extenstion(const filename_t& fname)
|
static std::tuple<filename_t, filename_t> split_by_extenstion(const filename_t& fname)
|
||||||
{
|
{
|
||||||
auto index = fname.rfind('.');
|
auto index = fname.rfind('.');
|
||||||
bool found_ext = index != filename_t::npos && index !=0 && fname[index - 1] != details::os::folder_sep;
|
if (index != filename_t::npos && index != fname.size() - 1 &&index !=0 && fname[index - 1] != details::os::folder_sep)
|
||||||
if (found_ext)
|
{
|
||||||
|
auto index2 = fname.find(details::os::folder_sep, index);
|
||||||
|
if (index2 == fname.npos) {
|
||||||
return std::make_tuple(fname.substr(0, index), fname.substr(index));
|
return std::make_tuple(fname.substr(0, index), fname.substr(index));
|
||||||
else
|
|
||||||
return std::make_tuple(fname, filename_t());
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
return std::make_tuple(fname, std::string());
|
||||||
|
}
|
||||||
private:
|
private:
|
||||||
FILE* _fd;
|
FILE* _fd;
|
||||||
filename_t _filename;
|
filename_t _filename;
|
||||||
|
@ -145,5 +145,19 @@ TEST_CASE("file_helper_split_by_extenstion7", "[file_helper::split_by_extenstion
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
TEST_CASE("file_helper_split_by_extenstion8", "[file_helper::split_by_extenstion(hidden_file)]]")
|
||||||
|
{
|
||||||
|
#ifdef _WIN32
|
||||||
|
auto filename = "folder.ext\\mylog";
|
||||||
|
auto expected_basename = "folder.ext\\mylog";
|
||||||
|
#else
|
||||||
|
auto filename = "folder.ext/mylog";
|
||||||
|
auto expected_basename = "folder.ext/mylog";
|
||||||
|
#endif
|
||||||
|
std::string basename, ext;
|
||||||
|
std::tie(basename, ext) = file_helper::split_by_extenstion(filename);
|
||||||
|
REQUIRE(basename == expected_basename);
|
||||||
|
REQUIRE(ext == "");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user