2021-10-24 22:04:23 +00:00
|
|
|
//# This file is a part of toml++ and is subject to the the terms of the MIT license.
|
|
|
|
//# Copyright (c) Mark Gillard <mark.gillard@outlook.com.au>
|
|
|
|
//# See https://github.com/marzer/tomlplusplus/blob/master/LICENSE for the full license text.
|
|
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
//# {{
|
|
|
|
#include "preprocessor.h"
|
|
|
|
#if !TOML_IMPLEMENTATION
|
|
|
|
#error This is an implementation-only header.
|
|
|
|
#endif
|
|
|
|
//# }}
|
|
|
|
|
|
|
|
#include "print_to_stream.h"
|
|
|
|
#include "source_region.h"
|
|
|
|
#include "date_time.h"
|
2021-10-30 12:56:14 +00:00
|
|
|
#include "toml_formatter.h"
|
2021-10-24 22:04:23 +00:00
|
|
|
#include "value.h"
|
|
|
|
#include "array.h"
|
|
|
|
#include "table.h"
|
|
|
|
TOML_DISABLE_WARNINGS;
|
|
|
|
#include <ostream>
|
|
|
|
#if TOML_INT_CHARCONV || TOML_FLOAT_CHARCONV
|
|
|
|
#include <charconv>
|
|
|
|
#endif
|
|
|
|
#if !TOML_INT_CHARCONV || !TOML_FLOAT_CHARCONV
|
|
|
|
#include <sstream>
|
|
|
|
#endif
|
|
|
|
#if !TOML_INT_CHARCONV
|
|
|
|
#include <iomanip>
|
|
|
|
#endif
|
|
|
|
TOML_ENABLE_WARNINGS;
|
|
|
|
#include "header_start.h"
|
|
|
|
|
|
|
|
TOML_ANON_NAMESPACE_START
|
|
|
|
{
|
|
|
|
template <typename T>
|
|
|
|
inline constexpr size_t charconv_buffer_length = 0;
|
|
|
|
|
|
|
|
template <>
|
|
|
|
inline constexpr size_t charconv_buffer_length<int8_t> = 4; // strlen("-128")
|
|
|
|
|
|
|
|
template <>
|
|
|
|
inline constexpr size_t charconv_buffer_length<int16_t> = 6; // strlen("-32768")
|
|
|
|
|
|
|
|
template <>
|
|
|
|
inline constexpr size_t charconv_buffer_length<int32_t> = 11; // strlen("-2147483648")
|
|
|
|
|
|
|
|
template <>
|
|
|
|
inline constexpr size_t charconv_buffer_length<int64_t> = 20; // strlen("-9223372036854775808")
|
|
|
|
|
|
|
|
template <>
|
|
|
|
inline constexpr size_t charconv_buffer_length<uint8_t> = 3; // strlen("255")
|
|
|
|
|
|
|
|
template <>
|
|
|
|
inline constexpr size_t charconv_buffer_length<uint16_t> = 5; // strlen("65535")
|
|
|
|
|
|
|
|
template <>
|
|
|
|
inline constexpr size_t charconv_buffer_length<uint32_t> = 10; // strlen("4294967295")
|
|
|
|
|
|
|
|
template <>
|
|
|
|
inline constexpr size_t charconv_buffer_length<uint64_t> = 20; // strlen("18446744073709551615")
|
|
|
|
|
|
|
|
template <>
|
2022-01-08 14:24:59 +00:00
|
|
|
inline constexpr size_t charconv_buffer_length<float> = 64;
|
2021-10-24 22:04:23 +00:00
|
|
|
|
|
|
|
template <>
|
2022-01-08 14:24:59 +00:00
|
|
|
inline constexpr size_t charconv_buffer_length<double> = 64;
|
2021-10-24 22:04:23 +00:00
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
TOML_INTERNAL_LINKAGE
|
2022-06-06 20:46:04 +00:00
|
|
|
void print_integer_to_stream(std::ostream & stream, T val, value_flags format = {}, size_t min_digits = 0)
|
2021-10-24 22:04:23 +00:00
|
|
|
{
|
|
|
|
if (!val)
|
|
|
|
{
|
2022-01-04 14:23:45 +00:00
|
|
|
if (!min_digits)
|
|
|
|
min_digits = 1;
|
|
|
|
|
|
|
|
for (size_t i = 0; i < min_digits; i++)
|
|
|
|
stream.put('0');
|
|
|
|
|
2021-10-24 22:04:23 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-11-02 20:13:09 +00:00
|
|
|
static constexpr auto value_flags_mask =
|
|
|
|
value_flags::format_as_binary | value_flags::format_as_octal | value_flags::format_as_hexadecimal;
|
|
|
|
format &= value_flags_mask;
|
|
|
|
|
2021-10-24 22:04:23 +00:00
|
|
|
int base = 10;
|
2022-01-04 14:23:45 +00:00
|
|
|
if (format != value_flags::none && val > T{})
|
2021-10-24 22:04:23 +00:00
|
|
|
{
|
|
|
|
switch (format)
|
|
|
|
{
|
|
|
|
case value_flags::format_as_binary: base = 2; break;
|
|
|
|
case value_flags::format_as_octal: base = 8; break;
|
|
|
|
case value_flags::format_as_hexadecimal: base = 16; break;
|
|
|
|
default: break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#if TOML_INT_CHARCONV
|
|
|
|
|
|
|
|
char buf[(sizeof(T) * CHAR_BIT)];
|
|
|
|
const auto res = std::to_chars(buf, buf + sizeof(buf), val, base);
|
|
|
|
const auto len = static_cast<size_t>(res.ptr - buf);
|
2022-01-04 14:23:45 +00:00
|
|
|
for (size_t i = len; i < min_digits; i++)
|
|
|
|
stream.put('0');
|
2021-10-24 22:04:23 +00:00
|
|
|
if (base == 16)
|
|
|
|
{
|
|
|
|
for (size_t i = 0; i < len; i++)
|
|
|
|
if (buf[i] >= 'a')
|
|
|
|
buf[i] -= 32;
|
|
|
|
}
|
|
|
|
impl::print_to_stream(stream, buf, len);
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
using unsigned_type = std::conditional_t<(sizeof(T) > sizeof(unsigned)), std::make_unsigned_t<T>, unsigned>;
|
|
|
|
using cast_type = std::conditional_t<std::is_signed_v<T>, std::make_signed_t<unsigned_type>, unsigned_type>;
|
|
|
|
|
2022-01-04 14:23:45 +00:00
|
|
|
if (base == 2)
|
2021-10-24 22:04:23 +00:00
|
|
|
{
|
2022-01-04 14:23:45 +00:00
|
|
|
const auto len = sizeof(T) * CHAR_BIT;
|
|
|
|
for (size_t i = len; i < min_digits; i++)
|
|
|
|
stream.put('0');
|
|
|
|
|
2021-10-24 22:04:23 +00:00
|
|
|
bool found_one = false;
|
|
|
|
const auto v = static_cast<unsigned_type>(val);
|
2022-01-04 14:23:45 +00:00
|
|
|
unsigned_type mask = unsigned_type{ 1 } << (len - 1u);
|
|
|
|
for (size_t i = 0; i < len; i++)
|
2021-10-24 22:04:23 +00:00
|
|
|
{
|
|
|
|
if ((v & mask))
|
|
|
|
{
|
|
|
|
stream.put('1');
|
|
|
|
found_one = true;
|
|
|
|
}
|
|
|
|
else if (found_one)
|
|
|
|
stream.put('0');
|
|
|
|
mask >>= 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
std::ostringstream ss;
|
|
|
|
ss.imbue(std::locale::classic());
|
|
|
|
ss << std::uppercase << std::setbase(base);
|
2022-01-04 14:23:45 +00:00
|
|
|
if (min_digits)
|
|
|
|
ss << std::setfill('0') << std::setw(static_cast<int>(min_digits));
|
2021-10-24 22:04:23 +00:00
|
|
|
ss << static_cast<cast_type>(val);
|
|
|
|
const auto str = std::move(ss).str();
|
2021-10-25 21:49:17 +00:00
|
|
|
impl::print_to_stream(stream, str);
|
2021-10-24 22:04:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
TOML_INTERNAL_LINKAGE
|
2022-06-06 20:46:04 +00:00
|
|
|
void print_floating_point_to_stream(std::ostream & stream,
|
|
|
|
T val,
|
|
|
|
value_flags format,
|
|
|
|
[[maybe_unused]] bool relaxed_precision)
|
2021-10-24 22:04:23 +00:00
|
|
|
{
|
|
|
|
switch (impl::fpclassify(val))
|
|
|
|
{
|
|
|
|
case impl::fp_class::neg_inf: impl::print_to_stream(stream, "-inf"sv); break;
|
|
|
|
|
|
|
|
case impl::fp_class::pos_inf: impl::print_to_stream(stream, "inf"sv); break;
|
|
|
|
|
|
|
|
case impl::fp_class::nan: impl::print_to_stream(stream, "nan"sv); break;
|
|
|
|
|
|
|
|
case impl::fp_class::ok:
|
|
|
|
{
|
|
|
|
static constexpr auto needs_decimal_point = [](auto&& s) noexcept
|
|
|
|
{
|
|
|
|
for (auto c : s)
|
|
|
|
if (c == '.' || c == 'E' || c == 'e')
|
|
|
|
return false;
|
|
|
|
return true;
|
|
|
|
};
|
|
|
|
|
|
|
|
#if TOML_FLOAT_CHARCONV
|
|
|
|
|
2022-01-08 14:24:59 +00:00
|
|
|
const auto hex = !!(format & value_flags::format_as_hexadecimal);
|
2021-10-24 22:04:23 +00:00
|
|
|
char buf[charconv_buffer_length<T>];
|
2022-01-08 14:24:59 +00:00
|
|
|
auto res = hex ? std::to_chars(buf, buf + sizeof(buf), val, std::chars_format::hex)
|
|
|
|
: std::to_chars(buf, buf + sizeof(buf), val);
|
|
|
|
auto str = std::string_view{ buf, static_cast<size_t>(res.ptr - buf) };
|
|
|
|
|
|
|
|
char buf2[charconv_buffer_length<T>];
|
|
|
|
if (!hex && relaxed_precision)
|
|
|
|
{
|
|
|
|
res = std::to_chars(buf2, buf2 + sizeof(buf2), val, std::chars_format::general, 6);
|
|
|
|
const auto str2 = std::string_view{ buf2, static_cast<size_t>(res.ptr - buf2) };
|
|
|
|
if (str2.length() < str.length())
|
|
|
|
str = str2;
|
|
|
|
}
|
|
|
|
|
2021-10-24 22:04:23 +00:00
|
|
|
impl::print_to_stream(stream, str);
|
2022-01-08 14:24:59 +00:00
|
|
|
if (!hex && needs_decimal_point(str))
|
2021-10-24 22:04:23 +00:00
|
|
|
toml::impl::print_to_stream(stream, ".0"sv);
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
std::ostringstream ss;
|
|
|
|
ss.imbue(std::locale::classic());
|
2022-01-08 14:24:59 +00:00
|
|
|
if (!relaxed_precision)
|
|
|
|
ss.precision(std::numeric_limits<T>::max_digits10);
|
2021-10-24 22:04:23 +00:00
|
|
|
if (!!(format & value_flags::format_as_hexadecimal))
|
|
|
|
ss << std::hexfloat;
|
|
|
|
ss << val;
|
|
|
|
const auto str = std::move(ss).str();
|
|
|
|
impl::print_to_stream(stream, str);
|
|
|
|
if (!(format & value_flags::format_as_hexadecimal) && needs_decimal_point(str))
|
|
|
|
impl::print_to_stream(stream, ".0"sv);
|
|
|
|
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default: TOML_UNREACHABLE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
TOML_ANON_NAMESPACE_END;
|
|
|
|
|
|
|
|
TOML_IMPL_NAMESPACE_START
|
|
|
|
{
|
|
|
|
TOML_EXTERNAL_LINKAGE
|
|
|
|
TOML_ATTR(nonnull)
|
2022-06-06 09:21:46 +00:00
|
|
|
void TOML_CALLCONV print_to_stream(std::ostream & stream, const char* val, size_t len)
|
2021-10-24 22:04:23 +00:00
|
|
|
{
|
|
|
|
stream.write(val, static_cast<std::streamsize>(len));
|
|
|
|
}
|
|
|
|
|
|
|
|
TOML_EXTERNAL_LINKAGE
|
2022-06-06 09:21:46 +00:00
|
|
|
void TOML_CALLCONV print_to_stream(std::ostream & stream, std::string_view val)
|
2021-10-24 22:04:23 +00:00
|
|
|
{
|
|
|
|
stream.write(val.data(), static_cast<std::streamsize>(val.length()));
|
|
|
|
}
|
|
|
|
|
|
|
|
TOML_EXTERNAL_LINKAGE
|
2022-06-06 09:21:46 +00:00
|
|
|
void TOML_CALLCONV print_to_stream(std::ostream & stream, const std::string& val)
|
2021-10-24 22:04:23 +00:00
|
|
|
{
|
|
|
|
stream.write(val.data(), static_cast<std::streamsize>(val.length()));
|
|
|
|
}
|
|
|
|
|
|
|
|
TOML_EXTERNAL_LINKAGE
|
2022-06-06 09:21:46 +00:00
|
|
|
void TOML_CALLCONV print_to_stream(std::ostream & stream, char val)
|
2021-10-24 22:04:23 +00:00
|
|
|
{
|
|
|
|
stream.put(val);
|
|
|
|
}
|
|
|
|
|
|
|
|
TOML_EXTERNAL_LINKAGE
|
2022-08-02 20:24:57 +00:00
|
|
|
void TOML_CALLCONV print_to_stream(std::ostream & stream, signed char val, value_flags format, size_t min_digits)
|
2021-10-24 22:04:23 +00:00
|
|
|
{
|
2022-01-04 14:23:45 +00:00
|
|
|
TOML_ANON_NAMESPACE::print_integer_to_stream(stream, val, format, min_digits);
|
2021-10-24 22:04:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TOML_EXTERNAL_LINKAGE
|
2022-08-02 20:24:57 +00:00
|
|
|
void TOML_CALLCONV print_to_stream(std::ostream & stream, signed short val, value_flags format, size_t min_digits)
|
2021-10-24 22:04:23 +00:00
|
|
|
{
|
2022-01-04 14:23:45 +00:00
|
|
|
TOML_ANON_NAMESPACE::print_integer_to_stream(stream, val, format, min_digits);
|
2021-10-24 22:04:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TOML_EXTERNAL_LINKAGE
|
2022-08-02 20:24:57 +00:00
|
|
|
void TOML_CALLCONV print_to_stream(std::ostream & stream, signed int val, value_flags format, size_t min_digits)
|
2021-10-24 22:04:23 +00:00
|
|
|
{
|
2022-01-04 14:23:45 +00:00
|
|
|
TOML_ANON_NAMESPACE::print_integer_to_stream(stream, val, format, min_digits);
|
2021-10-24 22:04:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TOML_EXTERNAL_LINKAGE
|
2022-08-02 20:24:57 +00:00
|
|
|
void TOML_CALLCONV print_to_stream(std::ostream & stream, signed long val, value_flags format, size_t min_digits)
|
2021-10-24 22:04:23 +00:00
|
|
|
{
|
2022-01-04 14:23:45 +00:00
|
|
|
TOML_ANON_NAMESPACE::print_integer_to_stream(stream, val, format, min_digits);
|
2021-10-24 22:04:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TOML_EXTERNAL_LINKAGE
|
2022-08-02 20:24:57 +00:00
|
|
|
void TOML_CALLCONV print_to_stream(std::ostream & stream,
|
|
|
|
signed long long val,
|
|
|
|
value_flags format,
|
|
|
|
size_t min_digits)
|
2021-10-24 22:04:23 +00:00
|
|
|
{
|
2022-01-04 14:23:45 +00:00
|
|
|
TOML_ANON_NAMESPACE::print_integer_to_stream(stream, val, format, min_digits);
|
2021-10-24 22:04:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TOML_EXTERNAL_LINKAGE
|
2022-08-02 20:24:57 +00:00
|
|
|
void TOML_CALLCONV print_to_stream(std::ostream & stream, unsigned char val, value_flags format, size_t min_digits)
|
2021-10-24 22:04:23 +00:00
|
|
|
{
|
2022-01-04 14:23:45 +00:00
|
|
|
TOML_ANON_NAMESPACE::print_integer_to_stream(stream, val, format, min_digits);
|
2021-10-24 22:04:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TOML_EXTERNAL_LINKAGE
|
2022-08-02 20:24:57 +00:00
|
|
|
void TOML_CALLCONV print_to_stream(std::ostream & stream, unsigned short val, value_flags format, size_t min_digits)
|
2021-10-24 22:04:23 +00:00
|
|
|
{
|
2022-01-04 14:23:45 +00:00
|
|
|
TOML_ANON_NAMESPACE::print_integer_to_stream(stream, val, format, min_digits);
|
2021-10-24 22:04:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TOML_EXTERNAL_LINKAGE
|
2022-08-02 20:24:57 +00:00
|
|
|
void TOML_CALLCONV print_to_stream(std::ostream & stream, unsigned int val, value_flags format, size_t min_digits)
|
|
|
|
{
|
|
|
|
TOML_ANON_NAMESPACE::print_integer_to_stream(stream, val, format, min_digits);
|
|
|
|
}
|
|
|
|
|
|
|
|
TOML_EXTERNAL_LINKAGE
|
|
|
|
void TOML_CALLCONV print_to_stream(std::ostream & stream, unsigned long val, value_flags format, size_t min_digits)
|
|
|
|
{
|
|
|
|
TOML_ANON_NAMESPACE::print_integer_to_stream(stream, val, format, min_digits);
|
|
|
|
}
|
|
|
|
|
|
|
|
TOML_EXTERNAL_LINKAGE
|
|
|
|
void TOML_CALLCONV print_to_stream(std::ostream & stream,
|
|
|
|
unsigned long long val,
|
|
|
|
value_flags format,
|
|
|
|
size_t min_digits)
|
2021-10-24 22:04:23 +00:00
|
|
|
{
|
2022-01-04 14:23:45 +00:00
|
|
|
TOML_ANON_NAMESPACE::print_integer_to_stream(stream, val, format, min_digits);
|
2021-10-24 22:04:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TOML_EXTERNAL_LINKAGE
|
2022-06-06 09:21:46 +00:00
|
|
|
void TOML_CALLCONV print_to_stream(std::ostream & stream, float val, value_flags format, bool relaxed_precision)
|
2021-10-24 22:04:23 +00:00
|
|
|
{
|
2022-01-08 14:24:59 +00:00
|
|
|
TOML_ANON_NAMESPACE::print_floating_point_to_stream(stream, val, format, relaxed_precision);
|
2021-10-24 22:04:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TOML_EXTERNAL_LINKAGE
|
2022-06-06 09:21:46 +00:00
|
|
|
void TOML_CALLCONV print_to_stream(std::ostream & stream, double val, value_flags format, bool relaxed_precision)
|
2021-10-24 22:04:23 +00:00
|
|
|
{
|
2022-01-08 14:24:59 +00:00
|
|
|
TOML_ANON_NAMESPACE::print_floating_point_to_stream(stream, val, format, relaxed_precision);
|
2021-10-24 22:04:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TOML_EXTERNAL_LINKAGE
|
2022-06-06 09:21:46 +00:00
|
|
|
void TOML_CALLCONV print_to_stream(std::ostream & stream, bool val)
|
2021-10-24 22:04:23 +00:00
|
|
|
{
|
|
|
|
print_to_stream(stream, val ? "true"sv : "false"sv);
|
|
|
|
}
|
|
|
|
|
|
|
|
TOML_EXTERNAL_LINKAGE
|
2022-06-06 09:21:46 +00:00
|
|
|
void TOML_CALLCONV print_to_stream(std::ostream & stream, const toml::date& val)
|
2021-10-24 22:04:23 +00:00
|
|
|
{
|
2022-01-04 14:23:45 +00:00
|
|
|
print_to_stream(stream, val.year, {}, 4);
|
2021-10-24 22:04:23 +00:00
|
|
|
stream.put('-');
|
2022-01-04 14:23:45 +00:00
|
|
|
print_to_stream(stream, val.month, {}, 2);
|
2021-10-24 22:04:23 +00:00
|
|
|
stream.put('-');
|
2022-01-04 14:23:45 +00:00
|
|
|
print_to_stream(stream, val.day, {}, 2);
|
2021-10-24 22:04:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TOML_EXTERNAL_LINKAGE
|
2022-06-06 09:21:46 +00:00
|
|
|
void TOML_CALLCONV print_to_stream(std::ostream & stream, const toml::time& val)
|
2021-10-24 22:04:23 +00:00
|
|
|
{
|
2022-01-04 14:23:45 +00:00
|
|
|
print_to_stream(stream, val.hour, {}, 2);
|
2021-10-24 22:04:23 +00:00
|
|
|
stream.put(':');
|
2022-01-04 14:23:45 +00:00
|
|
|
print_to_stream(stream, val.minute, {}, 2);
|
2021-10-24 22:04:23 +00:00
|
|
|
stream.put(':');
|
2022-01-04 14:23:45 +00:00
|
|
|
print_to_stream(stream, val.second, {}, 2);
|
2021-10-24 22:04:23 +00:00
|
|
|
if (val.nanosecond && val.nanosecond <= 999999999u)
|
|
|
|
{
|
|
|
|
stream.put('.');
|
|
|
|
auto ns = val.nanosecond;
|
2021-10-26 13:49:23 +00:00
|
|
|
size_t digits = 9u;
|
2021-10-24 22:04:23 +00:00
|
|
|
while (ns % 10u == 0u)
|
|
|
|
{
|
|
|
|
ns /= 10u;
|
|
|
|
digits--;
|
|
|
|
}
|
2022-01-04 14:23:45 +00:00
|
|
|
print_to_stream(stream, ns, {}, digits);
|
2021-10-24 22:04:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TOML_EXTERNAL_LINKAGE
|
2022-06-06 09:21:46 +00:00
|
|
|
void TOML_CALLCONV print_to_stream(std::ostream & stream, const toml::time_offset& val)
|
2021-10-24 22:04:23 +00:00
|
|
|
{
|
|
|
|
if (!val.minutes)
|
|
|
|
{
|
|
|
|
stream.put('Z');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto mins = static_cast<int>(val.minutes);
|
|
|
|
if (mins < 0)
|
|
|
|
{
|
|
|
|
stream.put('-');
|
|
|
|
mins = -mins;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
stream.put('+');
|
|
|
|
const auto hours = mins / 60;
|
|
|
|
if (hours)
|
|
|
|
{
|
2022-01-04 14:23:45 +00:00
|
|
|
print_to_stream(stream, static_cast<unsigned int>(hours), {}, 2);
|
2021-10-24 22:04:23 +00:00
|
|
|
mins -= hours * 60;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
print_to_stream(stream, "00"sv);
|
|
|
|
stream.put(':');
|
2022-01-04 14:23:45 +00:00
|
|
|
print_to_stream(stream, static_cast<unsigned int>(mins), {}, 2);
|
2021-10-24 22:04:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TOML_EXTERNAL_LINKAGE
|
2022-06-06 09:21:46 +00:00
|
|
|
void TOML_CALLCONV print_to_stream(std::ostream & stream, const toml::date_time& val)
|
2021-10-24 22:04:23 +00:00
|
|
|
{
|
|
|
|
print_to_stream(stream, val.date);
|
|
|
|
stream.put('T');
|
|
|
|
print_to_stream(stream, val.time);
|
|
|
|
if (val.offset)
|
|
|
|
print_to_stream(stream, *val.offset);
|
|
|
|
}
|
|
|
|
|
|
|
|
TOML_EXTERNAL_LINKAGE
|
2022-06-06 09:21:46 +00:00
|
|
|
void TOML_CALLCONV print_to_stream(std::ostream & stream, const source_position& val)
|
2021-10-24 22:04:23 +00:00
|
|
|
{
|
|
|
|
print_to_stream(stream, "line "sv);
|
|
|
|
print_to_stream(stream, val.line);
|
|
|
|
print_to_stream(stream, ", column "sv);
|
|
|
|
print_to_stream(stream, val.column);
|
|
|
|
}
|
|
|
|
|
|
|
|
TOML_EXTERNAL_LINKAGE
|
2022-06-06 09:21:46 +00:00
|
|
|
void TOML_CALLCONV print_to_stream(std::ostream & stream, const source_region& val)
|
2021-10-24 22:04:23 +00:00
|
|
|
{
|
|
|
|
print_to_stream(stream, val.begin);
|
|
|
|
if (val.path)
|
|
|
|
{
|
|
|
|
print_to_stream(stream, " of '"sv);
|
|
|
|
print_to_stream(stream, *val.path);
|
|
|
|
stream.put('\'');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-02 20:13:09 +00:00
|
|
|
#if TOML_ENABLE_FORMATTERS
|
2021-10-30 12:56:14 +00:00
|
|
|
|
2021-10-24 22:04:23 +00:00
|
|
|
TOML_EXTERNAL_LINKAGE
|
2022-06-06 09:21:46 +00:00
|
|
|
void TOML_CALLCONV print_to_stream(std::ostream & stream, const array& arr)
|
2021-10-24 22:04:23 +00:00
|
|
|
{
|
2021-10-30 12:56:14 +00:00
|
|
|
stream << toml_formatter{ arr };
|
2021-10-24 22:04:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TOML_EXTERNAL_LINKAGE
|
2022-06-06 09:21:46 +00:00
|
|
|
void TOML_CALLCONV print_to_stream(std::ostream & stream, const table& tbl)
|
2021-10-24 22:04:23 +00:00
|
|
|
{
|
2021-10-30 12:56:14 +00:00
|
|
|
stream << toml_formatter{ tbl };
|
2021-10-24 22:04:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TOML_EXTERNAL_LINKAGE
|
2022-06-06 09:21:46 +00:00
|
|
|
void TOML_CALLCONV print_to_stream(std::ostream & stream, const value<std::string>& val)
|
2021-10-24 22:04:23 +00:00
|
|
|
{
|
2021-10-30 12:56:14 +00:00
|
|
|
stream << toml_formatter{ val };
|
2021-10-24 22:04:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TOML_EXTERNAL_LINKAGE
|
2022-06-06 09:21:46 +00:00
|
|
|
void TOML_CALLCONV print_to_stream(std::ostream & stream, const value<int64_t>& val)
|
2021-10-24 22:04:23 +00:00
|
|
|
{
|
2021-10-30 12:56:14 +00:00
|
|
|
stream << toml_formatter{ val };
|
2021-10-24 22:04:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TOML_EXTERNAL_LINKAGE
|
2022-06-06 09:21:46 +00:00
|
|
|
void TOML_CALLCONV print_to_stream(std::ostream & stream, const value<double>& val)
|
2021-10-24 22:04:23 +00:00
|
|
|
{
|
2021-10-30 12:56:14 +00:00
|
|
|
stream << toml_formatter{ val };
|
2021-10-24 22:04:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TOML_EXTERNAL_LINKAGE
|
2022-06-06 09:21:46 +00:00
|
|
|
void TOML_CALLCONV print_to_stream(std::ostream & stream, const value<bool>& val)
|
2021-10-24 22:04:23 +00:00
|
|
|
{
|
2021-10-30 12:56:14 +00:00
|
|
|
stream << toml_formatter{ val };
|
2021-10-24 22:04:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TOML_EXTERNAL_LINKAGE
|
2022-06-06 09:21:46 +00:00
|
|
|
void TOML_CALLCONV print_to_stream(std::ostream & stream, const value<date>& val)
|
2021-10-24 22:04:23 +00:00
|
|
|
{
|
2021-10-30 12:56:14 +00:00
|
|
|
stream << toml_formatter{ val };
|
2021-10-24 22:04:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TOML_EXTERNAL_LINKAGE
|
2022-06-06 09:21:46 +00:00
|
|
|
void TOML_CALLCONV print_to_stream(std::ostream & stream, const value<time>& val)
|
2021-10-24 22:04:23 +00:00
|
|
|
{
|
2021-10-30 12:56:14 +00:00
|
|
|
stream << toml_formatter{ val };
|
2021-10-24 22:04:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TOML_EXTERNAL_LINKAGE
|
2022-06-06 09:21:46 +00:00
|
|
|
void TOML_CALLCONV print_to_stream(std::ostream & stream, const value<date_time>& val)
|
2021-10-24 22:04:23 +00:00
|
|
|
{
|
2021-10-30 12:56:14 +00:00
|
|
|
stream << toml_formatter{ val };
|
2021-10-24 22:04:23 +00:00
|
|
|
}
|
2021-10-30 12:56:14 +00:00
|
|
|
|
|
|
|
#endif
|
2021-10-24 22:04:23 +00:00
|
|
|
}
|
|
|
|
TOML_IMPL_NAMESPACE_END;
|
|
|
|
|
|
|
|
#include "header_end.h"
|