@@ -143,46 +143,6 @@ struct UrlStringEncoder : public StringEncoder<UrlStringEncoder>
143143 }
144144};
145145
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-
186146StringConverter::StringConverter (FilterParams params, StringConverter::Mode mode)
187147 : m_mode(mode)
188148{
@@ -207,13 +167,13 @@ InternalValue StringConverter::Filter(const InternalValue& baseVal, RenderContex
207167 switch (m_mode)
208168 {
209169 case TrimMode:
210- result = ApplyConverter (baseVal, [](auto str) {
170+ result = ApplyStringConverter (baseVal, [](auto str) -> InternalValue {
211171 ba::trim_all (str);
212172 return str;
213173 });
214174 break ;
215175 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 {
217177 if (isDelim && isAlpha (ch))
218178 {
219179 isDelim = false ;
@@ -228,7 +188,7 @@ InternalValue StringConverter::Filter(const InternalValue& baseVal, RenderContex
228188 case WordCountMode:
229189 {
230190 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 {
232192 if (isDelim && isAlNum (ch))
233193 {
234194 isDelim = false ;
@@ -241,23 +201,23 @@ InternalValue StringConverter::Filter(const InternalValue& baseVal, RenderContex
241201 break ;
242202 }
243203 case UpperMode:
244- result = ApplyConverter <GenericStringEncoder>(baseVal, [&isAlpha](auto ch, auto && fn) mutable {
204+ result = ApplyStringConverter <GenericStringEncoder>(baseVal, [&isAlpha](auto ch, auto && fn) mutable {
245205 if (isAlpha (ch))
246206 fn (std::toupper (ch, std::locale ()));
247207 else
248208 fn (ch);
249209 });
250210 break ;
251211 case LowerMode:
252- result = ApplyConverter <GenericStringEncoder>(baseVal, [&isAlpha](auto ch, auto && fn) mutable {
212+ result = ApplyStringConverter <GenericStringEncoder>(baseVal, [&isAlpha](auto ch, auto && fn) mutable {
253213 if (isAlpha (ch))
254214 fn (std::tolower (ch, std::locale ()));
255215 else
256216 fn (ch);
257217 });
258218 break ;
259219 case ReplaceMode:
260- result = ApplyConverter (baseVal, [this , &context](auto str) {
220+ result = ApplyStringConverter (baseVal, [this , &context](auto str) -> InternalValue {
261221 auto oldStr = GetAsSameString (str, this ->GetArgumentValue (" old" , context));
262222 auto newStr = GetAsSameString (str, this ->GetArgumentValue (" new" , context));
263223 auto count = ConvertToInt (this ->GetArgumentValue (" count" , context));
@@ -272,7 +232,7 @@ InternalValue StringConverter::Filter(const InternalValue& baseVal, RenderContex
272232 });
273233 break ;
274234 case TruncateMode:
275- result = ApplyConverter (baseVal, [this , &context, &isAlNum](auto str) {
235+ result = ApplyStringConverter (baseVal, [this , &context, &isAlNum](auto str) -> InternalValue {
276236 auto length = ConvertToInt (this ->GetArgumentValue (" length" , context));
277237 auto killWords = ConvertToBool (this ->GetArgumentValue (" killwords" , context));
278238 auto end = GetAsSameString (str, this ->GetArgumentValue (" end" , context));
0 commit comments