From b24e6433df3c3b2926568aff9c0173459e3e8eab Mon Sep 17 00:00:00 2001 From: Ekdohibs Date: Tue, 31 Jan 2017 18:05:03 +0100 Subject: Add clientside translations. --- src/util/string.h | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) (limited to 'src/util/string.h') 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 &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 +inline bool str_ends_with(const std::basic_string &str, + const std::basic_string &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 +inline bool str_ends_with(const std::basic_string &str, + const T *suffix, + bool case_insensitive = false) +{ + return str_ends_with(str, std::basic_string(suffix), + case_insensitive); +} + + /** * Splits a string into its component parts separated by the character * \p delimiter. @@ -598,6 +648,12 @@ std::vector > split(const std::basic_string &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. * -- cgit v1.2.3