#pragma once // Distributed under the LGPL version 3.0 license. See accompanying // file LICENSE or https://github.com/henryiii/CLI11 for details. #include #include #include #include "CLI/StringTools.hpp" namespace CLI { namespace detail { /// Internal parsing function std::vector parse_ini(std::istream &input) { std::string line; std::string section = "default"; std::vector output; while(getline(input, line)) { detail::trim(line); size_t len = line.length(); if(len > 1 && line[0] == '[' && line[len-1] == ']') { section = line.substr(1,len-2); std::transform(std::begin(section), std::end(section), std::begin(section), ::tolower); } else if (len > 0) { if(section == "default") output.push_back("--" + line); else output.push_back("--" + section + "." + line); } } return output; } /// Parse an INI file, throw an error (ParseError:INIParseError or FileError) on failure std::vector parse_ini(const std::string &name) { std::ifstream input{name}; if(!input.good()) throw FileError(name); return parse_ini(input); } } }