aboutsummaryrefslogtreecommitdiff
path: root/src/util/string.h
diff options
context:
space:
mode:
authorEkdohibs <nathanael.courant@laposte.net>2017-01-31 18:05:03 +0100
committerEkdohibs <nathanael.courant@laposte.net>2017-08-24 17:54:10 +0200
commitb24e6433df3c3b2926568aff9c0173459e3e8eab (patch)
treeeec6a9f05e78e3de7b08c805685cd54dcc5e43de /src/util/string.h
parentb28af0ed0777f66122ecaf0d0e302fe24c88d552 (diff)
downloadminetest-b24e6433df3c3b2926568aff9c0173459e3e8eab.tar.gz
minetest-b24e6433df3c3b2926568aff9c0173459e3e8eab.tar.bz2
minetest-b24e6433df3c3b2926568aff9c0173459e3e8eab.zip
Add clientside translations.
Diffstat (limited to 'src/util/string.h')
-rw-r--r--src/util/string.h56
1 files changed, 56 insertions, 0 deletions
diff --git a/src/util/string.h b/src/util/string.h
index 122262af8..2840f1192 100644
--- a/src/util/string.h
+++ b/src/util/string.h
@@ -203,6 +203,56 @@ inline bool str_starts_with(const std::basic_string<T> &str,
case_insensitive);
}
+
+/**
+ * Check whether \p str ends with the string suffix. If \p case_insensitive
+ * is true then the check is case insensitve (default is false; i.e. case is
+ * significant).
+ *
+ * @param str
+ * @param suffix
+ * @param case_insensitive
+ * @return true if the str begins with suffix
+ */
+template <typename T>
+inline bool str_ends_with(const std::basic_string<T> &str,
+ const std::basic_string<T> &suffix,
+ bool case_insensitive = false)
+{
+ if (str.size() < suffix.size())
+ return false;
+
+ size_t start = str.size() - suffix.size();
+ if (!case_insensitive)
+ return str.compare(start, suffix.size(), suffix) == 0;
+
+ for (size_t i = 0; i < suffix.size(); ++i)
+ if (tolower(str[start + i]) != tolower(suffix[i]))
+ return false;
+ return true;
+}
+
+
+/**
+ * Check whether \p str ends with the string suffix. If \p case_insensitive
+ * is true then the check is case insensitve (default is false; i.e. case is
+ * significant).
+ *
+ * @param str
+ * @param suffix
+ * @param case_insensitive
+ * @return true if the str begins with suffix
+ */
+template <typename T>
+inline bool str_ends_with(const std::basic_string<T> &str,
+ const T *suffix,
+ bool case_insensitive = false)
+{
+ return str_ends_with(str, std::basic_string<T>(suffix),
+ case_insensitive);
+}
+
+
/**
* Splits a string into its component parts separated by the character
* \p delimiter.
@@ -598,6 +648,12 @@ std::vector<std::basic_string<T> > split(const std::basic_string<T> &s, T delim)
return tokens;
}
+std::wstring translate_string(const std::wstring &s);
+
+inline std::wstring unescape_translate(const std::wstring &s) {
+ return unescape_enriched(translate_string(s));
+}
+
/**
* Checks that all characters in \p to_check are a decimal digits.
*