summaryrefslogtreecommitdiff
path: root/src/util/string.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/util/string.h')
-rw-r--r--src/util/string.h38
1 files changed, 37 insertions, 1 deletions
diff --git a/src/util/string.h b/src/util/string.h
index 572c37150..cc278da13 100644
--- a/src/util/string.h
+++ b/src/util/string.h
@@ -232,7 +232,7 @@ inline std::vector<std::basic_string<T> > str_split(
*/
inline std::string lowercase(const std::string &str)
{
- std::string s2;
+ std::string s2 = "";
s2.reserve(str.size());
@@ -423,6 +423,18 @@ inline void str_replace(std::string &str, const std::string &pattern,
}
/**
+ * Escapes characters [ ] \ , ; that can not be used in formspecs
+ */
+inline void str_formspec_escape(std::string &str)
+{
+ str_replace(str, "\\", "\\\\");
+ str_replace(str, "]", "\\]");
+ str_replace(str, "[", "\\[");
+ str_replace(str, ";", "\\;");
+ str_replace(str, ",", "\\,");
+}
+
+/**
* Replace all occurrences of the character \p from in \p str with \p to.
*
* @param str The string to (potentially) modify.
@@ -614,4 +626,28 @@ inline const char *bool_to_cstr(bool val)
return val ? "true" : "false";
}
+inline const std::string duration_to_string(int sec)
+{
+ int min = sec / 60;
+ sec %= 60;
+ int hour = min / 60;
+ min %= 60;
+
+ std::stringstream ss;
+ if (hour > 0) {
+ ss << hour << "h ";
+ }
+
+ if (min > 0) {
+ ss << min << "m ";
+ }
+
+ if (sec > 0) {
+ ss << sec << "s ";
+ }
+
+ return ss.str();
+}
+
+
#endif