@@ -23,41 +23,45 @@ namespace cucumber_cpp::library::cucumber_expression
2323 template <class T >
2424 std::function<T(const cucumber::messages::group&)> CreateStreamConverter ()
2525 {
26- return [](const cucumber::messages::group& matches)
26+ return [](const cucumber::messages::group& matches) -> T
2727 {
28- return StringTo<T>(matches.value .value ());
28+ if (matches.value .has_value ())
29+ return StringTo<T>(matches.value .value ());
30+ return {};
2931 };
3032 };
31- }
3233
33- std::function<std::string(const cucumber::messages::group&)> CreateStringConverter ()
34- {
35- return [](const cucumber::messages::group& matches)
34+ std::function<std::string(const cucumber::messages::group&)> CreateStringConverter ()
3635 {
37- std::string str = matches.children .front ().value .has_value ()
38- ? matches.children .front ().value .value ()
39- : matches.children .back ().value .value ();
36+ return [](const cucumber::messages::group& matches)
37+ {
38+ std::string str = matches.children .front ().value .has_value ()
39+ ? matches.children .front ().value .value ()
40+ : matches.children .back ().value .value ();
4041
41- str = std::regex_replace (str, std::regex (R"__( \\")__" ), " \" " );
42- str = std::regex_replace (str, std::regex (R"__( \\')__" ), " '" );
42+ str = std::regex_replace (str, std::regex (R"__( \\")__" ), " \" " );
43+ str = std::regex_replace (str, std::regex (R"__( \\')__" ), " '" );
4344
44- return str;
45- };
45+ return str;
46+ };
47+ }
4648 }
4749
4850 ParameterRegistry::ParameterRegistry ()
4951 {
5052 const static std::string integerNegativeRegex{ R"__( -?\d+)__" };
5153 const static std::string integerPositiveRegex{ R"__( \d+)__" };
5254 const static std::string floatRegex{ R"__( (?=.*\d.*)[-+]?\d*(?:\.(?=\d.*))?\d*(?:\d+[E][+-]?\d+)?)__" };
53- const static std::string stringDoubleRegex{ R"__( "([^\"\\]*(\\.[^\"\\]*)*)")__" };
54- const static std::string stringSingleRegex{ R"__( '([^'\\]*(\\.[^'\\]*)*)')__" };
55+ // const static std::string stringDoubleRegex{ R"__("([^\"\\]*(\\.[^\"\\]*)*)")__" };
56+ // const static std::string stringSingleRegex{ R"__('([^'\\]*(\\.[^'\\]*)*)')__" };
57+ const static std::string stringRegex{ R"__( "([^"\\]*(?:\\.[^"\\]*)*)"|'([^'\\]*(?:\\.[^'\\]*)*)')__" };
5558 const static std::string wordRegex{ R"__( [^\s]+)__" };
5659
5760 AddBuiltinParameter (" int" , { integerNegativeRegex, integerPositiveRegex }, CreateStreamConverter<std::int32_t >());
5861 AddBuiltinParameter (" float" , { floatRegex }, CreateStreamConverter<float >());
5962 AddBuiltinParameter (" word" , { wordRegex }, CreateStreamConverter<std::string>());
60- AddBuiltinParameter (" string" , { stringDoubleRegex, stringSingleRegex }, CreateStringConverter ());
63+ // AddBuiltinParameter("string", { stringDoubleRegex, stringSingleRegex }, CreateStringConverter());
64+ AddBuiltinParameter (" string" , { stringRegex }, CreateStringConverter ());
6165 AddBuiltinParameter (" " , { " .*" }, CreateStreamConverter<std::string>());
6266 AddBuiltinParameter (" bigdecimal" , { floatRegex }, CreateStreamConverter<double >());
6367 AddBuiltinParameter (" biginteger" , { { integerNegativeRegex, integerPositiveRegex } }, CreateStreamConverter<std::int64_t >());
0 commit comments