diff --git a/src/directives.cpp b/src/directives.cpp index 8653ccf..f6e9587 100644 --- a/src/directives.cpp +++ b/src/directives.cpp @@ -3,19 +3,15 @@ namespace YAML { Directives::Directives() : version{true, 1, 2}, tags{} {} -std::string Directives::TranslateTagHandle( +const std::string Directives::TranslateTagHandle( const std::string& handle) const { - std::string result; auto it = tags.find(handle); if (it == tags.end()) { if (handle == "!!") - result = "tag:yaml.org,2002:"; - else - result = handle; - } else { - result = it->second; + return "tag:yaml.org,2002:"; + return handle; } - return result; + return it->second; } } // namespace YAML diff --git a/src/tag.cpp b/src/tag.cpp index 0a8168e..df8a2cf 100644 --- a/src/tag.cpp +++ b/src/tag.cpp @@ -29,31 +29,22 @@ Tag::Tag(const Token& token) } } -std::string Tag::Translate(const Directives& directives) { - std::string result; - +const std::string Tag::Translate(const Directives& directives) { switch (type) { case VERBATIM: - result = value; - break; + return value; case PRIMARY_HANDLE: - result = directives.TranslateTagHandle("!") + value; - break; + return directives.TranslateTagHandle("!") + value; case SECONDARY_HANDLE: - result = directives.TranslateTagHandle("!!") + value; - break; + return directives.TranslateTagHandle("!!") + value; case NAMED_HANDLE: - result = directives.TranslateTagHandle("!" + handle + "!") + value; - break; + return directives.TranslateTagHandle("!" + handle + "!") + value; case NON_SPECIFIC: // TODO: - result = "!"; - break; + return "!"; default: assert(false); - throw std::runtime_error("yaml-cpp: internal error, bad tag type"); } - - return result; + throw std::runtime_error("yaml-cpp: internal error, bad tag type"); } } // namespace YAML