@@ -149,32 +149,29 @@ void ParserState::parse_command_parts(std::string_view& name, std::string_view&
149149 return ;
150150 }
151151
152- // Commands with parameters are typically 2 characters followed by data
153- // Examples: :Sr12:34:56#, :Sd+45*30:15#, :SC03/15/23#
154- // Commands without parameters: :GR#, :MS#, :Q#
155-
156- // Heuristic: If command is longer than 2 chars and first char is 'S',
157- // it likely has parameters (SetInfo commands)
158- // Also handles other commands with parameters
152+ // Lookup table: command families that take parameters after 2-char name
153+ // This replaces the if-else chain for better maintainability
154+ static constexpr char PARAMETER_FAMILIES[] = {
155+ ' S' , // SetInfo commands (Sr, Sd, SC, SL, etc.)
156+ ' R' , // Rate commands (R0-R9)
157+ ' T' , // Tracking commands (T+, T-)
158+ ' F' , // Focus commands (F+, F-)
159+ ' B' , // Reticle commands (B+, B-)
160+ ' g' , // GPS commands (some variants)
161+ ' L' , // Library commands (some variants)
162+ };
159163
160164 if (full_command.length () > 2 ) {
161165 char first = full_command[0 ];
162166
163- // SetInfo commands have parameters after 2-char name
164- if (first == ' S' ) {
165- name = full_command.substr (0 , 2 );
166- params = full_command.substr (2 );
167- return ;
168- }
169-
170- // Some other commands have parameters too
171- // For now, assume 2-char commands, rest is parameters
172- // This can be refined based on command-specific rules
173- if (full_command.length () > 2 &&
174- (first == ' R' || first == ' T' || first == ' F' || first == ' B' )) {
175- name = full_command.substr (0 , 2 );
176- params = full_command.substr (2 );
177- return ;
167+ // Check if first character is in parameter families
168+ for (char family : PARAMETER_FAMILIES) {
169+ if (first == family) {
170+ // Standard pattern: 2-char command name + parameters
171+ name = full_command.substr (0 , 2 );
172+ params = full_command.substr (2 );
173+ return ;
174+ }
178175 }
179176 }
180177
0 commit comments