Skip to content

Commit

Permalink
Added support of Windows platform to parsing file extension.
Browse files Browse the repository at this point in the history
  • Loading branch information
marek-trtik committed Oct 3, 2017
1 parent 821ba1c commit d4a04ac
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/util/file_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,18 @@ std::string fileutl_parse_name_in_pathname(std::string const &file_pathname)
std::string fileutl_parse_extension_in_pathname(const std::string &pathname)
{
const std::size_t idx=pathname.find_last_of('.');
# if defined(WIN32)
const std::size_t fwd_slash_idx=pathname.find_last_of('/');
const std::size_t bwd_slash_idx=pathname.find_last_of('\\');
const std::size_t slash_idx=
fwd_slash_idx==std::string::npos ? bwd_slash_idx :
bwd_slash_idx==std::string::npos ? fwd_slash_idx :
std::max(fwd_slash_idx, bwd_slash_idx);
# elif defined(__linux__) || defined(__APPLE__)
const std::size_t slash_idx=pathname.find_last_of('/');
# else
# error "Unsuported platform."
# endif
return
idx==std::string::npos || (slash_idx!=std::string::npos && idx<slash_idx) ?
std::string() : pathname.substr(idx);
Expand Down

0 comments on commit d4a04ac

Please sign in to comment.