diff --git a/indra/llui/lltrans.cpp b/indra/llui/lltrans.cpp index a1a8feedaa937608dcb95bf3448f4cf98c320735..ee3ada2cfec598c7c7897920af64a7534bf1ee42 100644 --- a/indra/llui/lltrans.cpp +++ b/indra/llui/lltrans.cpp @@ -35,6 +35,9 @@ #include <map> +#include <absl/strings/str_format.h> +#include <absl/strings/str_cat.h> + LLTrans::template_map_t LLTrans::sStringTemplates; LLTrans::template_map_t LLTrans::sDefaultStringTemplates; LLStringUtil::format_map_t LLTrans::sDefaultArgs; @@ -143,7 +146,7 @@ bool LLTrans::parseLanguageStrings(LLXMLNodePtr &root) static LLTrace::BlockTimerStatHandle FTM_GET_TRANS("Translate string"); //static -std::string LLTrans::getString(const std::string &xml_desc, const LLStringUtil::format_map_t& msg_args, bool def_string) +std::string LLTrans::getString(std::string_view xml_desc, const LLStringUtil::format_map_t& msg_args, bool def_string) { // Don't care about time as much as call count. Make sure we're not // calling LLTrans::getString() in an inner loop. JC @@ -167,12 +170,12 @@ std::string LLTrans::getString(const std::string &xml_desc, const LLStringUtil:: else { LL_WARNS_ONCE("configuration") << "Missing String in strings.xml: [" << xml_desc << "]" << LL_ENDL; - return "MissingString("+xml_desc+")"; + return absl::StrCat("MissingString(", xml_desc, ")"); } } //static -std::string LLTrans::getDefString(const std::string &xml_desc, const LLStringUtil::format_map_t& msg_args) +std::string LLTrans::getDefString(std::string_view xml_desc, const LLStringUtil::format_map_t& msg_args) { template_map_t::iterator iter = sDefaultStringTemplates.find(xml_desc); if (iter != sDefaultStringTemplates.end()) @@ -187,12 +190,12 @@ std::string LLTrans::getDefString(const std::string &xml_desc, const LLStringUti else { LL_WARNS_ONCE("configuration") << "Missing String in strings.xml: [" << xml_desc << "]" << LL_ENDL; - return "MissingString(" + xml_desc + ")"; + return absl::StrCat("MissingString(", xml_desc, ")"); } } //static -std::string LLTrans::getString(const std::string &xml_desc, const LLSD& msg_args, bool def_string) +std::string LLTrans::getString(std::string_view xml_desc, const LLSD& msg_args, bool def_string) { // Don't care about time as much as call count. Make sure we're not // calling LLTrans::getString() in an inner loop. JC @@ -213,12 +216,12 @@ std::string LLTrans::getString(const std::string &xml_desc, const LLSD& msg_args else { LL_WARNS_ONCE("configuration") << "Missing String in strings.xml: [" << xml_desc << "]" << LL_ENDL; - return "MissingString("+xml_desc+")"; + return absl::StrCat("MissingString(", xml_desc, ")"); } } //static -std::string LLTrans::getDefString(const std::string &xml_desc, const LLSD& msg_args) +std::string LLTrans::getDefString(std::string_view xml_desc, const LLSD& msg_args) { template_map_t::iterator iter = sDefaultStringTemplates.find(xml_desc); if (iter != sDefaultStringTemplates.end()) @@ -230,12 +233,12 @@ std::string LLTrans::getDefString(const std::string &xml_desc, const LLSD& msg_a else { LL_WARNS_ONCE("configuration") << "Missing String in strings.xml: [" << xml_desc << "]" << LL_ENDL; - return "MissingString(" + xml_desc + ")"; + return absl::StrCat("MissingString(", xml_desc, ")"); } } //static -bool LLTrans::findString(std::string &result, const std::string &xml_desc, const LLStringUtil::format_map_t& msg_args) +bool LLTrans::findString(std::string &result, std::string_view xml_desc, const LLStringUtil::format_map_t& msg_args) { LL_RECORD_BLOCK_TIME(FTM_GET_TRANS); @@ -257,7 +260,7 @@ bool LLTrans::findString(std::string &result, const std::string &xml_desc, const } //static -bool LLTrans::findString(std::string &result, const std::string &xml_desc, const LLSD& msg_args) +bool LLTrans::findString(std::string &result, std::string_view xml_desc, const LLSD& msg_args) { LL_RECORD_BLOCK_TIME(FTM_GET_TRANS); @@ -277,7 +280,7 @@ bool LLTrans::findString(std::string &result, const std::string &xml_desc, const } //static -std::string LLTrans::getCountString(const std::string& language, const std::string& xml_desc, S32 count) +std::string LLTrans::getCountString(const std::string_view language, const std::string_view xml_desc, S32 count) { // Compute which string identifier to use const char* form = ""; @@ -334,14 +337,14 @@ std::string LLTrans::getCountString(const std::string& language, const std::stri // Translate that string LLStringUtil::format_map_t args; - args["[COUNT]"] = llformat("%d", count); + args["[COUNT]"] = std::to_string(count); // Look up "AgeYearsB" or "AgeWeeksC" including the "form" - std::string key = llformat("%s%s", xml_desc.c_str(), form); + std::string key = absl::StrCat(xml_desc, form); return getString(key, args); } -void LLTrans::setDefaultArg(const std::string& name, const std::string& value) +void LLTrans::setDefaultArg(const std::string& name, const std::string value) { - sDefaultArgs[name] = value; + sDefaultArgs[name] = std::move(value); } diff --git a/indra/llui/lltrans.h b/indra/llui/lltrans.h index 9bd751fc78aeb0fffcc57c6c9425a46cdb06a958..10bafdfbc116db19baa9ea3f470ab315c801e399 100644 --- a/indra/llui/lltrans.h +++ b/indra/llui/lltrans.h @@ -43,7 +43,7 @@ class LLSD; class LLTransTemplate { public: - LLTransTemplate(const std::string& name = LLStringUtil::null, const std::string& text = LLStringUtil::null) : mName(name), mText(text) {} + LLTransTemplate(const std::string name = std::string(), const std::string text = std::string()) : mName(std::move(name)), mText(std::move(text)) {} std::string mName; std::string mText; @@ -76,41 +76,40 @@ class LLTrans * @param args A list of substrings to replace in the string * @returns Translated string */ - static std::string getString(const std::string &xml_desc, const LLStringUtil::format_map_t& args, bool def_string = false); - static std::string getDefString(const std::string &xml_desc, const LLStringUtil::format_map_t& args); - static std::string getString(const std::string &xml_desc, const LLSD& args, bool def_string = false); - static std::string getDefString(const std::string &xml_desc, const LLSD& args); - static bool findString(std::string &result, const std::string &xml_desc, const LLStringUtil::format_map_t& args); - static bool findString(std::string &result, const std::string &xml_desc, const LLSD& args); + static std::string getString(std::string_view xml_desc, const LLStringUtil::format_map_t& args, bool def_string = false); + static std::string getDefString(std::string_view xml_desc, const LLStringUtil::format_map_t& args); + static std::string getString(std::string_view xml_desc, const LLSD& args, bool def_string = false); + static std::string getDefString(std::string_view xml_desc, const LLSD& args); + static bool findString(std::string &result, std::string_view xml_desc, const LLStringUtil::format_map_t& args); + static bool findString(std::string &result, std::string_view xml_desc, const LLSD& args); // Returns translated string with [COUNT] replaced with a number, following // special per-language logic for plural nouns. For example, some languages // may have different plurals for 0, 1, 2 and > 2. // See "AgeWeeksA", "AgeWeeksB", etc. in strings.xml for examples. - static std::string getCountString(const std::string& language, const std::string& xml_desc, S32 count); + static std::string getCountString(const std::string_view language, const std::string_view xml_desc, S32 count); /** * @brief Returns a translated string * @param xml_desc String's description * @returns Translated string */ - static std::string getString(const std::string &xml_desc, bool def_string = false) + static std::string getString(std::string_view xml_desc, bool def_string = false) { LLStringUtil::format_map_t empty; return getString(xml_desc, empty); } - static bool findString(std::string &result, const std::string &xml_desc) + static bool findString(std::string &result, std::string_view xml_desc) { LLStringUtil::format_map_t empty; return findString(result, xml_desc, empty); } - static std::string getKeyboardString(const char* keystring) + static std::string getKeyboardString(const std::string_view keystring) { - std::string key_str(keystring); std::string trans_str; - return findString(trans_str, key_str) ? trans_str : key_str; + return findString(trans_str, keystring) ? trans_str : std::string(keystring); } // get the default args @@ -119,7 +118,7 @@ class LLTrans return sDefaultArgs; } - static void setDefaultArg(const std::string& name, const std::string& value); + static void setDefaultArg(const std::string& name, const std::string value); // insert default args into an arg list static void getArgs(LLStringUtil::format_map_t& args) @@ -128,7 +127,7 @@ class LLTrans } private: - typedef std::map<std::string, LLTransTemplate > template_map_t; + typedef std::map<std::string, LLTransTemplate, std::less<>> template_map_t; static template_map_t sStringTemplates; static template_map_t sDefaultStringTemplates; static LLStringUtil::format_map_t sDefaultArgs; diff --git a/indra/llwindow/llkeyboard.h b/indra/llwindow/llkeyboard.h index 9e5f980e5c248e3b572ac13a6313b7ea54e1afd2..fa866ed9342d91dcb16f8e93e9e722158c7360b0 100644 --- a/indra/llwindow/llkeyboard.h +++ b/indra/llwindow/llkeyboard.h @@ -42,7 +42,7 @@ enum EKeystate }; typedef boost::function<void(EKeystate keystate)> LLKeyFunc; -typedef std::string (LLKeyStringTranslatorFunc)(const char *label); +typedef std::string (LLKeyStringTranslatorFunc)(std::string_view label); enum EKeyboardInsertMode {