summaryrefslogtreecommitdiff
path: root/library/MiscUtils.cpp
diff options
context:
space:
mode:
authorAlexander Gavrilov2012-05-19 19:50:36 +0400
committerAlexander Gavrilov2012-05-19 19:50:36 +0400
commit7774f5f2c1b1e16b9bd3eefe0fd8b4287d03fef7 (patch)
tree26456ee2d47d78dde660842a4f317804a790b925 /library/MiscUtils.cpp
parent4aa6dbdd005c8930f2ae972e780caa3fde97f854 (diff)
downloaddfhack-7774f5f2c1b1e16b9bd3eefe0fd8b4287d03fef7.tar.gz
dfhack-7774f5f2c1b1e16b9bd3eefe0fd8b4287d03fef7.tar.bz2
dfhack-7774f5f2c1b1e16b9bd3eefe0fd8b4287d03fef7.tar.xz
Add a mechanism converting ui focus to a string representation.
The idea is to make ui handling more modular, dispensing with huge functions that switch or if/else on lots of variables. For now, used to split up functions in the sort plugin.
Diffstat (limited to 'library/MiscUtils.cpp')
-rw-r--r--library/MiscUtils.cpp24
1 files changed, 24 insertions, 0 deletions
diff --git a/library/MiscUtils.cpp b/library/MiscUtils.cpp
index 8658788b..b73d730c 100644
--- a/library/MiscUtils.cpp
+++ b/library/MiscUtils.cpp
@@ -36,6 +36,7 @@ distribution.
#include <ctype.h>
#include <stdarg.h>
+#include <string.h>
#include <sstream>
#include <map>
@@ -124,6 +125,29 @@ std::string toLower(const std::string &str)
return rv;
}
+bool prefix_matches(const std::string &prefix, const std::string &key, std::string *tail)
+{
+ size_t ksize = key.size();
+ size_t psize = prefix.size();
+ if (ksize < psize || memcmp(prefix.data(), key.data(), psize) != 0)
+ return false;
+ if (tail)
+ tail->clear();
+ if (ksize == psize)
+ return true;
+ if (psize == 0 || prefix[psize-1] == '/')
+ {
+ if (tail) *tail = key.substr(psize);
+ return true;
+ }
+ if (key[psize] == '/')
+ {
+ if (tail) *tail = key.substr(psize+1);
+ return true;
+ }
+ return false;
+}
+
#ifdef LINUX_BUILD // Linux
uint64_t GetTimeMs64()
{