From 2eedbba8417d192d9b58a07910d81a7a17d5c272 Mon Sep 17 00:00:00 2001 From: Oliver Hamlet Date: Fri, 26 Jun 2015 13:28:51 +0100 Subject: [PATCH] Changes to pass File class tests. 1. A scalar value is also emitted if the display name is not different from the file name, and the value is single-quoted to match masterlist style. 2. Condition and display YAML keys are only created if data exists for those keys, to match the emitter behaviour. --- src/backend/metadata/file.cpp | 4 ++-- src/backend/metadata/file.h | 18 +++++++++++++----- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/src/backend/metadata/file.cpp b/src/backend/metadata/file.cpp index 41ab2b73..269ed4da 100644 --- a/src/backend/metadata/file.cpp +++ b/src/backend/metadata/file.cpp @@ -56,8 +56,8 @@ namespace loot { namespace YAML { Emitter& operator << (Emitter& out, const loot::File& rhs) { - if (!rhs.IsConditional() && rhs.DisplayName().empty()) - out << rhs.Name(); + if (!rhs.IsConditional() && (rhs.DisplayName().empty() || rhs.DisplayName() == rhs.Name())) + out << YAML::SingleQuoted << rhs.Name(); else { out << BeginMap << Key << "name" << Value << YAML::SingleQuoted << rhs.Name(); diff --git a/src/backend/metadata/file.h b/src/backend/metadata/file.h index 5496603b..cdd68c97 100644 --- a/src/backend/metadata/file.h +++ b/src/backend/metadata/file.h @@ -53,28 +53,36 @@ namespace YAML { struct convert < loot::File > { static Node encode(const loot::File& rhs) { Node node; - node["condition"] = rhs.Condition(); node["name"] = rhs.Name(); - node["display"] = rhs.DisplayName(); + + if (rhs.IsConditional()) + node["condition"] = rhs.Condition(); + + if (rhs.DisplayName() != rhs.Name()) + node["display"] = rhs.DisplayName(); + return node; } static bool decode(const Node& node, loot::File& rhs) { + if (!node.IsMap() && !node.IsScalar()) + return false; + if (node.IsMap()) { if (!node["name"]) return false; - std::string condition, name, display; + std::string name = node["name"].as(); + std::string condition, display; if (node["condition"]) condition = node["condition"].as(); - if (node["name"]) - name = node["name"].as(); if (node["display"]) display = node["display"].as(); rhs = loot::File(name, display, condition); } else rhs = loot::File(node.as()); + return true; } };