//----------------------------------------------------------------- //----------------------------------------------------------------- ParamDictionary FromXml(const XML::Node* in_element) { ParamDictionary result; for(auto param = Core::XMLUtils::GetFirstChildElement(in_element); param != nullptr; param = Core::XMLUtils::GetNextSiblingElement(param)) { std::string key; std::string value; for(auto attrib = Core::XMLUtils::GetFirstAttribute(param); attrib != nullptr; attrib = Core::XMLUtils::GetNextAttribute(attrib)) { if (XMLUtils::GetName(attrib) == "key") { key = Core::XMLUtils::GetValue(attrib); } else if (XMLUtils::GetName(attrib) == "value") { value = attrib->value(); } } if(key.length() > 0 && value.length() > 0) { result.SetValue(key, value); } } return result; }
//----------------------------------------------------------------- //----------------------------------------------------------------- ParamDictionary FromString(const std::string& in_string) { ParamDictionary result; u32 start = 0; std::string key; std::string value; for(u32 i=0; i<in_string.size(); ++i) { const char c = in_string[i]; // Any of these characters if(c == '\t' || c == '\n' || c == '\r' || c == '=' || c == ';'|| (c == ' ' && key.empty())) { if(start == i) { start = i + 1; continue; } if(key.empty()) { key.assign(in_string.begin() + start, in_string.begin()+i); while(in_string[start] != '=' && start < in_string.size()) start++; i = start - 1; } else if(value.empty()) { while(in_string[start] == ' ' && start < in_string.size()) start++; value.assign(in_string.begin() + start, in_string.begin()+i); result.SetValue(key, value); key.clear(); value.clear(); } start = i + 1; continue; } } return result; }