Skip to content

Commit

Permalink
WB_FormulaSwitchToShorthand: Replace only full stimset names
Browse files Browse the repository at this point in the history
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 9b80987 (WaveBuilder: Add new
epoch type Combine, 2015-11-12).
  • Loading branch information
t-b committed Oct 2, 2023
1 parent 0e3b2ea commit 4b57da8
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
5 changes: 3 additions & 2 deletions Packages/MIES/MIES_WaveBuilder.ipf
Original file line number Diff line number Diff line change
Expand Up @@ -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 ""
Expand All @@ -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
Expand Down
20 changes: 20 additions & 0 deletions Packages/tests/Basic/UTF_WaveBuilder.ipf
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 4b57da8

Please sign in to comment.