@@ -80,92 +80,73 @@ namespace sysstr
80
80
81
81
return std::ranges::equal (test.begin (), test.end (), access.begin (), access.begin () + test_size);
82
82
}
83
+ }
84
+
85
+ template <class Storage >
86
+ template <std::invocable<std::string_view> Func>
87
+ inline
88
+ auto sys_string_t <Storage>::print_with(Func func) const -> decltype (func(std::string_view{}))
89
+ {
90
+ if constexpr (std::ranges::contiguous_range<typename sys_string_t <Storage>::char_access> &&
91
+ std::is_same_v<typename sys_string_t <Storage>::storage_type, char >)
92
+ {
93
+ typename sysstr::sys_string_t <Storage>::char_access access (*this );
94
+ return func (std::string_view (access.data (), access.size ()));
95
+ }
96
+ else
97
+ {
98
+ std::string out;
99
+ typename sysstr::sys_string_t <Storage>::utf8_access (*this ).each ([&out](char c) {
100
+ out += c;
101
+ });
102
+ return func (std::string_view (out));
103
+ }
104
+ }
83
105
84
- template <class Storage , class Func >
106
+ #if SYS_STRING_WCHAR_T_IS_UTF16
107
+ template <class Storage >
108
+ template <std::invocable<std::wstring_view> Func>
85
109
inline
86
- decltype ( auto ) with_output_string( const sys_string_t <Storage> & val, Func func)
110
+ auto sys_string_t <Storage>::wprint_with(Func func) const -> decltype ( func(std::wstring_view{}) )
87
111
{
88
112
if constexpr (std::ranges::contiguous_range<typename sys_string_t <Storage>::char_access> &&
89
- std::is_same_v<typename sys_string_t <Storage>::storage_type, char >)
113
+ std::is_same_v<typename sys_string_t <Storage>::storage_type, char16_t >)
90
114
{
91
- typename sysstr::sys_string_t <Storage>::char_access access (val );
92
- return func (std::string_view ( access.data (), access.size ()));
115
+ typename sysstr::sys_string_t <Storage>::char_access access (* this );
116
+ return func (std::wstring_view (( const wchar_t *) access.data (), access.size ()));
93
117
}
94
118
else
95
119
{
96
- std::string out;
97
- typename sysstr::sys_string_t <Storage>::utf8_access (val ).each ([&out](char c) {
98
- out += c ;
120
+ std::wstring out;
121
+ typename sysstr::sys_string_t <Storage>::utf16_access (* this ).each ([&out](char16_t c) {
122
+ out += wchar_t (c) ;
99
123
});
100
- return func (std::string_view (out));
124
+ return func (std::wstring_view (out));
101
125
}
102
126
}
103
-
104
- #if SYS_STRING_WCHAR_T_IS_UTF16
105
- template <class Storage , class Func >
106
- inline
107
- decltype (auto ) with_output_wstring(const sys_string_t <Storage> & val, Func func)
127
+ #elif SYS_STRING_WCHAR_T_IS_UTF32
128
+ template <class Storage >
129
+ template <std::invocable<std::wstring_view> Func>
130
+ inline
131
+ auto sys_string_t <Storage>::wprint_with(Func func) const -> decltype (func(std::wstring_view{}))
132
+ {
133
+ if constexpr (std::ranges::contiguous_range<typename sys_string_t <Storage>::char_access> &&
134
+ std::is_same_v<typename sys_string_t <Storage>::storage_type, char32_t >)
108
135
{
109
- if constexpr (std::ranges::contiguous_range<typename sys_string_t <Storage>::char_access> &&
110
- std::is_same_v<typename sys_string_t <Storage>::storage_type, char16_t >)
111
- {
112
- typename sysstr::sys_string_t <Storage>::char_access access (val);
113
- return func (std::wstring_view ((const wchar_t *)access.data (), access.size ()));
114
- }
115
- else
116
- {
117
- std::wstring out;
118
- typename sysstr::sys_string_t <Storage>::utf16_access (val).each ([&out](char16_t c) {
119
- out += wchar_t (c);
120
- });
121
- return func (std::wstring_view (out));
122
- }
123
- }
124
- #elif SYS_STRING_WCHAR_T_IS_UTF32
125
- template <class Storage , class Func >
126
- inline
127
- decltype (auto ) with_output_wstring(const sys_string_t <Storage> & val, Func func)
136
+ typename sysstr::sys_string_t <Storage>::char_access access (*this );
137
+ return func (std::wstring_view ((const wchar_t *)access.data (), access.size ()));
138
+ }
139
+ else
128
140
{
129
- if constexpr (std::ranges::contiguous_range<typename sys_string_t <Storage>::char_access> &&
130
- std::is_same_v<typename sys_string_t <Storage>::storage_type, char32_t >)
131
- {
132
- typename sysstr::sys_string_t <Storage>::char_access access (val);
133
- return func (std::wstring_view ((const wchar_t *)access.data (), access.size ()));
134
- }
135
- else
136
- {
137
- std::wstring out;
138
- typename sysstr::sys_string_t <Storage>::utf32_access (val).each ([&out](char32_t c) {
139
- out += wchar_t (c);
140
- });
141
- return func (std::wstring_view (out));
142
- }
141
+ std::wstring out;
142
+ typename sysstr::sys_string_t <Storage>::utf32_access (*this ).each ([&out](char32_t c) {
143
+ out += wchar_t (c);
144
+ });
145
+ return func (std::wstring_view (out));
143
146
}
144
- #endif
145
- }
146
-
147
-
148
- template <class Storage >
149
- inline
150
- auto operator <<(std::ostream & str, const sys_string_t <Storage> & val) -> std::ostream &
151
- {
152
- return util::with_output_string (val, [&](auto view) -> std::ostream & {
153
- return str << view;
154
- });
155
- }
156
-
157
- #if SYS_STRING_WCHAR_T_IS_UTF16 || SYS_STRING_WCHAR_T_IS_UTF32
158
-
159
- template <class Storage >
160
- inline
161
- auto operator <<(std::wostream & str, const sys_string_t <Storage> & val) -> std::wostream &
162
- {
163
- return util::with_output_wstring (val, [&](auto view) -> std::wostream & {
164
- return str << view;
165
- });
166
- }
147
+ }
148
+ #endif
167
149
168
- #endif
169
150
}
170
151
171
152
#if SYS_STRING_SUPPORTS_STD_FORMAT
@@ -180,7 +161,7 @@ template<class Storage> struct std::formatter<sysstr::sys_string_t<Storage>> : p
180
161
template <typename FormatContext>
181
162
auto format (const sysstr::sys_string_t <Storage> & str, FormatContext & ctx) const -> decltype(ctx.out())
182
163
{
183
- return sysstr::util::with_output_string ( str, [&](auto view) {
164
+ return str. print_with ( [&](auto view) -> decltype (ctx. out () ) {
184
165
return super::format (view, ctx);
185
166
});
186
167
}
@@ -198,7 +179,7 @@ template<class Storage> struct std::formatter<sysstr::sys_string_t<Storage>, wch
198
179
template <typename FormatContext>
199
180
auto format (const sysstr::sys_string_t <Storage> & str, FormatContext & ctx) const -> decltype(ctx.out())
200
181
{
201
- return sysstr::util::with_output_wstring ( str, [&](auto view) {
182
+ return str. wprint_with ( [&](auto view) -> decltype (ctx. out () ) {
202
183
return super::format (view, ctx);
203
184
});
204
185
}
0 commit comments