@@ -188,37 +188,31 @@ class TSWControllerMod : public RC::CppUserModBase
188188
189189 /* regex pattern to match {SIDE} with optional front/back placeholders */
190190 /* captures: front placeholder (optional), back placeholder (optional) */
191- std::regex side_placeholder_regex (R"( \{SIDE(:[^:]+)?(:[^:]+)?\})" );
192- std::smatch match;
193- std::wregex_match (control_name.begin (), control_name.end (), match, side_placeholder_regex);
194-
195- if (match.size () >= 1 )
191+ std::wregex side_placeholder_regex (STR (R"( \{SIDE(:[^:]+)?(:[^:]+)?\})" ));
192+ std::wsmatch side_placeholder_matches;
193+ if (std::regex_match (control_name, side_placeholder_matches, side_placeholder_regex))
196194 {
197- std::size_t placeholder_start = match [0 ].position () ;
198- std::size_t placeholder_end = match [0 ].position () + match[ 0 ]. length () ;
195+ std::size_t placeholder_start = side_placeholder_matches [0 ].first ;
196+ std::size_t placeholder_end = side_placeholder_matches [0 ].second ;
199197
200- /* determine which value to use based on train side */
201198 RC::StringType front_value = STR (" F" );
202199 RC::StringType back_value = STR (" B" );
203200
204- /* extract front placeholder if specified (between first and second colon) */
205- if (match.size () >= 2 )
201+ if (side_placeholder_matches.length () >= 2 )
206202 {
207- front_value = STR (match [1 ].str ().substr (1 ) );
203+ front_value = side_placeholder_matches [1 ].str ().substr (1 );
208204 }
209205
210- /* extract back placeholder if specified (after second colon) */
211- if (match.size () >= 3 )
206+ if (side_placeholder_matches.length () >= 3 )
212207 {
213- back_value = STR (match [2 ].str ().substr (1 ) );
208+ back_value = side_placeholder_matches [2 ].str ().substr (1 );
214209 }
215210
216- /* select appropriate value based on train side */
211+ /* determine which value to use based on train side */
217212 RC::StringType train_side_str = train_side == 0 ? front_value : back_value;
218-
219- /* replace the placeholder with the selected value */
220213 control_name.replace (placeholder_start, placeholder_end - placeholder_start, train_side_str);
221214 }
215+
222216 /* if no {SIDE} -> just return raw*/
223217 return control_name;
224218 }
0 commit comments