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 53 : std::string to_lower(std::string text) 31 : { 32 53 : std::transform(text.begin(), text.end(), text.begin(), 33 424 : [](unsigned char c) { return static_cast<char>(std::tolower(c)); }); 34 53 : return text; 35 : } 36 : 37 : } // namespace 38 : 39 30 : Result convert(ParseMode mode, std::string &text) 40 : { 41 30 : switch (mode) 42 : { 43 2 : case ParseMode::Strict: text = "strict"; return ESYSREPO_RESULT(ResultCode::OK); 44 28 : case ParseMode::Tolerant: text = "tolerant"; return ESYSREPO_RESULT(ResultCode::OK); 45 0 : default: return ESYSREPO_RESULT(ResultCode::INTERNAL_ERROR); 46 : } 47 : } 48 : 49 53 : Result convert(const std::string &text, ParseMode &mode) 50 : { 51 53 : const std::string lower = to_lower(text); 52 53 : if (lower == "strict") 53 : { 54 1 : mode = ParseMode::Strict; 55 1 : return ESYSREPO_RESULT(ResultCode::OK); 56 : } 57 55 : if (lower == "tolerant" || lower == "lenient" || lower == "compat" || lower == "compatible" 58 52 : || lower == "ignore-unknown") 59 : { 60 52 : mode = ParseMode::Tolerant; 61 52 : return ESYSREPO_RESULT(ResultCode::OK); 62 : } 63 0 : return ESYSREPO_RESULT(ResultCode::INTERNAL_ERROR, text); 64 53 : } 65 : 66 : } // namespace esys::repo::manifest