Skip to content

Commit d4a04ac

Browse files
committed
Added support of Windows platform to parsing file extension.
1 parent 821ba1c commit d4a04ac

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

src/util/file_util.cpp

+11
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,18 @@ std::string fileutl_parse_name_in_pathname(std::string const &file_pathname)
204204
std::string fileutl_parse_extension_in_pathname(const std::string &pathname)
205205
{
206206
const std::size_t idx=pathname.find_last_of('.');
207+
# if defined(WIN32)
208+
const std::size_t fwd_slash_idx=pathname.find_last_of('/');
209+
const std::size_t bwd_slash_idx=pathname.find_last_of('\\');
210+
const std::size_t slash_idx=
211+
fwd_slash_idx==std::string::npos ? bwd_slash_idx :
212+
bwd_slash_idx==std::string::npos ? fwd_slash_idx :
213+
std::max(fwd_slash_idx, bwd_slash_idx);
214+
# elif defined(__linux__) || defined(__APPLE__)
207215
const std::size_t slash_idx=pathname.find_last_of('/');
216+
# else
217+
# error "Unsuported platform."
218+
# endif
208219
return
209220
idx==std::string::npos || (slash_idx!=std::string::npos && idx<slash_idx) ?
210221
std::string() : pathname.substr(idx);

0 commit comments

Comments
 (0)