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
mr13.5
Marco Capetta 11 months ago
parent 49894e3f32
commit eff9dba5e3

@ -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;i<str.length();i++) {
sc_sess->var[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();

@ -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);

Loading…
Cancel
Save