mirror of
https://github.com/XRPLF/rippled.git
synced 2025-11-20 11:05:54 +00:00
78 lines
2.6 KiB
C++
78 lines
2.6 KiB
C++
//------------------------------------------------------------------------------
|
|
/*
|
|
This file is part of rippled: https://github.com/ripple/rippled
|
|
Copyright (c) 2012, 2013 Ripple Labs Inc.
|
|
|
|
Permission to use, copy, modify, and/or distribute this software for any
|
|
purpose with or without fee is hereby granted, provided that the above
|
|
copyright notice and this permission notice appear in all copies.
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
*/
|
|
//==============================================================================
|
|
|
|
#include <ripple/core/Section.h>
|
|
#include <boost/regex.hpp>
|
|
|
|
namespace ripple {
|
|
|
|
void
|
|
Section::append (std::vector <std::string> const& lines)
|
|
{
|
|
// <key> '=' <value>
|
|
static boost::regex const re1 (
|
|
"^" // start of line
|
|
"(?:\\s*)" // whitespace (optonal)
|
|
"([a-zA-Z][_a-zA-Z0-9]*)" // <key>
|
|
"(?:\\s*)" // whitespace (optional)
|
|
"(?:=)" // '='
|
|
"(?:\\s*)" // whitespace (optional)
|
|
"(.*\\S+)" // <value>
|
|
"(?:\\s*)" // whitespace (optional)
|
|
, boost::regex_constants::optimize
|
|
);
|
|
|
|
lines_.reserve (lines_.size() + lines.size());
|
|
for (auto const& line : lines)
|
|
{
|
|
boost::smatch match;
|
|
lines_.push_back (line);
|
|
if (boost::regex_match (line, match, re1))
|
|
{
|
|
/*auto const result =*/ map_.emplace (
|
|
std::make_pair (match[1], match[2]));
|
|
#if 0
|
|
if (! result.second)
|
|
{
|
|
// If we decide on how to merge values we can do it here.
|
|
}
|
|
beast::debug_ostream log;
|
|
//log << "\"" << match[1] << "\" = \"" << match[2] << "\"";
|
|
#endif
|
|
}
|
|
}
|
|
}
|
|
|
|
bool
|
|
Section::exists (std::string const& name) const
|
|
{
|
|
return map_.find (name) != map_.end();
|
|
}
|
|
|
|
std::pair <std::string, bool>
|
|
Section::find (std::string const& name) const
|
|
{
|
|
auto const iter = map_.find (name);
|
|
if (iter == map_.end())
|
|
return {{}, false};
|
|
return {iter->second, true};
|
|
}
|
|
|
|
} // ripple
|