1#include <xrpl/config/BasicConfig.h>
3#include <xrpl/basics/StringUtilities.h>
5#include <boost/regex/v5/regbase.hpp>
6#include <boost/regex/v5/regex.hpp>
7#include <boost/regex/v5/regex_match.hpp>
24 lookup_.insert_or_assign(key, value);
31 static boost::regex
const kRe1(
34 "([a-zA-Z][_a-zA-Z0-9]*)"
41 boost::regex_constants::optimize);
44 for (
auto line :
lines)
47 bool removedTrailing =
false;
48 auto comment = val.find(
'#');
49 while (comment != std::string::npos)
58 if (val.at(comment - 1) ==
'\\')
62 val.erase(comment - 1, 1);
69 removedTrailing =
true;
73 comment = val.find(
'#', comment);
75 return removedTrailing;
78 if (removeComment(line) && !line.empty())
85 if (boost::regex_match(line, match, kRe1))
87 set(match[1], match[2]);
94 lines_.push_back(std::move(line));
107 for (
auto const& [k, v] : section.
lookup_)
108 os << k <<
"=" << v <<
"\n";
117 return map_.contains(name);
123 return map_.emplace(name, name).first->second;
129 static Section const kNone(
"");
130 auto const iter =
map_.find(name);
131 if (iter ==
map_.end())
141 result.first->second.set(key, value);
167 for (
auto const& entry : ifs)
169 auto const result =
map_.emplace(
171 result.first->second.append(entry.second);
178 for (
auto const& [k, v] : c.
map_)
179 ss <<
"[" << k <<
"]\n" << v;
Holds unparsed configuration information.
void deprecatedClearSection(std::string const §ion)
Remove all the key/value pairs from the section.
void build(IniFileSections const &ifs)
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.
std::unordered_map< std::string, Section > map_
bool exists(std::string const &name) const
Returns true if a section with the given name exists.
void legacy(std::string const §ion, std::string value)
Set a value that is not a key/value pair.
Section & section(std::string const &name)
Returns the section with the given name.
Holds a collection of configuration values.
Section(std::string name="")
Create an empty section.
bool hadTrailingComments_
std::unordered_map< std::string, std::string > lookup_
std::string const & name() const
Returns the name of this section.
std::vector< std::string > values_
std::vector< std::string > const & lines() const
Returns all the lines in the section.
void set(std::string const &key, std::string const &value)
Set a key/value pair.
void legacy(std::string value)
Set the legacy value for this section.
std::vector< std::string > lines_
void append(std::vector< std::string > const &lines)
Append a set of lines to this section.
bool exists(std::string const &name) const
Returns true if a key with the given name exists.
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
std::ostream & operator<<(std::ostream &out, BaseUInt< Bits, Tag > const &u)
std::string trimWhitespace(std::string str)
std::unordered_map< std::string, std::vector< std::string > > IniFileSections