Changeset View
Changeset View
Standalone View
Standalone View
source/tools/atlas/AtlasObject/AtlasObjectText.cpp
Show All 13 Lines | |||||
* You should have received a copy of the GNU General Public License | * You should have received a copy of the GNU General Public License | ||||
* along with 0 A.D. If not, see <http://www.gnu.org/licenses/>. | * along with 0 A.D. If not, see <http://www.gnu.org/licenses/>. | ||||
*/ | */ | ||||
#include "AtlasObjectText.h" | #include "AtlasObjectText.h" | ||||
#include "AtlasObjectImpl.h" | #include "AtlasObjectImpl.h" | ||||
#include "AtlasObject.h" | #include "AtlasObject.h" | ||||
static std::wstring ConvertRecursive(const AtNode::Ptr obj, bool use_brackets = true) | static std::string ConvertRecursive(const AtNode::Ptr obj, bool use_brackets = true) | ||||
{ | { | ||||
// Convert (1, ()) into "1" | // Convert (1, ()) into "1" | ||||
// Convert (3, (d: (...), e: (...))) into "3 (conv(...), conv(...))" | // Convert (3, (d: (...), e: (...))) into "3 (conv(...), conv(...))" | ||||
// etc | // etc | ||||
// resulting in data-loss [because of the key names], and a rather arbitrary | // resulting in data-loss [because of the key names], and a rather arbitrary | ||||
// [alphabetical by key] ordering of children, but at least it's fairly readable | // [alphabetical by key] ordering of children, but at least it's fairly readable | ||||
if (! obj) | if (! obj) | ||||
Stan: if (!obj) | |||||
return L""; | return ""; | ||||
std::wstring result; | std::string result; | ||||
bool has_value = !obj->m_Value.empty(); | bool has_value = !obj->m_Value.empty(); | ||||
bool has_children = !obj->m_Children.empty(); | bool has_children = !obj->m_Children.empty(); | ||||
if (has_value && has_children) | if (has_value && has_children) | ||||
result = obj->m_Value + L" "; | result = obj->m_Value + " "; | ||||
else if (has_value) | else if (has_value) | ||||
result = obj->m_Value; | result = obj->m_Value; | ||||
// else no value; result = L"" | // else no value; result = "" | ||||
if (has_children) | if (has_children) | ||||
{ | { | ||||
if (use_brackets) | if (use_brackets) | ||||
result += L"("; | result += "("; | ||||
bool first_child = true; // so we can add ", " in appropriate places | bool first_child = true; // so we can add ", " in appropriate places | ||||
for (const AtNode::child_maptype::value_type& child : obj->m_Children) | for (const AtNode::child_maptype::value_type& child : obj->m_Children) | ||||
{ | { | ||||
if (!first_child) | if (!first_child) | ||||
Not Done Inline ActionsMaybe so we don't assign first_child to false at every iteration for (const AtNode::child_maptype::value_type& child : obj->m_Children) { if (!first_child) { result += ", "; first_child = false; } result += ConvertRecursive(child.second); } Stan: Maybe so we don't assign first_child to false at every iteration
```lang=cpp
for (const… | |||||
Not Done Inline ActionsStan, I'm going to let you think that through and realise why that wouldn't work. ? s0600204: Stan, I'm going to let you think that through and realise why that wouldn't work. ? | |||||
Not Done Inline Actionshaha ^^ Stan: haha ^^ | |||||
result += L", "; | result += ", "; | ||||
else | else | ||||
first_child = false; | first_child = false; | ||||
result += ConvertRecursive(child.second); | result += ConvertRecursive(child.second); | ||||
} | } | ||||
if (use_brackets) | if (use_brackets) | ||||
result += L")"; | result += ")"; | ||||
} | } | ||||
return result; | return result; | ||||
} | } | ||||
std::wstring AtlasObject::ConvertToString(const AtObj& obj) | std::string AtlasObject::ConvertToString(const AtObj& obj) | ||||
{ | { | ||||
return ConvertRecursive(obj.m_Node, false); | return ConvertRecursive(obj.m_Node, false); | ||||
} | } |
Wildfire Games · Phabricator
if (!obj)