1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-07-22 17:18:39 +00:00

Add removeStringEnd()

This commit is contained in:
Perttu Ahola 2012-03-25 12:48:14 +03:00
parent 26666bb36f
commit e71262463f
2 changed files with 21 additions and 0 deletions

View file

@ -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