Stroika Library 3.0d18
 
Loading...
Searching...
No Matches
Characters/Format.inl
1/*
2 * Copyright(c) Sophist Solutions, Inc. 1990-2025. All rights reserved
3 */
4
6
7 /*
8 ********************************************************************************
9 ***************************** FormatString<CHAR_T> *****************************
10 ********************************************************************************
11 */
12 template </*Common::IAnyOf< char, wchar_t>*/ typename CHAR_T>
13 constexpr FormatString<CHAR_T>::FormatString (const basic_string_view<CHAR_T>& s)
14 : fSV_{s}
15 {
16 }
17 template </*Common::IAnyOf< char, wchar_t>*/ typename CHAR_T>
18 constexpr wstring_view FormatString<CHAR_T>::get () const
19 {
20 return fSV_;
21 }
22 template </*Common::IAnyOf< char, wchar_t>*/ typename CHAR_T>
23 constexpr qStroika_Foundation_Characters_FMT_PREFIX_::wstring_view FormatString<CHAR_T>::getx_ () const
24 {
25 return qStroika_Foundation_Characters_FMT_PREFIX_::wstring_view{fSV_.data (), fSV_.size ()};
26 }
27 template </*Common::IAnyOf< char, wchar_t>*/ typename CHAR_T>
28 template <Common::StdCompat::formattable<wchar_t>... ARGS>
29 [[nodiscard]] inline String FormatString<CHAR_T>::operator() (ARGS&&... args) const
30 {
31 return Common::StdCompat::vformat (getx_ (), Common::StdCompat::make_wformat_args (args...));
32 }
33 template </*Common::IAnyOf< char, wchar_t>*/ typename CHAR_T>
34 template <Common::StdCompat::formattable<wchar_t>... ARGS>
35 [[nodiscard]] inline String FormatString<CHAR_T>::operator() (const locale& loc, ARGS&&... args) const
36 {
37 return Common::StdCompat::vformat (loc, getx_ (), Common::StdCompat::make_wformat_args (args...));
38 }
39#if qCompilerAndStdLib_vector_constexpr_warning_Buggy
40 DISABLE_COMPILER_GCC_WARNING_START ("GCC diagnostic ignored \"-Winvalid-constexpr\"");
41#endif
42#if qCompilerAndStdLib_vector_constexpr_Buggy
43 inline
44#else
45 constexpr
46#endif
47 FormatString<char>::FormatString (const FormatString& src)
48 : fStringData_{src.fStringData_}
49 , fFmtStr_{basic_string_view<wchar_t>{fStringData_.data (), fStringData_.size ()}}
50 {
51 }
52#if qCompilerAndStdLib_vector_constexpr_Buggy
53 inline
54#else
55 constexpr
56#endif
57 FormatString<char>::FormatString (const basic_string_view<char>& s)
58 : fStringData_{s.begin (), s.end ()}
59 , fFmtStr_{basic_string_view<wchar_t>{fStringData_.data (), fStringData_.size ()}}
60 {
61 Character::CheckASCII (span{s});
62 }
63 constexpr wstring_view FormatString<char>::get () const
64 {
65 return fFmtStr_.get ();
66 }
67 constexpr qStroika_Foundation_Characters_FMT_PREFIX_::wstring_view FormatString<char>::getx_ () const
68 {
69 return fFmtStr_.getx_ ();
70 }
71 template <Stroika_Foundation_Common_formattable_FilterOnStringLitOp_BWA (Common::StdCompat::formattable<wchar_t>)... ARGS>
72 [[nodiscard]] inline String FormatString<char>::operator() (ARGS&&... args) const
73 {
74 return Common::StdCompat::vformat (this->getx_ (), Common::StdCompat::make_wformat_args (args...));
75 }
76 template <Stroika_Foundation_Common_formattable_FilterOnStringLitOp_BWA (Common::StdCompat::formattable<wchar_t>)... ARGS>
77 [[nodiscard]] inline String FormatString<char>::operator() (const locale& loc, ARGS&&... args) const
78 {
79 return Common::StdCompat::vformat (loc, this->getx_ (), Common::StdCompat::make_wformat_args (args...));
80 }
81
82 /*
83 ********************************************************************************
84 ************************* Characters::Literals *********************************
85 ********************************************************************************
86 */
87 inline namespace Literals {
88#if qCompilerAndStdLib_vector_constexpr_Buggy
89 inline
90#else
91 constexpr
92#endif
94 operator""_f (const char* str, size_t len)
95 {
96 return FormatString<char>{string_view{str, len}};
97 }
98 constexpr FormatString<wchar_t> operator""_f (const wchar_t* str, size_t len)
99 {
100 return FormatString<wchar_t>{wstring_view{str, len}};
101 }
102 }
103#if qCompilerAndStdLib_vector_constexpr_warning_Buggy
104 DISABLE_COMPILER_GCC_WARNING_END ("GCC diagnostic ignored \"-Winvalid-constexpr\"");
105#endif
106
107 /*
108 ********************************************************************************
109 *********************************** VFormat ************************************
110 ********************************************************************************
111 */
112 template <typename CHAR_T>
113 [[nodiscard]] inline String VFormat (const FormatString<CHAR_T>& f, const Common::StdCompat::wformat_args& args)
114 {
115 return Common::StdCompat::vformat (f.getx_ (), args);
116 }
117 template <typename CHAR_T>
118 [[nodiscard]] inline String VFormat (const locale& loc, const FormatString<CHAR_T>& f, const Common::StdCompat::wformat_args& args)
119 {
120 return Common::StdCompat::vformat (loc, f.getx_ (), args);
121 }
122
123 /*
124 ********************************************************************************
125 ************************************ Format ************************************
126 ********************************************************************************
127 */
128 template <typename CHAR_T, Common::StdCompat::formattable<wchar_t>... ARGS>
129 inline String Format (const FormatString<CHAR_T>& f, ARGS&&... args)
130 {
131 return VFormat (f, Common::StdCompat::make_wformat_args (args...));
132 }
133 template <typename CHAR_T, Common::StdCompat::formattable<wchar_t>... ARGS>
134 inline String Format (const locale& loc, const FormatString<CHAR_T>& f, ARGS&&... args)
135 {
136 return VFormat (loc, f, Common::StdCompat::make_wformat_args (args...));
137 }
138
139}
static constexpr void CheckASCII(span< const CHAR_T > s)
if not IsASCII (arg) throw RuntimeException...
String is like std::u32string, except it is much easier to use, often much more space efficient,...
Definition String.h:201
String VFormat(const FormatString< CHAR_T > &f, const Common::StdCompat::wformat_args &args)
same as std::vformat, except always uses wformat_args, and produces Stroika String (and maybe more - ...
Roughly equivalent to std::wformat_string, except that it can be constructed from 'char' string,...
constexpr qStroika_Foundation_Characters_FMT_PREFIX_::wstring_view getx_() const