qxLib
format.h
Go to the documentation of this file.
1 /**
2 
3  @file format.h
4  @author Khrapov
5  @date 27.03.2026
6  @copyright © Nick Khrapov, 2026. All right reserved.
7 
8 **/
9 #pragma once
10 
12 
13 namespace qx
14 {
15 
16 /**
17  @brief std::format / fmt::format wrapper that returns qx::string
18  @tparam args_t - format arguments types
19  @param sFormat - format string
20  @param args - template parameter pack
21  @retval - formatted string
22 **/
23 template<class... args_t>
24  requires format_acceptable_args_c<char, args_t...>
25 cstring format(const QX_FMT_NS::format_string<std::type_identity_t<args_t>...> sFormat, args_t&&... args) noexcept
26 {
27  // doesn't work for fmt for some reason
28 #if QX_CONF_FMT_LIB == QX_FMT_LIB_STD
29  return cstring::static_format(sFormat, std::forward<args_t>(args)...);
30 #else
32  cstring_view(sFormat.get().data(), sFormat.get().size()),
33  std::forward<args_t>(args)...);
34 
35 #endif
36 }
37 
38 /**
39  @brief std::format / fmt::format wrapper that returns qx::wstring
40  @tparam args_t - format arguments types
41  @param sFormat - format string
42  @param args - template parameter pack
43  @retval - formatted string
44 **/
45 template<class... args_t>
46  requires format_acceptable_args_c<wchar_t, args_t...>
47 wstring format(const QX_FMT_NS::wformat_string<std::type_identity_t<args_t>...> sFormat, args_t&&... args) noexcept
48 {
49  return wstring::static_format(sFormat, std::forward<args_t>(args)...);
50 }
51 
52 /**
53  @brief Converts any type that has a std::formatter overload to qx::basic_string
54  @tparam T - object type
55  @tparam char_t - char type (char, wchar_t, etc)
56  @tparam traits_t - char traits. \see string_traits.h
57  @param value - object to convert
58  @retval - qx::basic_string
59 **/
60 template<class T, class char_t = char_type, class traits_t = string_traits::traits<char_t>>
62 {
64 }
65 
66 } // namespace qx
String class.
Definition: string.h:83
requires static format_acceptable_args_c< char_t, args_t... > basic_string static_format(const format_string_type< std::type_identity_t< args_t >... > sFormat, args_t &&... args) noexcept
Create a string by formatting it with the format string and the args.
requires static format_acceptable_args_c< char_t, args_t... > basic_string static_vformat(string_view svFormat, args_t &&... args)
Create a string by formatting it with the format string and the args.
requires(same_variadic_args_v< args_t... >) const expr auto coalesce(args_t &&... args)
Coalesce function, C# a ?? b analogue.
Definition: coalesce.inl:57
requires format_acceptable_args_c< char, args_t... > cstring format(const QX_FMT_NS::format_string< std::type_identity_t< args_t >... > sFormat, args_t &&... args) noexcept
std::format / fmt::format wrapper that returns qx::string
Definition: format.h:25
basic_string< char_t, traits_t > convert_to_string(const T &value) noexcept
Converts any type that has a std::formatter overload to qx::basic_string.
Definition: format.h:61
#define QX_STR_PREFIX(value_t, str)
Chose witch of prefixes add to string : L or none.
Definition: string_utils.h:247