@@ -2618,14 +2618,18 @@ inline std::shared_ptr<Context> Context::builtins() {
26182618 auto & text = args.at (" text" );
26192619 return text.is_null () ? text : Value (strip (text.get <std::string>()));
26202620 }));
2621- globals.set (" lower" , simple_function (" lower" , { " text" }, [](const std::shared_ptr<Context> &, Value & args) {
2622- auto text = args.at (" text" );
2623- if (text.is_null ()) return text;
2624- std::string res;
2625- auto str = text.get <std::string>();
2626- std::transform (str.begin (), str.end (), std::back_inserter (res), ::tolower);
2627- return Value (res);
2628- }));
2621+ auto char_transform_function = [](const std::string & name, const std::function<char (char )> & fn) {
2622+ return simple_function (name, { " text" }, [=](const std::shared_ptr<Context> &, Value & args) {
2623+ auto text = args.at (" text" );
2624+ if (text.is_null ()) return text;
2625+ std::string res;
2626+ auto str = text.get <std::string>();
2627+ std::transform (str.begin (), str.end (), std::back_inserter (res), fn);
2628+ return Value (res);
2629+ });
2630+ };
2631+ globals.set (" lower" , char_transform_function (" lower" , ::tolower));
2632+ globals.set (" upper" , char_transform_function (" upper" , ::toupper));
26292633 globals.set (" default" , Value::callable ([=](const std::shared_ptr<Context> &, ArgumentsValue & args) {
26302634 args.expectArgs (" default" , {2 , 3 }, {0 , 1 });
26312635 auto & value = args.args [0 ];
0 commit comments