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)
26 {
28  cstring_view(sFormat.get().data(), sFormat.get().size()),
29  std::forward<args_t>(args)...);
30 }
31 
32 /**
33  @brief std::format / fmt::format wrapper that returns qx::wstring
34  @tparam args_t - format arguments types
35  @param sFormat - format string
36  @param args - template parameter pack
37  @retval - formatted string
38 **/
39 template<class... args_t>
40  requires format_acceptable_args_c<wchar_t, args_t...>
41 wstring format(const QX_FMT_NS::wformat_string<std::type_identity_t<args_t>...> sFormat, args_t&&... args)
42 {
44  wstring_view(sFormat.get().data(), sFormat.get().size()),
45  std::forward<args_t>(args)...);
46 }
47 
48 /**
49  @brief Converts any type that has a std::formatter overload to qx::basic_string
50  @tparam T - object type
51  @tparam char_t - char type (char, wchar_t, etc)
52  @tparam traits_t - char traits. \see string_traits.h
53  @param value - object to convert
54  @retval - qx::basic_string
55 **/
56 template<class T, class char_t = char_type, class traits_t = string_traits::traits<char_t>>
58 {
60 }
61 
62 } // namespace qx
String class.
Definition: string.h:77
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 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)
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)
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)
Converts any type that has a std::formatter overload to qx::basic_string.
Definition: format.h:57
#define QX_STR_PREFIX(value_t, str)
Chose witch of prefixes add to string : L or none.
Definition: string_utils.h:247