gui: support string resources
storing strings in a map (for fast lookup) in resource manager To define a string resource in <resources>: <string name="foo">Hello</string> To use a string, e.g.: <text>%@foo%</text> Not yet done: language-specific resources (should be solved not only for strings, but for all kinds of resources - e.g. for localized images) Change-Id: I3ba5cf5298c09e0d28a83973e9662f179271b33f
This commit is contained in:
+12
-10
@@ -729,35 +729,37 @@ int gui_changePackage(std::string newPackage)
|
||||
return 0;
|
||||
}
|
||||
|
||||
std::string gui_parse_text(string inText)
|
||||
std::string gui_parse_text(std::string str)
|
||||
{
|
||||
// Copied from std::string GUIText::parseText(void)
|
||||
// This function parses text for DataManager values encompassed by %value% in the XML
|
||||
static int counter = 0;
|
||||
std::string str = inText;
|
||||
// and string resources (%@resource_name%)
|
||||
size_t pos = 0;
|
||||
size_t next = 0, end = 0;
|
||||
|
||||
while (1)
|
||||
{
|
||||
next = str.find('%', pos);
|
||||
size_t next = str.find('%', pos);
|
||||
if (next == std::string::npos)
|
||||
return str;
|
||||
|
||||
end = str.find('%', next + 1);
|
||||
size_t end = str.find('%', next + 1);
|
||||
if (end == std::string::npos)
|
||||
return str;
|
||||
|
||||
// We have a block of data
|
||||
std::string var = str.substr(next + 1,(end - next) - 1);
|
||||
str.erase(next,(end - next) + 1);
|
||||
std::string var = str.substr(next + 1, (end - next) - 1);
|
||||
str.erase(next, (end - next) + 1);
|
||||
|
||||
if (next + 1 == end)
|
||||
str.insert(next, 1, '%');
|
||||
else
|
||||
{
|
||||
std::string value;
|
||||
if (DataManager::GetValue(var, value) == 0)
|
||||
if (var.size() > 0 && var[0] == '@') {
|
||||
// this is a string resource ("%@string_name%")
|
||||
value = PageManager::GetResources()->FindString(var.substr(1));
|
||||
str.insert(next, value);
|
||||
}
|
||||
else if (DataManager::GetValue(var, value) == 0)
|
||||
str.insert(next, value);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user