3 #include "fly/types/string/concepts.hpp"
4 #include "fly/types/string/literals.hpp"
11 namespace fly::detail {
40 void setf(std::ios_base::fmtflags flag);
48 void setf(std::ios_base::fmtflags flag, std::ios_base::fmtflags mask);
55 template <
typename Facet>
70 void width(std::streamsize size);
83 std::ostream &m_stream;
85 const std::ios_base::fmtflags m_flags;
86 bool m_changed_flags {
false};
88 const std::locale m_locale;
89 bool m_changed_locale {
false};
92 bool m_changed_fill {
false};
94 const std::streamsize m_width;
95 bool m_changed_width {
false};
97 const std::streamsize m_precision;
98 bool m_changed_precision {
false};
108 template <fly::StandardCharacter CharType>
112 CharType do_widen(
char ch)
const override;
114 const char *do_widen(
const char *begin,
const char *end, CharType *dest)
const override;
117 static constexpr
const auto s_plus_sign = FLY_CHR(
char,
'+');
118 static constexpr
const auto s_space = FLY_CHR(CharType,
' ');
124 m_flags(stream.flags()),
125 m_locale(stream.getloc()),
126 m_fill(stream.fill()),
127 m_width(stream.width()),
128 m_precision(stream.precision())
137 m_stream.flags(m_flags);
139 if (m_changed_locale)
141 m_stream.imbue(m_locale);
145 m_stream.fill(m_fill);
149 m_stream.width(m_width);
151 if (m_changed_precision)
153 m_stream.precision(m_precision);
161 m_changed_flags =
true;
167 m_stream.setf(flag, mask);
168 m_changed_flags =
true;
172 template <
typename Facet>
175 m_stream.imbue({m_stream.getloc(),
new Facet()});
176 m_changed_locale =
true;
183 m_changed_fill =
true;
189 m_stream.width(size);
190 m_changed_width =
true;
196 m_stream.precision(size);
197 m_changed_precision =
true;
201 template <fly::StandardCharacter CharType>
204 return (ch == s_plus_sign) ? s_space :
static_cast<CharType
>(ch);
208 template <fly::StandardCharacter CharType>
210 PositivePaddingFacet<CharType>::do_widen(
const char *begin,
const char *end, CharType *dest)
const
214 *dest++ = do_widen(*begin++);
Definition: stream_util.hpp:110
Definition: stream_util.hpp:21
ScopedStreamModifiers(std::ostream &stream) noexcept
Definition: stream_util.hpp:122
void width(std::streamsize size)
Definition: stream_util.hpp:187
void setf(std::ios_base::fmtflags flag)
Definition: stream_util.hpp:158
void precision(std::streamsize size)
Definition: stream_util.hpp:194
~ScopedStreamModifiers()
Definition: stream_util.hpp:133
void fill(char ch)
Definition: stream_util.hpp:180
void locale()
Definition: stream_util.hpp:173