Toolbox
snapshot
The Reactive C++ Toolbox
Loading...
Searching...
No Matches
toolbox
util
VarSub.hpp
Go to the documentation of this file.
1
// The Reactive C++ Toolbox.
2
// Copyright (C) 2013-2019 Swirly Cloud Limited
3
// Copyright (C) 2021 Reactive Markets Limited
4
//
5
// Licensed under the Apache License, Version 2.0 (the "License");
6
// you may not use this file except in compliance with the License.
7
// You may obtain a copy of the License at
8
//
9
// http://www.apache.org/licenses/LICENSE-2.0
10
//
11
// Unless required by applicable law or agreed to in writing, software
12
// distributed under the License is distributed on an "AS IS" BASIS,
13
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
// See the License for the specific language governing permissions and
15
// limitations under the License.
16
17
#ifndef TOOLBOX_UTIL_VARSUB_HPP
18
#define TOOLBOX_UTIL_VARSUB_HPP
19
20
#include <
toolbox/Config.h
>
21
22
#include <functional>
23
#include <set>
24
#include <string>
25
26
namespace
toolbox
{
27
inline
namespace
util {
28
29
TOOLBOX_API
std::string
get_env
(
const
std::string& name);
30
32
class
TOOLBOX_API
VarSub
{
33
public
:
34
explicit
VarSub
(std::function<std::string(
const
std::string&)> fn = get_env)
35
: fn_{
std
::move(fn)}
36
{
37
}
38
~VarSub
();
39
40
// Copy.
41
VarSub
(
const
VarSub
&);
42
VarSub
&
operator=
(
const
VarSub
&);
43
44
// Move.
45
VarSub
(
VarSub
&&) noexcept;
46
VarSub
& operator=(
VarSub
&&) noexcept;
47
48
void
operator()(
std
::
string
& s)
const
{ substitute(s, std::string::npos, 0); }
49
50
private
:
62
bool
substitute(std::string& s,
const
std::size_t i, std::size_t j,
63
std::set<std::string>* outer =
nullptr
)
const
;
64
65
std::function<std::string(
const
std::string&)> fn_;
66
};
67
68
}
// namespace util
69
}
// namespace toolbox
70
71
#endif
// TOOLBOX_UTIL_VARSUB_HPP
Config.h
TOOLBOX_API
#define TOOLBOX_API
Definition
Config.h:39
toolbox::util::VarSub
Variable substitution.
Definition
VarSub.hpp:32
toolbox::util::VarSub::VarSub
VarSub(VarSub &&) noexcept
toolbox::util::VarSub::~VarSub
~VarSub()
toolbox::util::VarSub::VarSub
VarSub(const VarSub &)
toolbox::util::VarSub::VarSub
VarSub(std::function< std::string(const std::string &)> fn=get_env)
Definition
VarSub.hpp:34
toolbox::util::VarSub::operator=
VarSub & operator=(const VarSub &)
std
STL namespace.
toolbox::util::get_env
string get_env(const string &name)
Definition
VarSub.cpp:25
toolbox
Definition
Benchmark.cpp:26
Generated by
1.9.8