Line data Source code
1 : /*! 2 : * \file esys/repo/manifest/format_manifest.cpp 3 : * \brief 4 : * 5 : * \cond 6 : * __legal_b__ 7 : * 8 : * Copyright (c) 2021 Michel Gillet 9 : * Distributed under the MIT License. 10 : * (See accompanying file LICENSE.txt or 11 : * copy at https://opensource.org/licenses/MIT) 12 : * 13 : * __legal_e__ 14 : * \endcond 15 : * 16 : */ 17 : 18 : #include "esys/repo/esysrepo_prec.h" 19 : #include "esys/repo/manifest/format.h" 20 : 21 : namespace esys::repo::manifest 22 : { 23 : 24 22 : Result convert(Format format, std::string &text) 25 : { 26 22 : switch (format) 27 : { 28 22 : case Format::XML: text = "xml"; break; 29 0 : case Format::JSON: text = "json"; break; 30 0 : default: return ESYSREPO_RESULT(ResultCode::MANIFEST_FORMAT_UNKNOWN); 31 : } 32 22 : return ESYSREPO_RESULT(ResultCode::OK); 33 : } 34 : 35 37 : Result convert(const std::string &text, Format &format) 36 : { 37 37 : if (text == "xml") 38 37 : format = Format::XML; 39 0 : else if (text == "json") 40 0 : format = Format::JSON; 41 : else 42 : { 43 0 : format = Format::UNKNOWN; 44 0 : return ESYSREPO_RESULT(ResultCode::MANIFEST_FORMAT_UNKNOWN); 45 : } 46 37 : return ESYSREPO_RESULT(ResultCode::OK); 47 : } 48 : 49 0 : ESYSREPO_API std::string convert(Format format) 50 : { 51 0 : std::string text; 52 0 : auto result = convert(format, text); 53 0 : if (result.error()) return ""; 54 0 : return text; 55 0 : } 56 : 57 0 : ESYSREPO_API Format convert(const std::string &text) 58 : { 59 0 : Format format; 60 0 : Result result = convert(text, format); 61 0 : if (result.error()) return Format::NOT_SET; 62 0 : return format; 63 0 : } 64 : 65 : } // namespace esys::repo::manifest