diff options
author | kwolekr <kwolekr@minetest.net> | 2014-02-08 17:50:26 -0500 |
---|---|---|
committer | kwolekr <kwolekr@minetest.net> | 2014-02-08 17:50:59 -0500 |
commit | 83bafbe08b508266d31a6a76f1ffc2cddc662390 (patch) | |
tree | 555f877e367a8e1a00200c3fe3fa889538169291 /src/util | |
parent | f4f98c9550325aa8178f99cd32ea8806669aa280 (diff) | |
download | minetest-83bafbe08b508266d31a6a76f1ffc2cddc662390.tar.gz minetest-83bafbe08b508266d31a6a76f1ffc2cddc662390.tar.bz2 minetest-83bafbe08b508266d31a6a76f1ffc2cddc662390.zip |
Make flag strings clear specified flag with 'no' prefix
Remove flagmask field from set_mapgen_params table
Add small bits of needed documentation
Diffstat (limited to 'src/util')
-rw-r--r-- | src/util/string.cpp | 46 | ||||
-rw-r--r-- | src/util/string.h | 4 |
2 files changed, 34 insertions, 16 deletions
diff --git a/src/util/string.cpp b/src/util/string.cpp index 925d0ea35..afe40610c 100644 --- a/src/util/string.cpp +++ b/src/util/string.cpp @@ -108,46 +108,63 @@ std::string urldecode(std::string str) return oss.str(); } -u32 readFlagString(std::string str, FlagDesc *flagdesc) { - u32 result = 0; +u32 readFlagString(std::string str, FlagDesc *flagdesc, u32 *flagmask) +{ + u32 result = 0, mask = 0; char *s = &str[0]; char *flagstr, *strpos = NULL; - + while ((flagstr = strtok_r(s, ",", &strpos))) { s = NULL; - + while (*flagstr == ' ' || *flagstr == '\t') flagstr++; - + + bool flagset = true; + if (!strncasecmp(flagstr, "no", 2)) { + flagset = false; + flagstr += 2; + } + for (int i = 0; flagdesc[i].name; i++) { if (!strcasecmp(flagstr, flagdesc[i].name)) { - result |= flagdesc[i].flag; + mask |= flagdesc[i].flag; + if (flagset) + result |= flagdesc[i].flag; break; } } } - + + if (flagmask) + *flagmask = mask; + return result; } -std::string writeFlagString(u32 flags, FlagDesc *flagdesc) { +std::string writeFlagString(u32 flags, FlagDesc *flagdesc, u32 flagmask) +{ std::string result; - + for (int i = 0; flagdesc[i].name; i++) { - if (flags & flagdesc[i].flag) { + if (flagmask & flagdesc[i].flag) { + if (!(flags & flagdesc[i].flag)) + result += "no"; + result += flagdesc[i].name; result += ", "; } } - + size_t len = result.length(); if (len >= 2) result.erase(len - 2, 2); - + return result; } -char *mystrtok_r(char *s, const char *sep, char **lasts) { +char *mystrtok_r(char *s, const char *sep, char **lasts) +{ char *t; if (!s) @@ -172,7 +189,8 @@ char *mystrtok_r(char *s, const char *sep, char **lasts) { return s; } -u64 read_seed(const char *str) { +u64 read_seed(const char *str) +{ char *endptr; u64 num; diff --git a/src/util/string.h b/src/util/string.h index e5a60bc47..d6a9926ab 100644 --- a/src/util/string.h +++ b/src/util/string.h @@ -319,8 +319,8 @@ inline std::string unescape_string(std::string &s) std::string translatePassword(std::string playername, std::wstring password); std::string urlencode(std::string str); std::string urldecode(std::string str); -u32 readFlagString(std::string str, FlagDesc *flagdesc); -std::string writeFlagString(u32 flags, FlagDesc *flagdesc); +u32 readFlagString(std::string str, FlagDesc *flagdesc, u32 *flagmask); +std::string writeFlagString(u32 flags, FlagDesc *flagdesc, u32 flagmask); char *mystrtok_r(char *s, const char *sep, char **lasts); u64 read_seed(const char *str); |