27 lines
1.2 KiB
Mathematica
27 lines
1.2 KiB
Mathematica
( sInputText as nullable text,
|
|
optional bWholeCell as nullable logical,
|
|
optional sTag as nullable text,
|
|
optional tSubstitution as nullable table) as text =>
|
|
|
|
let
|
|
bIsWholeCell = if (bWholeCell = null) then true else bWholeCell,
|
|
bIsTagged = not (sTag = null),
|
|
tSubstitution = if tSubstitution = null then
|
|
if bIsTagged then
|
|
try Table.SelectRows(fP("RENAMING_RULES"), each ([#"#"] = sTag)) otherwise fP("RENAMING_RULES")
|
|
else
|
|
fP("RENAMING_RULES")
|
|
else
|
|
tSubstitution,
|
|
|
|
tSubstBuffer = Table.Buffer(tSubstitution),
|
|
ReplacedText = List.Accumulate(Table.ToRows(tSubstBuffer), sInputText, (state, substitution) =>
|
|
if bIsWholeCell then
|
|
if (state = substitution{0}) then
|
|
substitution{1}
|
|
else
|
|
state
|
|
else
|
|
Text.Replace(state, substitution{0}, substitution{1}))
|
|
in
|
|
ReplacedText |