global-functions: $CharacterReplace: do not limit string length

I've tried something like this to update a device:

/ system script set source=[ $CharacterReplace [ get global-config-overlay source ] "GlobalConfigVersion 10" "GlobalConfigVersion 11" ] global-config-overlay;

This broke with global-config-overlay longer than 999 characters. So makes
sure there is no limit for string length.
This commit is contained in:
Christian Hesse 2020-02-03 21:29:21 +01:00
parent 0c705d5311
commit 03af7d6d9c

View file

@ -64,7 +64,6 @@
:local String [ :tostr $1 ];
:local ReplaceFrom [ :tostr $2 ];
:local ReplaceWith [ :tostr $3 ];
:local Len [ :len $ReplaceFrom ];
:local Return "";
:if ($ReplaceFrom = "") do={
@ -74,7 +73,7 @@
:while ([ :typeof [ :find $String $ReplaceFrom ] ] != "nil") do={
:local Pos [ :find $String $ReplaceFrom ];
:set Return ($Return . [ :pick $String 0 $Pos ] . $ReplaceWith);
:set String [ :pick $String ($Pos + $Len) 999 ];
:set String [ :pick $String ($Pos + [ :len $ReplaceFrom ]) [ :len $String ] ];
}
:return ($Return . $String);