Line data Source code
1 : /*! 2 : * \file esys/repo/manifest/parsemode_manifest.cpp 3 : * \brief Manifest XML parse strictness (format-agnostic) 4 : * 5 : * \cond 6 : * __legal_b__ 7 : * 8 : * Copyright (c) 2026 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/parsemode.h" 20 : 21 : #include <algorithm> 22 : #include <cctype> 23 : 24 : namespace esys::repo::manifest 25 : { 26 : 27 : namespace 28 : { 29 : 30 41 : std::string to_lower(std::string text) 31 : { 32 41 : std::transform(text.begin(), text.end(), text.begin(), 33 328 : [](unsigned char c) { return static_cast<char>(std::tolower(c)); }); 34 41 : return text; 35 : } 36 : 37 : } // namespace 38 : 39 26 : Result convert(ParseMode mode, std::string &text) 40 : { 41 26 : switch (mode) 42 : { 43 2 : case ParseMode::Strict: text = "strict"; return ESYSREPO_RESULT(ResultCode::OK); 44 24 : case ParseMode::Tolerant: text = "tolerant"; return ESYSREPO_RESULT(ResultCode::OK); 45 0 : default: return ESYSREPO_RESULT(ResultCode::INTERNAL_ERROR); 46 : } 47 : } 48 : 49 41 : Result convert(const std::string &text, ParseMode &mode) 50 : { 51 41 : const std::string lower = to_lower(text); 52 41 : if (lower == "strict") 53 : { 54 1 : mode = ParseMode::Strict; 55 1 : return ESYSREPO_RESULT(ResultCode::OK); 56 : } 57 43 : if (lower == "tolerant" || lower == "lenient" || lower == "compat" || lower == "compatible" 58 40 : || lower == "ignore-unknown") 59 : { 60 40 : mode = ParseMode::Tolerant; 61 40 : return ESYSREPO_RESULT(ResultCode::OK); 62 : } 63 0 : return ESYSREPO_RESULT(ResultCode::INTERNAL_ERROR, text); 64 41 : } 65 : 66 : } // namespace esys::repo::manifest