From 4b57da80cd43a078f58566c21e4f76d024f83d78 Mon Sep 17 00:00:00 2001 From: Thomas Braun Date: Mon, 2 Oct 2023 20:57:16 +0200 Subject: [PATCH] WB_FormulaSwitchToShorthand: Replace only full stimset names We must not just replace stimset names as two stimsets might have the same ending substring. By just replacing only full words we avoid the issue without having to change what we store in WPT. Bug introduced in the initial version in 9b809878 (WaveBuilder: Add new epoch type Combine, 2015-11-12). --- Packages/MIES/MIES_WaveBuilder.ipf | 5 +++-- Packages/tests/Basic/UTF_WaveBuilder.ipf | 20 ++++++++++++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/Packages/MIES/MIES_WaveBuilder.ipf b/Packages/MIES/MIES_WaveBuilder.ipf index 5737633aba..8f8a50f8ce 100644 --- a/Packages/MIES/MIES_WaveBuilder.ipf +++ b/Packages/MIES/MIES_WaveBuilder.ipf @@ -2158,7 +2158,7 @@ End Function/S WB_FormulaSwitchToShorthand(variable channelType, string formula) variable numSets, i - string stimset, shorthand + string stimset, shorthand, regex if(isEmpty(formula)) return "" @@ -2171,7 +2171,8 @@ Function/S WB_FormulaSwitchToShorthand(variable channelType, string formula) shorthand = epochCombineList[i][%Shorthand] stimset = epochCombineList[i][%stimset] - formula = ReplaceString(stimset + "?", formula, shorthand) + regex = "(?i)\\b\\Q" + stimset + "\\E\\b\?" + formula = ReplaceRegexInString(regex, formula, shorthand) endfor return formula diff --git a/Packages/tests/Basic/UTF_WaveBuilder.ipf b/Packages/tests/Basic/UTF_WaveBuilder.ipf index c25691db12..ff43b24e3c 100644 --- a/Packages/tests/Basic/UTF_WaveBuilder.ipf +++ b/Packages/tests/Basic/UTF_WaveBuilder.ipf @@ -357,3 +357,23 @@ Function WB_StimsetWithNoEpochsAreNotSaved() CHECK_EQUAL_STR(ST_GetStimsetList(searchString = basename + "*"), "") End + +Function CombineStimsetSubStrings() + + string setNameA, setNameAA, setNameCombine + + setNameA = ST_CreateStimSet("setABC", CHANNEL_TYPE_DAC) + setNameAA = ST_CreateStimSet("newsetABC", CHANNEL_TYPE_DAC) + + setNameCombine = ST_CreateStimSet("setCombine", CHANNEL_TYPE_DAC) + + ST_SetStimsetParameter(setNameCombine, "Total number of epochs", var = 1) + ST_SetStimsetParameter(setNameCombine, "Type of Epoch 0", var = EPOCH_TYPE_COMBINE) + + ST_SetStimsetParameter(setNameCombine, "Combine epoch formula version", epochIndex = 0, str = WAVEBUILDER_COMBINE_FORMULA_VER) + ST_SetStimsetParameter(setNameCombine, "Combine epoch formula", epochIndex = 0, str = LowerStr(setNameA) + "?" + " + " + LowerStr(setNameAA) + "?") + + WAVE/Z wv = WB_CreateAndGetStimSet(setNameCombine) + CHECK_WAVE(wv, NUMERIC_WAVE) + CHECK_NO_RTE() +End