@@ -100,15 +100,15 @@ namespace cucumber_cpp::library::cucumber_expression
100100
101101 std::string Expression::RewriteOptional (const Node& node)
102102 {
103- std::string partialRegex{ CreateString (node) };
103+ std::string partialRegex{ CreateEmptyRegexString (node) };
104104
105- if (GetPossibleNodeWithParameters (node))
105+ if (ContainsNodeWithParameters (node))
106106 throw ParameterIsNotAllowedInOptional (node, expression);
107107
108- if (GetPossibleNodeWithOptionals (node))
108+ if (ContainsNodeWithOptionals (node))
109109 throw OptionalIsNotAllowedInOptional (node, expression);
110110
111- if (AreNodesEmpty (node))
111+ if (NodesAreEmpty (node))
112112 throw OptionalMayNotBeEmpty (node, expression);
113113
114114 for (const auto & child : node.Children ())
@@ -124,11 +124,11 @@ namespace cucumber_cpp::library::cucumber_expression
124124 if (child.Children ().empty ())
125125 throw AlternativeMayNotBeEmpty (node, expression);
126126
127- if (AreNodesEmpty (child))
127+ if (NodesAreEmpty (child))
128128 throw AlternativeMayNotExclusivelyContainOptionals (node, expression);
129129 }
130130
131- std::string partialRegex{ CreateString (node) };
131+ std::string partialRegex{ CreateEmptyRegexString (node) };
132132 partialRegex += RewriteToRegex (node.Children ().front ());
133133 for (const auto & child : node.Children () | std::views::drop (1 ))
134134 partialRegex += ' |' + RewriteToRegex (child);
@@ -138,7 +138,7 @@ namespace cucumber_cpp::library::cucumber_expression
138138
139139 std::string Expression::RewriteAlternative (const Node& node)
140140 {
141- std::string partialRegex{ CreateString (node) };
141+ std::string partialRegex{ CreateEmptyRegexString (node) };
142142
143143 for (const auto & child : node.Children ())
144144 partialRegex += RewriteToRegex (child);
@@ -171,42 +171,39 @@ namespace cucumber_cpp::library::cucumber_expression
171171
172172 std::string Expression::RewriteExpression (const Node& node)
173173 {
174- std::string partialRegex{ CreateString (node) };
174+ std::string partialRegex{ CreateEmptyRegexString (node) };
175175
176176 for (const auto & child : node.Children ())
177177 partialRegex += RewriteToRegex (child);
178178
179179 return std::format (" ^{}$" , partialRegex);
180180 }
181181
182- std::string Expression::CreateString (const Node& node) const
182+ std::string Expression::CreateEmptyRegexString (const Node& node) const
183183 {
184184 std::string partialRegex{};
185185 partialRegex.reserve (node.Children ().size () * 10 );
186186 return partialRegex;
187187 }
188188
189- bool Expression::AreNodesEmpty (const Node& node) const
189+ bool Expression::NodesAreEmpty (const Node& node) const
190190 {
191191 auto results = GetNodesWithType (node, NodeType::text);
192192 return results.empty ();
193193 }
194194
195- std::optional<std::reference_wrapper< const Node>> Expression::GetPossibleNodeWithParameters (const Node& node) const
195+ bool Expression::ContainsNodeWithParameters (const Node& node) const
196196 {
197- return GetPossibleNode (node, NodeType::parameter);
197+ return ContainsNodeWithType (node, NodeType::parameter);
198198 }
199199
200- std::optional<std::reference_wrapper< const Node>> Expression::GetPossibleNodeWithOptionals (const Node& node) const
200+ bool Expression::ContainsNodeWithOptionals (const Node& node) const
201201 {
202- return GetPossibleNode (node, NodeType::optional);
202+ return ContainsNodeWithType (node, NodeType::optional);
203203 }
204204
205- std::optional<std::reference_wrapper< const Node>> Expression::GetPossibleNode (const Node& node, NodeType type) const
205+ bool Expression::ContainsNodeWithType (const Node& node, NodeType type) const
206206 {
207- auto results = GetNodesWithType (node, type);
208- if (results.empty ())
209- return std::nullopt ;
210- return std::ref (results.front ());
207+ return !GetNodesWithType (node, type).empty ();
211208 }
212209}
0 commit comments