summaryrefslogtreecommitdiff
path: root/library/MiscUtils.cpp
diff options
context:
space:
mode:
authorAlexander Gavrilov2012-01-08 20:02:12 +0400
committerAlexander Gavrilov2012-01-08 20:02:12 +0400
commitea790f1346a3dff8df6331dc84a16a7915bca4fd (patch)
tree6b31f4f4df7061c75af9a2d7610d10105841382a /library/MiscUtils.cpp
parent64a9a49ec0393a903403b728fe41758ab774ebf8 (diff)
downloaddfhack-ea790f1346a3dff8df6331dc84a16a7915bca4fd.tar.gz
dfhack-ea790f1346a3dff8df6331dc84a16a7915bca4fd.tar.bz2
dfhack-ea790f1346a3dff8df6331dc84a16a7915bca4fd.tar.xz
Move a few functions into the core, and add some more.
Diffstat (limited to 'library/MiscUtils.cpp')
-rw-r--r--library/MiscUtils.cpp40
1 files changed, 40 insertions, 0 deletions
diff --git a/library/MiscUtils.cpp b/library/MiscUtils.cpp
index 72e3eae2..aa141313 100644
--- a/library/MiscUtils.cpp
+++ b/library/MiscUtils.cpp
@@ -34,6 +34,7 @@ distribution.
#include <ctime>
#endif
+#include <ctype.h>
#include <stdarg.h>
std::string stl_sprintf(const char *fmt, ...) {
@@ -59,6 +60,45 @@ std::string stl_vsprintf(const char *fmt, va_list args) {
}
}
+bool split_string(std::vector<std::string> *out,
+ const std::string &str, const std::string &separator, bool squash_empty)
+{
+ out->clear();
+
+ size_t start = 0, pos;
+
+ if (!separator.empty())
+ {
+ while ((pos = str.find(separator,start)) != std::string::npos)
+ {
+ if (pos > start || !squash_empty)
+ out->push_back(str.substr(start, pos-start));
+ start = pos + separator.size();
+ }
+ }
+
+ if (start < str.size() || !squash_empty)
+ out->push_back(str.substr(start));
+
+ return out->size() > 1;
+}
+
+std::string toUpper(const std::string &str)
+{
+ std::string rv(str.size(),' ');
+ for (unsigned i = 0; i < str.size(); ++i)
+ rv[i] = toupper(str[i]);
+ return rv;
+}
+
+std::string toLower(const std::string &str)
+{
+ std::string rv(str.size(),' ');
+ for (unsigned i = 0; i < str.size(); ++i)
+ rv[i] = tolower(str[i]);
+ return rv;
+}
+
#ifdef LINUX_BUILD // Linux
uint64_t GetTimeMs64()
{