Created
February 11, 2020 23:29
-
-
Save bit-hack/4e47029adffeeba112d61466cb0af353 to your computer and use it in GitHub Desktop.
return the base of a given file path.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
std::string base_path(std::string in) { | |
const size_t last1 = in.rfind('/'); | |
const size_t last2 = in.rfind('\\'); | |
const size_t last = std::max(last1 == std::string::npos ? 0 : last1, | |
last2 == std::string::npos ? 0 : last2); | |
in.resize(last); | |
return in; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment