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 authored and johnbartholomew committed Apr 17, 2024
1 parent 67a4421 commit e8e278e
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 @@ -1018,21 +1018,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 e8e278e

Please sign in to comment.