Skip to content

Commit

Permalink
Improve performance of escapeStringBash and escapeStringDollars
Browse files Browse the repository at this point in the history
  • Loading branch information
itchyny committed Apr 8, 2024
1 parent 4e7678a commit 9d58b57
Showing 1 changed file with 2 additions and 12 deletions.
14 changes: 2 additions & 12 deletions stdlib/std.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -1005,21 +1005,11 @@ limitations under the License.

escapeStringBash(str_)::
local str = std.toString(str_);
local trans(ch) =
if ch == "'" then
"'\"'\"'"
else
ch;
"'%s'" % std.join('', [trans(ch) for ch in std.stringChars(str)]),
"'%s'" % std.strReplace(str, "'", "'\"'\"'"),

escapeStringDollars(str_)::
local str = std.toString(str_);
local trans(ch) =
if ch == '$' then
'$$'
else
ch;
std.foldl(function(a, b) a + trans(b), std.stringChars(str), ''),
std.strReplace(str, '$', '$$'),

local xml_escapes = {
'<': '&lt;',
Expand Down

0 comments on commit 9d58b57

Please sign in to comment.