From 5f49f72aab10e55803397a7a10f4aa7cf6bf13e1 Mon Sep 17 00:00:00 2001 From: n-ando Date: Mon, 2 Oct 2023 02:22:23 -0400 Subject: [PATCH] getParameterByModulename()'s bug fixed --- src/lib/rtm/ManagerServant.cpp | 82 +++++++++++----------------------- src/lib/rtm/ManagerServant.h | 26 +++++++++++ 2 files changed, 53 insertions(+), 55 deletions(-) diff --git a/src/lib/rtm/ManagerServant.cpp b/src/lib/rtm/ManagerServant.cpp index 7b8c3d2fb..3cda97d63 100644 --- a/src/lib/rtm/ManagerServant.cpp +++ b/src/lib/rtm/ManagerServant.cpp @@ -323,65 +323,37 @@ namespace RTM std::string ManagerServant::getParameterByModulename(const std::string& param_name, std::string &module_name) { - size_t pos0 = module_name.find("&" + param_name + "="); - size_t pos1 = module_name.find("?" + param_name + "="); - - if (pos0 == std::string::npos && pos1 == std::string::npos) - { - return ""; - } - - size_t pos = 0; - if (pos0 == std::string::npos) - { - pos = pos1; - } - else - { - pos = pos0; - } - - std::string paramstr; - size_t endpos = module_name.find('&', pos + 1); - - - if (endpos == std::string::npos) - { - endpos = module_name.find('?', pos + 1); - - if (endpos == std::string::npos) - { - paramstr = module_name.substr((pos + 1)); - - } - else - { - paramstr = module_name.substr((pos + 1), endpos); - } - } - else - { - paramstr = module_name.substr((pos + 1), endpos); - } - RTC_VERBOSE(("%s arg: %s", param_name.c_str(), paramstr.c_str())); - - size_t eqpos = paramstr.find('='); - - paramstr = paramstr.substr(eqpos + 1); + size_t param_start = module_name.find(param_name + "="); + if (param_start == std::string::npos) + { // no specified param + return ""; + } - RTC_DEBUG(("%s is %s", param_name.c_str(), paramstr.c_str())); + size_t param_end = module_name.find("&", param_start); - if (endpos == std::string::npos) - { - module_name = module_name.substr(0, pos); - } - else - { - module_name = module_name.substr(0, pos) + module_name.substr(endpos); - } + if (param_end == std::string::npos) + { // param is end of param list + param_end = module_name.length(); + } - return paramstr; + // extract param's value + // module_name?....param_name=param_value + // substr( ^ arg1 ^ arg2 ^ ) + std::string param_value = + module_name.substr(param_start + param_name.length() + 1, + param_end - param_start - param_name.length() - 1); + RTC_DEBUG(("%s is %s", param_name.c_str(), param_value.c_str())); + // remove specified param + if (module_name[param_start - 1] == '?') + { // module_name?{param_name=param_value}: remove {} + module_name.erase(param_start, param_end - param_start + 1); + } + if (module_name[param_start - 1] == '&') + { // module_name?other_param...{¶m_name=param_value}: remove {} + module_name.erase(param_start - 1, param_end - param_start + 1); + } + return param_value; } /*! diff --git a/src/lib/rtm/ManagerServant.h b/src/lib/rtm/ManagerServant.h index 02076e5fe..7d8f4d8a0 100644 --- a/src/lib/rtm/ManagerServant.h +++ b/src/lib/rtm/ManagerServant.h @@ -703,6 +703,32 @@ namespace RTM * @endif */ void updateMasterManager(); + /* + * @if jp + * @brief create引数から指定されたキーの値を返す + * + * create引数から指定されたキーを値を返すとともに、そのキーと値を削除した引 + * 数を返す。 + * module_name: module_name?param1=value1¶m2=value2¶m3... + * param_name: param2 + * の場合 + * 返り値: value2 + * module_name: module_name?param1=value1¶m3... + * となる。 + * + * @else @brief returns value of specified param_name from create arg + * + * This function returns the value of specified param_name from + * create argument, and delete param_name=value from the create + * arg string. If the arguments are + * module_name: module_name?param1=value1¶m2=value2¶m3... + * param_name: param2 + * this function returns + * ret value: value2 + * module_name: module_name?param1=value1¶m3... + * + * @endif + */ std::string getParameterByModulename(const std::string& param_name, std::string &module_name); static bool isProcessIDManager(const std::string& mgrname);