2#ifndef LOGIT_CPP_HEADER_LOGIT_CPP_LOGIT_UTILS_TAG_UTILS_HPP_INCLUDED
3#define LOGIT_CPP_HEADER_LOGIT_CPP_LOGIT_UTILS_TAG_UTILS_HPP_INCLUDED
7#include <initializer_list>
13namespace logit {
namespace detail {
21 std::ostringstream oss;
30 inline std::pair<std::string,std::string>
make_tag(std::string key, std::string value) {
31 return { std::move(key), std::move(value) };
40 inline std::pair<std::string,std::string>
make_tag(
const char* key,
const V& v) {
47 inline std::string
format_tags(std::initializer_list<std::pair<std::string,std::string>> tags) {
48 if (tags.size() == 0)
return {};
49 std::ostringstream oss;
53 for (
const auto& kv : tags) {
57 const std::string& k = kv.first;
58 const std::string& v = kv.second;
60 auto need_quote = [] (
const std::string& s) {
61 return s.find(
' ') != std::string::npos ||
62 s.find(
'=') != std::string::npos;
66# if LOGIT_TAG_QUOTE_VALUES
69 for (
char c : v) {
if (c ==
'"') oss <<
'\\'; oss << c; }
#define LOGIT_TAG_PAIR_SEP
Separator between individual tag pairs (e.g., " " or "; ").
#define LOGIT_TAG_KV_SEP
Separator between a tag key and its value.
#define LOGIT_TAGS_JOIN
Separator inserted between the main message and the tag list (e.g., " | ").
std::string to_string_any(const T &v)
Convert value to string via stream insertion.
std::string format_tags(std::initializer_list< std::pair< std::string, std::string > > tags)
Format tag list into a single string.
std::pair< std::string, std::string > make_tag(std::string key, std::string value)
Create tag from string key and value.
std::string make_section(const T &name)
Format a raw section name as [name].
The primary namespace for the LogIt++ library.