8 #ifndef FMTQUILL_XCHAR_H_ 9 #define FMTQUILL_XCHAR_H_ 16 #ifndef FMTQUILL_MODULE 18 # if FMTQUILL_USE_LOCALE 23 FMTQUILL_BEGIN_NAMESPACE
27 using is_exotic_char = bool_constant<!std::is_same<T, char>::value>;
33 S, void_t<decltype(sizeof(
detail::to_string_view(std::declval<S>())))>> {
39 S, enable_if_t<
std::is_base_of<detail::compile_string, S>
::value>> {
40 using type =
typename S::char_type;
48 #if FMTQUILL_USE_LOCALE 50 std::use_facet<std::numpunct<wchar_t>>(loc.get<std::locale>());
51 auto separator = std::wstring();
52 auto grouping = numpunct.grouping();
53 if (!grouping.empty()) separator = std::wstring(1, numpunct.thousands_sep());
64 using wformat_context = buffered_context<wchar_t>;
72 static constexpr
int num_static_named_args =
73 detail::count_static_named_args<T...>();
76 Char,
static_cast<int>(
sizeof...(T)), num_static_named_args,
77 num_static_named_args != detail::count_named_args<T...>()>;
87 FMTQUILL_CONSTEVAL FMTQUILL_ALWAYS_INLINE
basic_fstring(
const S& s) : str_(s) {
88 if (FMTQUILL_USE_CONSTEVAL)
92 FMTQUILL_ENABLE_IF(std::is_base_of<detail::compile_string, S>::value&&
93 std::is_same<typename S::char_type, Char>::value)>
94 FMTQUILL_ALWAYS_INLINE basic_fstring(
const S&) : str_(S()) {
96 FMTQUILL_CONSTEXPR
int ignore =
98 detail::ignore_unused(ignore);
106 template <
typename Char,
typename... T>
109 template <
typename... T>
116 template <>
struct is_char<char8_t> : bool_constant<detail::is_utf8_enabled> {};
119 template <
typename... T>
120 constexpr
auto make_wformat_args(T&... args)
121 -> decltype(fmtquill::make_format_args<wformat_context>(args...)) {
122 return fmtquill::make_format_args<wformat_context>(args...);
125 #if !FMTQUILL_USE_NONTYPE_TEMPLATE_ARGS 133 template <
typename It,
typename Sentinel>
136 return {begin, end, sep};
139 template <typename Range, FMTQUILL_ENABLE_IF(!is_tuple_like<Range>::value)>
141 ->
join_view<decltype(std::begin(range)), decltype(std::end(range)),
143 return join(std::begin(range), std::end(range), sep);
146 template <
typename T>
147 auto join(std::initializer_list<T> list,
wstring_view sep)
149 return join(std::begin(list), std::end(list), sep);
152 template <typename Tuple, FMTQUILL_ENABLE_IF(is_tuple_like<Tuple>::value)>
158 template <typename Char, FMTQUILL_ENABLE_IF(!std::is_same<Char, char>::value)>
161 -> std::basic_string<Char> {
163 detail::vformat_to(buf, fmt, args);
164 return {buf.data(), buf.size()};
167 template <
typename... T>
168 auto format(wformat_string<T...> fmt, T&&... args) -> std::wstring {
169 return vformat(fmtquill::wstring_view(fmt), fmtquill::make_wformat_args(args...));
172 template <
typename OutputIt,
typename... T>
173 auto format_to(OutputIt out, wformat_string<T...> fmt, T&&... args)
175 return vformat_to(out, fmtquill::wstring_view(fmt),
176 fmtquill::make_wformat_args(args...));
181 template <
typename S,
typename... T,
182 typename Char = detail::format_string_char_t<S>,
183 FMTQUILL_ENABLE_IF(!std::is_same<Char, char>::value &&
184 !std::is_same<Char, wchar_t>::value)>
185 auto format(
const S& fmt, T&&... args) -> std::basic_string<Char> {
186 return vformat(detail::to_string_view(fmt),
187 fmtquill::make_format_args<buffered_context<Char>>(args...));
190 template <
typename Locale,
typename S,
191 typename Char = detail::format_string_char_t<S>,
193 detail::is_exotic_char<Char>::value)>
194 inline auto vformat(
const Locale& loc,
const S& fmt,
196 -> std::basic_string<Char> {
198 detail::vformat_to(buf, detail::to_string_view(fmt), args,
200 return {buf.data(), buf.size()};
203 template <
typename Locale,
typename S,
typename... T,
204 typename Char = detail::format_string_char_t<S>,
206 detail::is_exotic_char<Char>::value)>
207 inline auto format(
const Locale& loc,
const S& fmt, T&&... args)
208 -> std::basic_string<Char> {
209 return vformat(loc, detail::to_string_view(fmt),
210 fmtquill::make_format_args<buffered_context<Char>>(args...));
213 template <
typename OutputIt,
typename S,
214 typename Char = detail::format_string_char_t<S>,
216 detail::is_exotic_char<Char>::value)>
217 auto vformat_to(OutputIt out,
const S& fmt,
219 auto&& buf = detail::get_buffer<Char>(out);
220 detail::vformat_to(buf, detail::to_string_view(fmt), args);
221 return detail::get_iterator(buf, out);
224 template <
typename OutputIt,
typename S,
typename... T,
225 typename Char = detail::format_string_char_t<S>,
227 !std::is_same<Char, char>::value &&
228 !std::is_same<Char, wchar_t>::value)>
229 inline auto format_to(OutputIt out,
const S& fmt, T&&... args) -> OutputIt {
230 return vformat_to(out, detail::to_string_view(fmt),
231 fmtquill::make_format_args<buffered_context<Char>>(args...));
234 template <
typename Locale,
typename S,
typename OutputIt,
typename... Args,
235 typename Char = detail::format_string_char_t<S>,
238 detail::is_exotic_char<Char>::value)>
239 inline auto vformat_to(OutputIt out,
const Locale& loc,
const S& fmt,
242 auto&& buf = detail::get_buffer<Char>(out);
244 return detail::get_iterator(buf, out);
247 template <
typename Locale,
typename OutputIt,
typename S,
typename... T,
248 typename Char = detail::format_string_char_t<S>,
251 detail::is_exotic_char<Char>::value>
252 inline auto format_to(OutputIt out,
const Locale& loc,
const S& fmt,
254 typename std::enable_if<enable, OutputIt>::type {
255 return vformat_to(out, loc, detail::to_string_view(fmt),
256 fmtquill::make_format_args<buffered_context<Char>>(args...));
259 template <
typename OutputIt,
typename Char,
typename... Args,
261 detail::is_exotic_char<Char>::value)>
267 detail::vformat_to(buf, fmt, args);
268 return {buf.out(), buf.count()};
271 template <
typename OutputIt,
typename S,
typename... T,
272 typename Char = detail::format_string_char_t<S>,
274 detail::is_exotic_char<Char>::value)>
275 inline auto format_to_n(OutputIt out,
size_t n,
const S& fmt, T&&... args)
277 return vformat_to_n(out, n, fmtquill::basic_string_view<Char>(fmt),
278 fmtquill::make_format_args<buffered_context<Char>>(args...));
281 template <
typename S,
typename... T,
282 typename Char = detail::format_string_char_t<S>,
283 FMTQUILL_ENABLE_IF(detail::is_exotic_char<Char>::value)>
284 inline auto formatted_size(
const S& fmt, T&&... args) ->
size_t {
286 detail::vformat_to(buf, detail::to_string_view(fmt),
287 fmtquill::make_format_args<buffered_context<Char>>(args...));
293 detail::vformat_to(buf, fmt, args);
294 buf.push_back(L
'\0');
295 if (std::fputws(buf.data(), f) == -1)
296 FMTQUILL_THROW(system_error(errno, FMTQUILL_STRING(
"cannot write to file")));
300 vprint(stdout, fmt, args);
303 template <
typename... T>
304 void print(std::FILE* f, wformat_string<T...> fmt, T&&... args) {
305 return vprint(f,
wstring_view(fmt), fmtquill::make_wformat_args(args...));
308 template <
typename... T>
void print(wformat_string<T...> fmt, T&&... args) {
309 return vprint(
wstring_view(fmt), fmtquill::make_wformat_args(args...));
312 template <
typename... T>
313 void println(std::FILE* f, wformat_string<T...> fmt, T&&... args) {
314 return print(f, L
"{}\n", fmtquill::format(fmt, std::forward<T>(args)...));
317 template <
typename... T>
void println(wformat_string<T...> fmt, T&&... args) {
318 return print(L
"{}\n", fmtquill::format(fmt, std::forward<T>(args)...));
324 detail::vformat_to(buf, ts, fmt, args);
325 return {buf.data(), buf.size()};
328 template <
typename... T>
329 inline auto format(
text_style ts, wformat_string<T...> fmt, T&&... args)
331 return fmtquill::vformat(ts, fmt, fmtquill::make_wformat_args(args...));
334 template <
typename... T>
335 FMTQUILL_DEPRECATED
void print(std::FILE* f,
text_style ts, wformat_string<T...> fmt,
337 vprint(f, ts, fmt, fmtquill::make_wformat_args(args...));
340 template <
typename... T>
341 FMTQUILL_DEPRECATED
void print(
text_style ts, wformat_string<T...> fmt,
343 return print(stdout, ts, fmt, args...);
348 detail::vformat_to(buffer, fmt, args);
349 detail::write_buffer(os, buffer);
352 template <
typename... T>
353 void print(std::wostream& os, wformat_string<T...> fmt, T&&... args) {
354 vprint(os, fmt, fmtquill::make_format_args<buffered_context<wchar_t>>(args...));
357 template <
typename... T>
358 void println(std::wostream& os, wformat_string<T...> fmt, T&&... args) {
359 print(os, L
"{}\n", fmtquill::format(fmt, std::forward<T>(args)...));
363 template <
typename T>
inline auto to_wstring(
const T& value) -> std::wstring {
364 return format(FMTQUILL_STRING(L
"{}"), value);
367 FMTQUILL_END_NAMESPACE
369 #endif // FMTQUILL_XCHAR_H_
Definition: format.h:1986
Definition: format.h:3738
Parsing context consisting of a format string range being parsed and an argument counter for automati...
Definition: base.h:644
Definition: format.h:3670
Setups a signal handler to handle fatal signals.
Definition: BackendManager.h:24
An implementation of std::basic_string_view for pre-C++17.
Definition: base.h:523
A text style consisting of foreground and background colors and emphasis.
Definition: color.h:236
typename V::value_type char_t
String's character (code unit) type. detail:: is intentional to prevent ADL.
Definition: base.h:961
Definition: format.h:4006
Definition: format.h:3592