2020-03-12 17:23:25 +02:00
|
|
|
//# This file is a part of toml++ and is subject to the the terms of the MIT license.
|
2021-01-02 17:48:47 +02:00
|
|
|
//# Copyright (c) Mark Gillard <mark.gillard@outlook.com.au>
|
2020-03-12 17:23:25 +02:00
|
|
|
//# See https://github.com/marzer/tomlplusplus/blob/master/LICENSE for the full license text.
|
2020-04-10 19:46:00 +03:00
|
|
|
// SPDX-License-Identifier: MIT
|
2020-01-07 17:52:50 +02:00
|
|
|
#pragma once
|
2020-04-06 15:57:49 +03:00
|
|
|
|
2021-10-25 01:04:23 +03:00
|
|
|
#include "std_string.h"
|
2021-11-06 18:59:47 +02:00
|
|
|
#include "forward_declarations.h"
|
2021-10-25 01:04:23 +03:00
|
|
|
#include "header_start.h"
|
2020-09-06 13:01:14 +03:00
|
|
|
|
2020-07-25 20:37:30 +03:00
|
|
|
TOML_IMPL_NAMESPACE_START
|
2020-01-07 17:52:50 +02:00
|
|
|
{
|
|
|
|
// Q: "why does print_to_stream() exist? why not just use ostream::write(), ostream::put() etc?"
|
|
|
|
// A: - I'm supporting C++20's char8_t as well; wrapping streams allows switching string modes transparently.
|
2020-02-03 11:12:43 +02:00
|
|
|
// - I'm using <charconv> to format numerics. Faster and locale-independent.
|
2021-10-25 01:04:23 +03:00
|
|
|
// - I can (potentially) avoid forcing users to drag in <sstream> and <iomanip>.
|
2020-02-03 11:12:43 +02:00
|
|
|
// - Strings in C++. Honestly.
|
|
|
|
|
2021-10-25 01:04:23 +03:00
|
|
|
TOML_API
|
|
|
|
TOML_ATTR(nonnull)
|
|
|
|
void print_to_stream(std::ostream&, const char*, size_t);
|
2020-01-07 17:52:50 +02:00
|
|
|
|
2021-10-25 01:04:23 +03:00
|
|
|
TOML_API
|
|
|
|
void print_to_stream(std::ostream&, std::string_view);
|
2020-01-07 17:52:50 +02:00
|
|
|
|
2021-10-25 01:04:23 +03:00
|
|
|
TOML_API
|
|
|
|
void print_to_stream(std::ostream&, const std::string&);
|
2020-01-07 17:52:50 +02:00
|
|
|
|
2021-10-25 01:04:23 +03:00
|
|
|
TOML_API
|
|
|
|
void print_to_stream(std::ostream&, char);
|
2020-01-07 17:52:50 +02:00
|
|
|
|
2021-10-25 01:04:23 +03:00
|
|
|
TOML_API
|
|
|
|
void print_to_stream(std::ostream&, int8_t, value_flags = {});
|
2020-01-07 17:52:50 +02:00
|
|
|
|
2021-10-25 01:04:23 +03:00
|
|
|
TOML_API
|
|
|
|
void print_to_stream(std::ostream&, int16_t, value_flags = {});
|
2020-01-07 17:52:50 +02:00
|
|
|
|
2021-10-25 01:04:23 +03:00
|
|
|
TOML_API
|
|
|
|
void print_to_stream(std::ostream&, int32_t, value_flags = {});
|
2020-01-07 17:52:50 +02:00
|
|
|
|
2021-10-25 01:04:23 +03:00
|
|
|
TOML_API
|
|
|
|
void print_to_stream(std::ostream&, int64_t, value_flags = {});
|
2020-01-07 17:52:50 +02:00
|
|
|
|
2021-10-25 01:04:23 +03:00
|
|
|
TOML_API
|
|
|
|
void print_to_stream(std::ostream&, uint8_t, value_flags = {});
|
2020-01-07 17:52:50 +02:00
|
|
|
|
2021-10-25 01:04:23 +03:00
|
|
|
TOML_API
|
|
|
|
void print_to_stream(std::ostream&, uint16_t, value_flags = {});
|
2020-04-06 15:57:49 +03:00
|
|
|
|
2021-10-25 01:04:23 +03:00
|
|
|
TOML_API
|
|
|
|
void print_to_stream(std::ostream&, uint32_t, value_flags = {});
|
2020-09-06 13:01:14 +03:00
|
|
|
|
2021-10-25 01:04:23 +03:00
|
|
|
TOML_API
|
|
|
|
void print_to_stream(std::ostream&, uint64_t, value_flags = {});
|
2021-10-23 12:22:41 +03:00
|
|
|
|
2021-10-25 01:04:23 +03:00
|
|
|
TOML_API
|
|
|
|
void print_to_stream(std::ostream&, float, value_flags = {});
|
2020-04-06 15:57:49 +03:00
|
|
|
|
2021-10-25 01:04:23 +03:00
|
|
|
TOML_API
|
|
|
|
void print_to_stream(std::ostream&, double, value_flags = {});
|
2021-10-23 12:22:41 +03:00
|
|
|
|
2021-10-25 01:04:23 +03:00
|
|
|
TOML_API
|
|
|
|
void print_to_stream(std::ostream&, bool);
|
2021-10-23 12:22:41 +03:00
|
|
|
|
2021-10-25 01:04:23 +03:00
|
|
|
TOML_API
|
|
|
|
void print_to_stream(std::ostream&, const toml::date&);
|
2020-01-07 17:52:50 +02:00
|
|
|
|
2021-10-25 01:04:23 +03:00
|
|
|
TOML_API
|
|
|
|
void print_to_stream(std::ostream&, const toml::time&);
|
2020-01-07 17:52:50 +02:00
|
|
|
|
2021-10-25 01:04:23 +03:00
|
|
|
TOML_API
|
|
|
|
void print_to_stream(std::ostream&, const toml::time_offset&);
|
2020-01-07 17:52:50 +02:00
|
|
|
|
2021-10-25 01:04:23 +03:00
|
|
|
TOML_API
|
|
|
|
void print_to_stream(std::ostream&, const toml::date_time&);
|
2020-01-07 17:52:50 +02:00
|
|
|
|
2021-10-25 01:04:23 +03:00
|
|
|
TOML_API
|
|
|
|
void print_to_stream(std::ostream&, const source_position&);
|
2020-04-03 00:39:21 +03:00
|
|
|
|
2021-10-25 01:04:23 +03:00
|
|
|
TOML_API
|
|
|
|
void print_to_stream(std::ostream&, const source_region&);
|
2020-01-07 17:52:50 +02:00
|
|
|
|
2021-11-02 22:13:09 +02:00
|
|
|
#if TOML_ENABLE_FORMATTERS
|
2021-10-30 15:56:14 +03:00
|
|
|
|
2021-10-25 01:04:23 +03:00
|
|
|
TOML_API
|
|
|
|
void print_to_stream(std::ostream&, const array&);
|
2020-01-07 17:52:50 +02:00
|
|
|
|
2021-10-25 01:04:23 +03:00
|
|
|
TOML_API
|
|
|
|
void print_to_stream(std::ostream&, const table&);
|
2020-01-07 17:52:50 +02:00
|
|
|
|
2021-10-25 01:04:23 +03:00
|
|
|
TOML_API
|
|
|
|
void print_to_stream(std::ostream&, const value<std::string>&);
|
2020-01-07 17:52:50 +02:00
|
|
|
|
2021-10-25 01:04:23 +03:00
|
|
|
TOML_API
|
|
|
|
void print_to_stream(std::ostream&, const value<int64_t>&);
|
2020-01-07 17:52:50 +02:00
|
|
|
|
2021-10-25 01:04:23 +03:00
|
|
|
TOML_API
|
|
|
|
void print_to_stream(std::ostream&, const value<double>&);
|
2020-01-07 17:52:50 +02:00
|
|
|
|
2021-10-25 01:04:23 +03:00
|
|
|
TOML_API
|
|
|
|
void print_to_stream(std::ostream&, const value<bool>&);
|
2020-01-07 17:52:50 +02:00
|
|
|
|
2021-10-25 01:04:23 +03:00
|
|
|
TOML_API
|
|
|
|
void print_to_stream(std::ostream&, const value<date>&);
|
2020-01-07 17:52:50 +02:00
|
|
|
|
2021-10-25 01:04:23 +03:00
|
|
|
TOML_API
|
|
|
|
void print_to_stream(std::ostream&, const value<time>&);
|
2020-01-12 17:37:02 +02:00
|
|
|
|
2021-10-25 01:04:23 +03:00
|
|
|
TOML_API
|
|
|
|
void print_to_stream(std::ostream&, const value<date_time>&);
|
|
|
|
|
2021-10-30 15:56:14 +03:00
|
|
|
#endif
|
|
|
|
|
2021-10-25 01:04:23 +03:00
|
|
|
template <typename T>
|
|
|
|
inline void print_to_stream_with_escapes(std::ostream & stream, const T& str)
|
2020-01-12 17:37:02 +02:00
|
|
|
{
|
|
|
|
for (auto c : str)
|
|
|
|
{
|
2020-07-18 15:10:19 +03:00
|
|
|
if TOML_UNLIKELY(c >= '\x00' && c <= '\x1F')
|
2021-10-25 01:04:23 +03:00
|
|
|
print_to_stream(stream, low_character_escape_table[c]);
|
2020-07-18 15:10:19 +03:00
|
|
|
else if TOML_UNLIKELY(c == '\x7F')
|
2021-10-25 01:04:23 +03:00
|
|
|
print_to_stream(stream, "\\u007F"sv);
|
2020-07-18 15:10:19 +03:00
|
|
|
else if TOML_UNLIKELY(c == '"')
|
2021-10-25 01:04:23 +03:00
|
|
|
print_to_stream(stream, "\\\""sv);
|
2020-07-18 15:10:19 +03:00
|
|
|
else if TOML_UNLIKELY(c == '\\')
|
2021-10-25 01:04:23 +03:00
|
|
|
print_to_stream(stream, "\\\\"sv);
|
2020-01-12 17:37:02 +02:00
|
|
|
else
|
2021-10-25 01:04:23 +03:00
|
|
|
print_to_stream(stream, c);
|
2020-01-12 17:37:02 +02:00
|
|
|
}
|
|
|
|
}
|
2020-02-03 11:12:43 +02:00
|
|
|
|
2021-10-25 01:04:23 +03:00
|
|
|
template <typename T, typename U>
|
|
|
|
inline void print_to_stream_bookended(std::ostream & stream, const T& val, const U& bookend)
|
2020-02-03 11:12:43 +02:00
|
|
|
{
|
2021-10-25 01:04:23 +03:00
|
|
|
print_to_stream(stream, bookend);
|
|
|
|
print_to_stream(stream, val);
|
|
|
|
print_to_stream(stream, bookend);
|
2020-02-03 11:12:43 +02:00
|
|
|
}
|
2020-04-03 00:39:21 +03:00
|
|
|
}
|
2021-10-25 01:04:23 +03:00
|
|
|
TOML_IMPL_NAMESPACE_END;
|
2020-09-06 13:01:14 +03:00
|
|
|
|
2021-10-24 13:21:32 +03:00
|
|
|
#include "header_end.h"
|