1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
/*
* This source code is released into the public domain.
*/
#include "config_string.hh"
namespace lfjail::config {
/*
* config::string_option, string values.
*
* The option constructors are usually invoked from a global object before
* main() runs, so don't propagate exceptions.
*/
//NOLINTNEXTLINE(bugprone-exception-escape)
string_option::string_option(std::string_view name_,
std::string_view description_) noexcept
try : value(name_, description_, true)
{
} catch (std::exception const &exc) {
std::cerr << "lfjail: ERROR: failed to initialise string_option "
<< name_ << ": " << exc.what() << "\n";
std::abort();
}
//NOLINTNEXTLINE(bugprone-exception-escape)
string_option::string_option(std::string_view name_,
std::string_view description_,
std::string_view default_value) noexcept
try : value(name_, description_, false)
, _value(std::from_range, default_value)
{
} catch (std::exception const &exc) {
std::cerr << "lfjail: ERROR: failed to initialise string_option "
<< name_ << ": " << exc.what() << "\n";
std::abort();
}
auto string_option::get_string() const -> std::string {
return _value;
};
void string_option::set_string(std::string_view new_value) {
_value = new_value;
}
void string_option::add_to_ucl(ucl_object_t *ucl) const {
auto ucl_value = ucl_object_fromstring_common(
_value.data(), _value.size(),
UCL_STRING_RAW);
ucl_object_insert_key(ucl, ucl_value,
name.data(), name.size(), true);
}
} // namespace lfjail::config
|