From eff9dba5e3c81f7cf2c7a41f4558d18743c2f2b1 Mon Sep 17 00:00:00 2001 From: Marco Capetta Date: Wed, 3 Sep 2025 09:19:43 +0200 Subject: [PATCH] MT#63029 Add a new DSM function to GetStringToChar It allows to split a string in an array of char for spelling or other purposes. Change-Id: Ia218740558e844d2b6b439006c557545b5f0f165 --- apps/dsm/mods/mod_utils/ModUtils.cpp | 29 ++++++++++++++++++++++++++++ apps/dsm/mods/mod_utils/ModUtils.h | 1 + 2 files changed, 30 insertions(+) diff --git a/apps/dsm/mods/mod_utils/ModUtils.cpp b/apps/dsm/mods/mod_utils/ModUtils.cpp index 5268c151..18900be5 100644 --- a/apps/dsm/mods/mod_utils/ModUtils.cpp +++ b/apps/dsm/mods/mod_utils/ModUtils.cpp @@ -50,6 +50,7 @@ MOD_ACTIONEXPORT_BEGIN(MOD_CLS_NAME) { DEF_CMD("utils.getCountLeft", SCUGetCountLeftAction); DEF_CMD("utils.getCountRightNoSuffix", SCUGetCountRightNoSuffixAction); DEF_CMD("utils.getCountLeftNoSuffix", SCUGetCountLeftNoSuffixAction); + DEF_CMD("utils.getStringToChar", SCUGetStringToCharAction); DEF_CMD("utils.getNewId", SCGetNewIdAction); DEF_CMD("utils.spell", SCUSpellAction); @@ -545,6 +546,34 @@ EXEC_ACTION_START(SCUGetCountLeftNoSuffixAction) { } EXEC_ACTION_END; +CONST_ACTION_3P(SCUGetStringToCharAction, ',', true); +EXEC_ACTION_START(SCUGetStringToCharAction) { + unsigned int cnt = 0; + bool lower = false; + + string str = resolveVars(par1, sess, sc_sess, event_params); + + if (!par2.length()) { + ERROR("name of the destination array nor specified\n"); + sc_sess->SET_ERRNO(DSM_ERRNO_UNKNOWN_ARG); + sc_sess->SET_STRERROR("name of the destination array nor specified\n"); + return false; + } + string dst_array = (par2[0] == '$') ? par2.substr(1) : par2; + + if (par3.length() && par3 == "true") + lower = true; + + DBG("splitting to chars the string '%s'\n", str.c_str()); + + for (size_t i=0;ivar[dst_array+"["+int2str(cnt)+"]"] = (lower) ? tolower(str[i]) : str[i]; + cnt++; + } + +} EXEC_ACTION_END; + + EXEC_ACTION_START(SCGetNewIdAction) { string d = resolveVars(arg, sess, sc_sess, event_params); sc_sess->var[d]=AmSession::getNewId(); diff --git a/apps/dsm/mods/mod_utils/ModUtils.h b/apps/dsm/mods/mod_utils/ModUtils.h index e5a2c55d..5b0e2f19 100644 --- a/apps/dsm/mods/mod_utils/ModUtils.h +++ b/apps/dsm/mods/mod_utils/ModUtils.h @@ -48,6 +48,7 @@ DEF_ACTION_2P(SCUGetCountRightAction); DEF_ACTION_2P(SCUGetCountLeftAction); DEF_ACTION_2P(SCUGetCountRightNoSuffixAction); DEF_ACTION_2P(SCUGetCountLeftNoSuffixAction); +DEF_ACTION_3P(SCUGetStringToCharAction); DEF_ACTION_1P(SCGetNewIdAction); DEF_ACTION_2P(SCUSpellAction);