From ab7955d87427b93ca6f64a8127d854ed96dcc9b0 Mon Sep 17 00:00:00 2001 From: Ethan Yonker Date: Mon, 21 Dec 2015 10:17:34 -0600 Subject: Improve string resource lookup in twmsg Change-Id: Iaac7d3df0bd12a4d817d4ad273254662865b775a --- gui/twmsg.cpp | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/gui/twmsg.cpp b/gui/twmsg.cpp index 6c3bad4ae..9fe9e5a94 100644 --- a/gui/twmsg.cpp +++ b/gui/twmsg.cpp @@ -25,19 +25,7 @@ std::string Message::GetFormatString(const std::string& name) const { - std::string resname; - size_t pos = name.find('='); - if (pos == std::string::npos) - resname = name; - else - resname = name.substr(0, pos); - - std::string formatstr = resourceLookup(resname); - bool notfound = formatstr.empty() || formatstr.substr(0, 2) == "{@"; // HACK: TODO: integrate this with resource-not-found logic - if (notfound && pos != std::string::npos) - // resource not found - use the default format string specified after "=" - formatstr = name.substr(pos + 1); - return formatstr; + return resourceLookup(name); } // Look up in local replacement vars first, if not found then use outer lookup object @@ -91,9 +79,25 @@ class ResourceLookup : public StringLookup public: virtual std::string operator()(const std::string& name) const { + std::string resname; + std::string default_value; + + size_t pos = name.find('='); + if (pos == std::string::npos) { + resname = name; + } else { + resname = name.substr(0, pos); + default_value = name.substr(pos + 1); + } const ResourceManager* res = PageManager::GetResources(); - if (res) - return res->FindString(name); + if (res) { + if (default_value.empty()) + return res->FindString(resname); + else + return res->FindString(resname, default_value); + } else if (!default_value.empty()) { + return default_value; + } return name; } }; -- cgit v1.2.3