20 #include <ripple/basics/BasicConfig.h>
21 #include <ripple/basics/StringUtilities.h>
22 #include <boost/regex.hpp>
34 auto const result = cont().emplace(key, value);
36 result.first->second = value;
43 static boost::regex
const re1(
46 "([a-zA-Z][_a-zA-Z0-9]*)"
53 boost::regex_constants::optimize);
56 for (
auto line :
lines)
58 auto remove_comment = [](
std::string& val) ->
bool {
59 bool removed_trailing =
false;
60 auto comment = val.
find(
'#');
61 while (comment != std::string::npos)
70 else if (val.at(comment - 1) ==
'\\')
74 val.erase(comment - 1, 1);
81 removed_trailing =
true;
85 comment = val.find(
'#', comment);
87 return removed_trailing;
90 if (remove_comment(line) && !line.empty())
97 if (boost::regex_match(line, match, re1))
98 set(match[1], match[2]);
109 return cont().find(
name) != cont().end();
115 auto const iter = cont().find(
name);
116 if (iter == cont().end())
118 return {iter->second,
true};
124 for (
auto const& [k, v] : section.cont())
125 os << k <<
"=" << v <<
"\n";
134 return map_.find(name) !=
map_.end();
147 auto const iter =
map_.find(name);
148 if (iter ==
map_.end())
159 auto const result =
map_.emplace(
160 std::piecewise_construct,
163 result.first->second.set(key, value);
189 for (
auto const& entry : ifs)
191 auto const result =
map_.emplace(
192 std::piecewise_construct,
195 result.first->second.append(entry.second);
202 for (
auto const& [k, v] : c.
map_)
203 ss <<
"[" << k <<
"]\n" << v;
Holds a collection of configuration values.
std::vector< std::string > values_
void legacy(std::string value)
Set the legacy value for this section.
Section(std::string const &name="")
Create an empty section.
bool exists(std::string const &name) const
Returns true if a key with the given name exists.
std::string trim_whitespace(std::string str)
std::ostream & operator<<(std::ostream &os, TOffer< TIn, TOut > const &offer)
void append(std::vector< std::string > const &lines)
Append a set of lines to this section.
std::string const & name() const
Returns the name of this section.
void deprecatedClearSection(std::string const §ion)
Remove all the key/value pairs from the section.
void build(IniFileSections const &ifs)
void legacy(std::string const §ion, std::string value)
Set a value that is not a key/value pair.
std::vector< std::string > const & lines() const
Returns all the lines in the section.
bool had_trailing_comments_
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::pair< std::string, bool > find(std::string const &name) const
Retrieve a key/value pair.
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
void set(std::string const &key, std::string const &value)
Set a key/value pair.
std::vector< std::string > lines_
std::map< std::string, Section, boost::beast::iless > map_
Holds unparsed configuration information.
bool exists(std::string const &name) const
Returns true if a section with the given name exists.
Section & section(std::string const &name)
Returns the section with the given name.