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());
59 template <
typename Char>
63 static_assert(!std::is_same<Char, char>::value,
"");
74 using wformat_context = buffered_context<wchar_t>;
82 static constexpr
int num_static_named_args =
83 detail::count_static_named_args<T...>();
86 Char,
static_cast<int>(
sizeof...(T)), num_static_named_args,
87 num_static_named_args != detail::count_named_args<T...>()>;
97 FMTQUILL_CONSTEVAL FMTQUILL_ALWAYS_INLINE
basic_fstring(
const S& s) : str_(s) {
98 if (FMTQUILL_USE_CONSTEVAL)
101 template <
typename S,
102 FMTQUILL_ENABLE_IF(std::is_base_of<detail::compile_string, S>::value&&
103 std::is_same<typename S::char_type, Char>::value)>
104 FMTQUILL_ALWAYS_INLINE basic_fstring(
const S&) : str_(S()) {
106 FMTQUILL_CONSTEXPR
int ignore =
108 detail::ignore_unused(ignore);
116 template <
typename Char,
typename... T>
119 template <
typename... T>
125 template <
typename... T>
126 constexpr
auto make_wformat_args(T&... args)
127 -> decltype(fmtquill::make_format_args<wformat_context>(args...)) {
128 return fmtquill::make_format_args<wformat_context>(args...);
131 #if !FMTQUILL_USE_NONTYPE_TEMPLATE_ARGS 139 template <
typename It,
typename Sentinel>
140 auto join(It begin, Sentinel end, wstring_view sep)
142 return {begin, end, sep};
145 template <typename Range, FMTQUILL_ENABLE_IF(!is_tuple_like<Range>::value)>
146 auto join(Range&& range, wstring_view sep)
147 ->
join_view<decltype(std::begin(range)), decltype(std::end(range)),
149 return join(std::begin(range), std::end(range), sep);
152 template <
typename T>
153 auto join(std::initializer_list<T> list, wstring_view sep)
155 return join(std::begin(list), std::end(list), sep);
158 template <typename Tuple, FMTQUILL_ENABLE_IF(is_tuple_like<Tuple>::value)>
164 template <typename Char, FMTQUILL_ENABLE_IF(!std::is_same<Char, char>::value)>
167 -> std::basic_string<Char> {
169 detail::vformat_to(buf, fmt, args);
170 return {buf.data(), buf.size()};
173 template <
typename... T>
174 auto format(wformat_string<T...> fmt, T&&... args) -> std::wstring {
175 return vformat(fmtquill::wstring_view(fmt), fmtquill::make_wformat_args(args...));
178 template <
typename OutputIt,
typename... T>
179 auto format_to(OutputIt out, wformat_string<T...> fmt, T&&... args)
181 return vformat_to(out, fmtquill::wstring_view(fmt),
182 fmtquill::make_wformat_args(args...));
187 template <
typename S,
typename... T,
188 typename Char = detail::format_string_char_t<S>,
189 FMTQUILL_ENABLE_IF(!std::is_same<Char, char>::value &&
190 !std::is_same<Char, wchar_t>::value)>
191 auto format(
const S& fmt, T&&... args) -> std::basic_string<Char> {
192 return vformat(detail::to_string_view(fmt),
193 fmtquill::make_format_args<buffered_context<Char>>(args...));
196 template <
typename S,
typename Char = detail::format_
string_
char_t<S>,
197 FMTQUILL_ENABLE_IF(detail::is_exotic_
char<Char>::value)>
198 inline auto vformat(
locale_ref loc,
const S& fmt,
200 -> std::basic_string<Char> {
202 detail::vformat_to(buf, detail::to_string_view(fmt), args, loc);
203 return {buf.data(), buf.size()};
206 template <
typename S,
typename... T,
207 typename Char = detail::format_string_char_t<S>,
208 FMTQUILL_ENABLE_IF(detail::is_exotic_char<Char>::value)>
209 inline auto format(
locale_ref loc,
const S& fmt, T&&... args)
210 -> std::basic_string<Char> {
211 return vformat(loc, detail::to_string_view(fmt),
212 fmtquill::make_format_args<buffered_context<Char>>(args...));
215 template <
typename OutputIt,
typename S,
216 typename Char = detail::format_string_char_t<S>,
218 detail::is_exotic_char<Char>::value)>
219 auto vformat_to(OutputIt out,
const S& fmt,
221 auto&& buf = detail::get_buffer<Char>(out);
222 detail::vformat_to(buf, detail::to_string_view(fmt), args);
223 return detail::get_iterator(buf, out);
226 template <
typename OutputIt,
typename S,
typename... T,
227 typename Char = detail::format_string_char_t<S>,
229 !std::is_same<Char, char>::value &&
230 !std::is_same<Char, wchar_t>::value)>
231 inline auto format_to(OutputIt out,
const S& fmt, T&&... args) -> OutputIt {
232 return vformat_to(out, detail::to_string_view(fmt),
233 fmtquill::make_format_args<buffered_context<Char>>(args...));
236 template <
typename S,
typename OutputIt,
typename... Args,
237 typename Char = detail::format_string_char_t<S>,
239 detail::is_exotic_char<Char>::value)>
240 inline auto vformat_to(OutputIt out,
locale_ref loc,
const S& fmt,
243 auto&& buf = detail::get_buffer<Char>(out);
244 vformat_to(buf, detail::to_string_view(fmt), args, loc);
245 return detail::get_iterator(buf, out);
248 template <
typename OutputIt,
typename S,
typename... T,
249 typename Char = detail::format_string_char_t<S>,
251 detail::is_exotic_char<Char>::value>
252 inline auto format_to(OutputIt out,
locale_ref loc,
const S& fmt, T&&... args)
253 ->
typename std::enable_if<enable, OutputIt>::type {
254 return vformat_to(out, loc, detail::to_string_view(fmt),
255 fmtquill::make_format_args<buffered_context<Char>>(args...));
258 template <
typename OutputIt,
typename Char,
typename... Args,
260 detail::is_exotic_char<Char>::value)>
266 detail::vformat_to(buf, fmt, args);
267 return {buf.out(), buf.count()};
270 template <
typename OutputIt,
typename S,
typename... T,
271 typename Char = detail::format_string_char_t<S>,
273 detail::is_exotic_char<Char>::value)>
274 inline auto format_to_n(OutputIt out,
size_t n,
const S& fmt, T&&... args)
276 return vformat_to_n(out, n, fmtquill::basic_string_view<Char>(fmt),
277 fmtquill::make_format_args<buffered_context<Char>>(args...));
280 template <
typename S,
typename... T,
281 typename Char = detail::format_string_char_t<S>,
282 FMTQUILL_ENABLE_IF(detail::is_exotic_char<Char>::value)>
283 inline auto formatted_size(
const S& fmt, T&&... args) ->
size_t {
285 detail::vformat_to(buf, detail::to_string_view(fmt),
286 fmtquill::make_format_args<buffered_context<Char>>(args...));
290 inline void vprint(std::FILE* f, wstring_view fmt,
wformat_args args) {
292 detail::vformat_to(buf, fmt, args);
293 buf.push_back(L
'\0');
294 if (std::fputws(buf.data(), f) == -1)
295 FMTQUILL_THROW(system_error(errno, FMTQUILL_STRING(
"cannot write to file")));
298 inline void vprint(wstring_view fmt,
wformat_args args) {
299 vprint(stdout, fmt, args);
302 template <
typename... T>
303 void print(std::FILE* f, wformat_string<T...> fmt, T&&... args) {
304 return vprint(f, wstring_view(fmt), fmtquill::make_wformat_args(args...));
307 template <
typename... T>
void print(wformat_string<T...> fmt, T&&... args) {
308 return vprint(wstring_view(fmt), fmtquill::make_wformat_args(args...));
311 template <
typename... T>
312 void println(std::FILE* f, wformat_string<T...> fmt, T&&... args) {
313 return print(f, L
"{}\n", fmtquill::format(fmt, std::forward<T>(args)...));
316 template <
typename... T>
void println(wformat_string<T...> fmt, T&&... args) {
317 return print(L
"{}\n", fmtquill::format(fmt, std::forward<T>(args)...));
323 detail::vformat_to(buf, ts, fmt, args);
324 return {buf.data(), buf.size()};
327 template <
typename... T>
328 inline auto format(
text_style ts, wformat_string<T...> fmt, T&&... args)
330 return fmtquill::vformat(ts, fmt, fmtquill::make_wformat_args(args...));
333 inline void vprint(std::wostream& os, wstring_view fmt,
wformat_args args) {
335 detail::vformat_to(buffer, fmt, args);
336 detail::write_buffer(os, buffer);
339 template <
typename... T>
340 void print(std::wostream& os, wformat_string<T...> fmt, T&&... args) {
341 vprint(os, fmt, fmtquill::make_format_args<buffered_context<wchar_t>>(args...));
344 template <
typename... T>
345 void println(std::wostream& os, wformat_string<T...> fmt, T&&... args) {
346 print(os, L
"{}\n", fmtquill::format(fmt, std::forward<T>(args)...));
350 template <
typename T>
inline auto to_wstring(
const T& value) -> std::wstring {
351 return format(FMTQUILL_STRING(L
"{}"), value);
354 FMTQUILL_END_NAMESPACE
356 #endif // FMTQUILL_XCHAR_H_
Definition: format.h:2031
Definition: format.h:3886
Parsing context consisting of a format string range being parsed and an argument counter for automati...
Definition: base.h:634
Definition: UserDefinedDirectFormatFuzzer.cpp:81
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:526
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:987
Definition: format.h:4155
Definition: format.h:3763