Ne.app NeANT
The Ne.app NeANT User module of the NeANT distribution.
formatter.hpp
Go to the documentation of this file.
1// # This file is a part of toml++ and is subject to the the terms of the MIT license.
2// # Copyright (c) Mark Gillard <mark.gillard@outlook.com.au>
3// # See https://github.com/marzer/tomlplusplus/blob/master/LICENSE for the full license text.
4// SPDX-License-Identifier: MIT
5#pragma once
6
7#include "preprocessor.hpp"
8#if TOML_ENABLE_FORMATTERS
9
11#include "header_start.hpp"
12#include "print_to_stream.hpp"
14
16 struct formatter_constants {
17 format_flags mandatory_flags;
18 format_flags ignored_flags;
19
20 std::string_view float_pos_inf;
21 std::string_view float_neg_inf;
22 std::string_view float_nan;
23
24 std::string_view bool_true;
25 std::string_view bool_false;
26 };
27
28 struct formatter_config {
30 std::string_view indent;
31 };
32
33 class TOML_EXPORTED_CLASS formatter {
34 private:
35 const node* source_;
36#if TOML_ENABLE_PARSER && !TOML_EXCEPTIONS
37 const parse_result* result_;
38#endif
39 const formatter_constants* constants_;
40 formatter_config config_;
41 size_t indent_columns_;
42 format_flags int_format_mask_;
43 std::ostream* stream_; //
44 int indent_; // these are set in attach()
45 bool naked_newline_; //
46
47 protected:
49 const node& source() const noexcept { return *source_; }
50
52 std::ostream& stream() const noexcept { return *stream_; }
53
55 int indent() const noexcept { return indent_; }
56
57 void indent(int level) noexcept { indent_ = level; }
58
59 void increase_indent() noexcept { indent_++; }
60
61 void decrease_indent() noexcept { indent_--; }
62
64 size_t indent_columns() const noexcept { return indent_columns_; }
65
67 bool indent_array_elements() const noexcept {
68 return !!(config_.flags & format_flags::indent_array_elements);
69 }
70
72 bool indent_sub_tables() const noexcept {
73 return !!(config_.flags & format_flags::indent_sub_tables);
74 }
75
77 bool literal_strings_allowed() const noexcept {
78 return !!(config_.flags & format_flags::allow_literal_strings);
79 }
80
82 bool multi_line_strings_allowed() const noexcept {
83 return !!(config_.flags & format_flags::allow_multi_line_strings);
84 }
85
87 bool real_tabs_in_strings_allowed() const noexcept {
88 return !!(config_.flags & format_flags::allow_real_tabs_in_strings);
89 }
90
92 bool unicode_strings_allowed() const noexcept {
93 return !!(config_.flags & format_flags::allow_unicode_strings);
94 }
95
97 bool terse_kvps() const noexcept {
98 return !!(config_.flags & format_flags::terse_key_value_pairs);
99 }
100
102 void attach(std::ostream& stream) noexcept;
103
105 void detach() noexcept;
106
108 void print_newline(bool force = false);
109
111 void print_indent();
112
114 void print_unformatted(char);
115
117 void print_unformatted(std::string_view);
118
120 void print_string(std::string_view str, bool allow_multi_line = true, bool allow_bare = false,
121 bool allow_literal_whitespace = true);
122
124 void print(const value<std::string>&);
125
127 void print(const value<int64_t>&);
128
130 void print(const value<double>&);
131
133 void print(const value<bool>&);
134
136 void print(const value<date>&);
137
139 void print(const value<time>&);
140
142 void print(const value<date_time>&);
143
145 void print_value(const node&, node_type);
146
149 bool dump_failed_parse_result();
150
153 formatter(const node*, const parse_result*, const formatter_constants&,
154 const formatter_config&) noexcept;
155 };
156}
158
160#include "header_end.hpp"
161#endif // TOML_ENABLE_FORMATTERS
const char print[]
#define stream
Definition 17.names.cpp:548
#define flags
T value(const T &val)
The result of a parsing operation.
const char * str
Definition exec.cpp:170
enum TOML_CLOSED_FLAGS_ENUM format_flags
Format flags for modifying how TOML data is printed to streams.
enum TOML_CLOSED_FLAGS_ENUM indent_sub_tables
Apply indentation to tables nested within other tables/arrays.
enum TOML_CLOSED_FLAGS_ENUM indent_array_elements
Apply indentation to array elements when the array is forced to wrap over multiple lines.
#define TOML_EXPORTED_CLASS
An 'export' annotation to add to classes. \detail Not defined by default.
#define TOML_EXPORTED_MEMBER_FUNCTION
An 'export' annotation to add to non-static class member functions. \detail Not defined by default.
Definition json.h:5363
#define TOML_NODISCARD_CTOR
#define TOML_NODISCARD
#define TOML_PURE_INLINE_GETTER
#define TOML_IMPL_NAMESPACE_END
#define TOML_IMPL_NAMESPACE_START
#define true
Definition stdbool.h:25
#define false
Definition stdbool.h:26
A date-time.
A local time-of-day.