diff options
author | Perttu Ahola <celeron55@gmail.com> | 2012-03-25 12:48:14 +0300 |
---|---|---|
committer | Perttu Ahola <celeron55@gmail.com> | 2012-03-25 14:48:14 +0300 |
commit | e71262463f8fd2d9509b5646b4e08cfa09fc2889 (patch) | |
tree | 2902af0582c2d5a4e9815605fe7ec6ccf117e191 /src/utility_string.h | |
parent | 26666bb36f594bbca8aa71654c009bbceb1e5eb8 (diff) | |
download | minetest-e71262463f8fd2d9509b5646b4e08cfa09fc2889.tar.gz minetest-e71262463f8fd2d9509b5646b4e08cfa09fc2889.tar.bz2 minetest-e71262463f8fd2d9509b5646b4e08cfa09fc2889.zip |
Add removeStringEnd()
Diffstat (limited to 'src/utility_string.h')
-rw-r--r-- | src/utility_string.h | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/src/utility_string.h b/src/utility_string.h index f29057ad7..df283ba69 100644 --- a/src/utility_string.h +++ b/src/utility_string.h @@ -31,5 +31,20 @@ static inline std::string padStringRight(std::string s, size_t len) return s; } +// ends: NULL- or ""-terminated array of strings +// Returns "" if no end could be removed. +static inline std::string removeStringEnd(const std::string &s, const char *ends[]) +{ + const char **p = ends; + for(; (*p) && (*p)[0] != '\0'; p++){ + std::string end = *p; + if(s.size() < end.size()) + continue; + if(s.substr(s.size()-end.size(), end.size()) == end) + return s.substr(0, s.size() - end.size()); + } + return ""; +} + #endif |