@@ -143,46 +143,6 @@ struct UrlStringEncoder : public StringEncoder<UrlStringEncoder>
143
143
}
144
144
};
145
145
146
- template <typename Fn>
147
- struct StringConverterImpl : public visitors ::BaseVisitor<>
148
- {
149
- using BaseVisitor::operator ();
150
-
151
- StringConverterImpl (const Fn& fn) : m_fn(fn) {}
152
-
153
- template <typename CharT>
154
- InternalValue operator ()(const std::basic_string<CharT>& str) const
155
- {
156
- return m_fn (str);
157
- }
158
-
159
- const Fn& m_fn;
160
- };
161
-
162
- template <typename CharT>
163
- struct SameStringGetter : public visitors ::BaseVisitor<std::basic_string<CharT>>
164
- {
165
- using ResultString = std::basic_string<CharT>;
166
- using visitors::BaseVisitor<ResultString>::operator ();
167
-
168
- ResultString operator ()(const ResultString& str) const
169
- {
170
- return str;
171
- }
172
- };
173
-
174
- template <template <typename > class Cvt = StringConverterImpl, typename Fn>
175
- auto ApplyConverter (const InternalValue& str, Fn&& fn)
176
- {
177
- return Apply<Cvt<Fn>>(str, std::forward<Fn>(fn));
178
- }
179
-
180
- template <typename CharT>
181
- auto GetAsSameString (const std::basic_string<CharT>& s, const InternalValue& val)
182
- {
183
- return Apply<SameStringGetter<CharT>>(val);
184
- }
185
-
186
146
StringConverter::StringConverter (FilterParams params, StringConverter::Mode mode)
187
147
: m_mode(mode)
188
148
{
@@ -207,13 +167,13 @@ InternalValue StringConverter::Filter(const InternalValue& baseVal, RenderContex
207
167
switch (m_mode)
208
168
{
209
169
case TrimMode:
210
- result = ApplyConverter (baseVal, [](auto str) {
170
+ result = ApplyStringConverter (baseVal, [](auto str) -> InternalValue {
211
171
ba::trim_all (str);
212
172
return str;
213
173
});
214
174
break ;
215
175
case TitleMode:
216
- result = ApplyConverter <GenericStringEncoder>(baseVal, [isDelim = true , &isAlpha, &isAlNum](auto ch, auto && fn) mutable {
176
+ result = ApplyStringConverter <GenericStringEncoder>(baseVal, [isDelim = true , &isAlpha, &isAlNum](auto ch, auto && fn) mutable {
217
177
if (isDelim && isAlpha (ch))
218
178
{
219
179
isDelim = false ;
@@ -228,7 +188,7 @@ InternalValue StringConverter::Filter(const InternalValue& baseVal, RenderContex
228
188
case WordCountMode:
229
189
{
230
190
int64_t wc = 0 ;
231
- ApplyConverter <GenericStringEncoder>(baseVal, [isDelim = true , &wc, &isAlpha, &isAlNum](auto ch, auto && fn) mutable {
191
+ ApplyStringConverter <GenericStringEncoder>(baseVal, [isDelim = true , &wc, &isAlpha, &isAlNum](auto ch, auto && fn) mutable {
232
192
if (isDelim && isAlNum (ch))
233
193
{
234
194
isDelim = false ;
@@ -241,23 +201,23 @@ InternalValue StringConverter::Filter(const InternalValue& baseVal, RenderContex
241
201
break ;
242
202
}
243
203
case UpperMode:
244
- result = ApplyConverter <GenericStringEncoder>(baseVal, [&isAlpha](auto ch, auto && fn) mutable {
204
+ result = ApplyStringConverter <GenericStringEncoder>(baseVal, [&isAlpha](auto ch, auto && fn) mutable {
245
205
if (isAlpha (ch))
246
206
fn (std::toupper (ch, std::locale ()));
247
207
else
248
208
fn (ch);
249
209
});
250
210
break ;
251
211
case LowerMode:
252
- result = ApplyConverter <GenericStringEncoder>(baseVal, [&isAlpha](auto ch, auto && fn) mutable {
212
+ result = ApplyStringConverter <GenericStringEncoder>(baseVal, [&isAlpha](auto ch, auto && fn) mutable {
253
213
if (isAlpha (ch))
254
214
fn (std::tolower (ch, std::locale ()));
255
215
else
256
216
fn (ch);
257
217
});
258
218
break ;
259
219
case ReplaceMode:
260
- result = ApplyConverter (baseVal, [this , &context](auto str) {
220
+ result = ApplyStringConverter (baseVal, [this , &context](auto str) -> InternalValue {
261
221
auto oldStr = GetAsSameString (str, this ->GetArgumentValue (" old" , context));
262
222
auto newStr = GetAsSameString (str, this ->GetArgumentValue (" new" , context));
263
223
auto count = ConvertToInt (this ->GetArgumentValue (" count" , context));
@@ -272,7 +232,7 @@ InternalValue StringConverter::Filter(const InternalValue& baseVal, RenderContex
272
232
});
273
233
break ;
274
234
case TruncateMode:
275
- result = ApplyConverter (baseVal, [this , &context, &isAlNum](auto str) {
235
+ result = ApplyStringConverter (baseVal, [this , &context, &isAlNum](auto str) -> InternalValue {
276
236
auto length = ConvertToInt (this ->GetArgumentValue (" length" , context));
277
237
auto killWords = ConvertToBool (this ->GetArgumentValue (" killwords" , context));
278
238
auto end = GetAsSameString (str, this ->GetArgumentValue (" end" , context));
0 commit comments