@@ -323,65 +323,37 @@ namespace RTM
323
323
324
324
std::string ManagerServant::getParameterByModulename (const std::string& param_name, std::string &module_name)
325
325
{
326
- size_t pos0 = module_name.find (" &" + param_name + " =" );
327
- size_t pos1 = module_name.find (" ?" + param_name + " =" );
328
-
329
- if (pos0 == std::string::npos && pos1 == std::string::npos)
330
- {
331
- return " " ;
332
- }
333
-
334
- size_t pos = 0 ;
335
- if (pos0 == std::string::npos)
336
- {
337
- pos = pos1;
338
- }
339
- else
340
- {
341
- pos = pos0;
342
- }
343
-
344
- std::string paramstr;
345
- size_t endpos = module_name.find (' &' , pos + 1 );
346
-
347
-
348
- if (endpos == std::string::npos)
349
- {
350
- endpos = module_name.find (' ?' , pos + 1 );
351
-
352
- if (endpos == std::string::npos)
353
- {
354
- paramstr = module_name.substr ((pos + 1 ));
355
-
356
- }
357
- else
358
- {
359
- paramstr = module_name.substr ((pos + 1 ), endpos);
360
- }
361
- }
362
- else
363
- {
364
- paramstr = module_name.substr ((pos + 1 ), endpos);
365
- }
366
- RTC_VERBOSE ((" %s arg: %s" , param_name.c_str (), paramstr.c_str ()));
367
-
368
- size_t eqpos = paramstr.find (' =' );
369
-
370
- paramstr = paramstr.substr (eqpos + 1 );
326
+ size_t param_start = module_name.find (param_name + " =" );
371
327
328
+ if (param_start == std::string::npos)
329
+ { // no specified param
330
+ return " " ;
331
+ }
372
332
373
- RTC_DEBUG (( " %s is %s " , param_name. c_str (), paramstr. c_str ()) );
333
+ size_t param_end = module_name. find ( " & " , param_start );
374
334
375
- if (endpos == std::string::npos)
376
- {
377
- module_name = module_name.substr (0 , pos);
378
- }
379
- else
380
- {
381
- module_name = module_name.substr (0 , pos) + module_name.substr (endpos);
382
- }
335
+ if (param_end == std::string::npos)
336
+ { // param is end of param list
337
+ param_end = module_name.length ();
338
+ }
383
339
384
- return paramstr;
340
+ // extract param's value
341
+ // module_name?....param_name=param_value
342
+ // substr( ^ arg1 ^ arg2 ^ )
343
+ std::string param_value =
344
+ module_name.substr (param_start + param_name.length () + 1 ,
345
+ param_end - param_start - param_name.length () - 1 );
346
+ RTC_DEBUG ((" %s is %s" , param_name.c_str (), param_value.c_str ()));
347
+ // remove specified param
348
+ if (module_name[param_start - 1 ] == ' ?' )
349
+ { // module_name?{param_name=param_value}: remove {}
350
+ module_name.erase (param_start, param_end - param_start + 1 );
351
+ }
352
+ if (module_name[param_start - 1 ] == ' &' )
353
+ { // module_name?other_param...{¶m_name=param_value}: remove {}
354
+ module_name.erase (param_start - 1 , param_end - param_start + 1 );
355
+ }
356
+ return param_value;
385
357
}
386
358
387
359
/* !
0 commit comments