OpenVPN 3 Core Library
Loading...
Searching...
No Matches
jsonhelperfmt.hpp
Go to the documentation of this file.
1// OpenVPN -- An application to securely tunnel IP networks
2// over a single port, with support for SSL/TLS-based
3// session authentication and key exchange,
4// packet encryption, packet authentication, and
5// packet compression.
6//
7// Copyright (C) 2012- OpenVPN Inc.
8//
9// SPDX-License-Identifier: MPL-2.0 OR AGPL-3.0-only WITH openvpn3-openssl-exception
10//
11
12#pragma once
13
14#include <string>
15
17
18namespace openvpn::json {
19
20// format name.title but omit .title if title is empty
21template <typename NAME, typename TITLE>
22inline std::string fmt_name(const NAME &name, const TITLE &title)
23{
24 if (!StringTempl::empty(title))
25 return StringTempl::to_string(title) + '.' + StringTempl::to_string(name);
26 else
27 return StringTempl::to_string(name);
28}
29
30// if title is not a number, treat as an ordinary string
31template <typename TITLE,
32 typename std::enable_if<!std::is_arithmetic<TITLE>::value, int>::type = 0>
33inline std::string fmt_name_cast(const TITLE &title)
34{
35 return StringTempl::to_string(title);
36}
37
38// if title is a number, assume that it is referring to an array element
39template <typename TITLE,
40 typename std::enable_if<std::is_arithmetic<TITLE>::value, int>::type = 0>
41inline std::string fmt_name_cast(const TITLE &title)
42{
43 return "element." + StringTempl::to_string(title);
44}
45
46} // namespace openvpn::json
std::string to_string(std::nullptr_t)
bool empty(std::nullptr_t)
std::string fmt_name_cast(const TITLE &title)
std::string fmt_name(const NAME &name, const TITLE &title)