File tree 1 file changed +8
-15
lines changed
1 file changed +8
-15
lines changed Original file line number Diff line number Diff line change @@ -37,31 +37,24 @@ IGL_INLINE std::string igl::dirname(const std::string & path)
37
37
{
38
38
return std::string (" " );
39
39
}
40
- #if defined (WIN32)
41
- char del (' \\ ' );
42
- #else
43
- char del (' /' );
44
- #endif
45
- // http://stackoverflow.com/questions/5077693/dirnamephp-similar-function-in-c
46
- std::string::const_reverse_iterator last_slash =
47
- std::find (
48
- path.rbegin (),
49
- path.rend (),del);
50
- if ( last_slash == path.rend () )
40
+ // https://stackoverflow.com/a/3071694/148668
41
+ size_t found = path.find_last_of (" /\\ " );
42
+ if (found == std::string::npos)
51
43
{
52
44
// No slashes found
53
45
return std::string (" ." );
54
- }else if (1 == (last_slash. base () - path. begin ()) )
46
+ }else if (found == 0 )
55
47
{
56
48
// Slash is first char
57
- return std::string (&del );
58
- }else if (path. end () == last_slash. base () )
49
+ return std::string (path. begin (),path. begin ()+ 1 );
50
+ }else if (found == path. length ()- 1 )
59
51
{
60
52
// Slash is last char
61
53
std::string redo = std::string (path.begin (),path.end ()-1 );
62
54
return igl::dirname (redo);
63
55
}
64
- return std::string (path.begin (),last_slash.base ()-1 );
56
+ // Return everything up to but not including last slash
57
+ return std::string (path.begin (),path.begin ()+found);
65
58
}
66
59
67
60
You can’t perform that action at this time.
0 commit comments