diff options
author | Ryan Trinkle <ryan.trinkle@gmail.com> | 2017-12-02 13:03:40 -0500 |
---|---|---|
committer | Ryan Trinkle <ryan.trinkle@gmail.com> | 2017-12-02 13:28:00 -0500 |
commit | 6281eb123bcdefcaebbd973600f4d33772012025 (patch) | |
tree | 5299241350ff82fed733cfb62091bb9f58674de0 /lib | |
parent | 7d27f25582b70b8d74100a5df8d7ba8e869cad24 (diff) |
nixpkgs.lib: Add escapeNixString
Diffstat (limited to 'lib')
-rw-r--r-- | lib/strings.nix | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/lib/strings.nix b/lib/strings.nix index aca9ef45e615..9cbd1494a2b5 100644 --- a/lib/strings.nix +++ b/lib/strings.nix @@ -219,6 +219,14 @@ rec { */ escapeShellArgs = concatMapStringsSep " " escapeShellArg; + /* Turn a string into a Nix expression representing that string + + Example: + escapeNixString "hello\${}\n" + => "\"hello\\\${}\\n\"" + */ + escapeNixString = s: escape ["$"] (builtins.toJSON s); + /* Obsolete - use replaceStrings instead. */ replaceChars = builtins.replaceStrings or ( del: new: s: |