From fa2b78c782a33c309b2e6d2764cb03126cae520d Mon Sep 17 00:00:00 2001 From: Donat Zenichev Date: Thu, 26 Sep 2024 19:53:56 +0200 Subject: [PATCH] MT#59962 DSM: Add new function 'removeFromString()' To simplify the work in DSM with strings, the new function which removes patterns from the source string, has been added. This allows us to remove unneeded stuff from the given value, avoiding usage of complex regexes. Change-Id: I07fd08938a10475120affb395c5b506e8d412f78 --- apps/dsm/DSMCoreModule.cpp | 16 ++++++++++++++++ apps/dsm/DSMCoreModule.h | 2 ++ 2 files changed, 18 insertions(+) diff --git a/apps/dsm/DSMCoreModule.cpp b/apps/dsm/DSMCoreModule.cpp index db67bc14..8e9b3027 100644 --- a/apps/dsm/DSMCoreModule.cpp +++ b/apps/dsm/DSMCoreModule.cpp @@ -124,6 +124,8 @@ DSMAction* DSMCoreModule::getAction(const string& from_str) { DEF_CMD("unregisterEventQueue", SCUnregisterEventQueueAction); DEF_CMD("createSystemDSM", SCCreateSystemDSMAction); + DEF_CMD("removeFromString", SCRemovePatternAction); + DEF_CMD("getErrorCodePlayback", SCGetErrorCodePlaybackAction); if (cmd == "DI") { @@ -1008,6 +1010,20 @@ EXEC_ACTION_START(SCArrayIndexAction) { } } EXEC_ACTION_END; +CONST_ACTION_2P(SCRemovePatternAction, ',', false); +EXEC_ACTION_START(SCRemovePatternAction) { + string source_name = (par1.length() && par1[0] == '$') ? par1.substr(1) : par1; + string source_value = resolveVars(par1, sess, sc_sess, event_params); + string pattern = par2; + size_t pos = std::string::npos; + while ((pos = source_value.find(pattern)) != std::string::npos) + { + source_value.erase(pos, pattern.length()); + } + sc_sess->var[source_name] = source_value; +} EXEC_ACTION_END; + + CONST_ACTION_3P(SCGetErrorCodePlaybackAction, ',', false); EXEC_ACTION_START(SCGetErrorCodePlaybackAction) { string source_value = resolveVars(par1, sess, sc_sess, event_params); diff --git a/apps/dsm/DSMCoreModule.h b/apps/dsm/DSMCoreModule.h index ec1d06a2..d8077238 100644 --- a/apps/dsm/DSMCoreModule.h +++ b/apps/dsm/DSMCoreModule.h @@ -135,6 +135,8 @@ DEF_ACTION_1P(SCUnregisterEventQueueAction); DEF_ACTION_2P(SCCreateSystemDSMAction); +DEF_ACTION_2P(SCRemovePatternAction); + DEF_ACTION_3P(SCGetErrorCodePlaybackAction); DEF_ACTION_1P(SCTrackObjectAction);