#include "mapsector.h"
#include "settings.h"
#include "log.h"
+#include "utility_string.h"
/*
Asserts that the exception occurs
assert(is_yes("YeS") == true);
assert(is_yes("") == false);
assert(is_yes("FAlse") == false);
+ const char *ends[] = {"abc", "c", "bc", NULL};
+ assert(removeStringEnd("abc", ends) == "");
+ assert(removeStringEnd("bc", ends) == "b");
+ assert(removeStringEnd("12c", ends) == "12");
+ assert(removeStringEnd("foo", ends) == "");
}
};
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