1#include <xrpl/basics/BasicConfig.h>
2#include <xrpl/basics/StringUtilities.h>
4#include <boost/regex/v5/regbase.hpp>
5#include <boost/regex/v5/regex.hpp>
6#include <boost/regex/v5/regex_fwd.hpp>
7#include <boost/regex/v5/regex_match.hpp>
31 static boost::regex
const re1(
34 "([a-zA-Z][_a-zA-Z0-9]*)"
41 boost::regex_constants::optimize);
44 for (
auto line :
lines)
46 auto remove_comment = [](
std::string& val) ->
bool {
47 bool removed_trailing =
false;
48 auto comment = val.
find(
'#');
49 while (comment != std::string::npos)
58 else if (val.at(comment - 1) ==
'\\')
62 val.erase(comment - 1, 1);
69 removed_trailing =
true;
73 comment = val.find(
'#', comment);
75 return removed_trailing;
78 if (remove_comment(line) && !line.empty())
85 if (boost::regex_match(line,
match, re1))
103 for (
auto const& [k, v] : section.
lookup_)
104 os << k <<
"=" << v <<
"\n";
113 return map_.contains(name);
119 return map_.emplace(name, name).first->second;
126 auto const iter =
map_.find(name);
127 if (iter ==
map_.end())
138 auto const result =
map_.emplace(
142 result.first->second.
set(key, value);
168 for (
auto const& entry : ifs)
170 auto const result =
map_.emplace(
174 result.first->second.append(entry.second);
181 for (
auto const& [k, v] : c.
map_)
182 ss <<
"[" << k <<
"]\n" << v;
Holds unparsed configuration information.
bool exists(std::string const &name) const
Returns true if a section with the given name exists.
void deprecatedClearSection(std::string const §ion)
Remove all the key/value pairs from the section.
Section & section(std::string const &name)
Returns the section with the given name.
void build(IniFileSections const &ifs)
std::unordered_map< std::string, Section > map_
void overwrite(std::string const §ion, std::string const &key, std::string const &value)
Overwrite a key/value pair with a command line argument If the section does not exist it is created.
void legacy(std::string const §ion, std::string value)
Set a value that is not a key/value pair.
Holds a collection of configuration values.
std::string const & name() const
Returns the name of this section.
void set(std::string const &key, std::string const &value)
Set a key/value pair.
std::vector< std::string > lines_
std::vector< std::string > const & lines() const
Returns all the lines in the section.
void legacy(std::string value)
Set the legacy value for this section.
bool exists(std::string const &name) const
Returns true if a key with the given name exists.
bool had_trailing_comments_
void append(std::vector< std::string > const &lines)
Append a set of lines to this section.
Section(std::string const &name="")
Create an empty section.
std::unordered_map< std::string, std::string > lookup_
std::vector< std::string > values_
T insert_or_assign(T... args)
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
std::string trim_whitespace(std::string str)
std::ostream & operator<<(std::ostream &out, base_uint< Bits, Tag > const &u)