lib.strings: Add function to do C-style escaping
This commit is contained in:
parent
a08741ffbd
commit
4c420ee485
|
@ -320,6 +320,19 @@ rec {
|
|||
*/
|
||||
escape = list: replaceChars list (map (c: "\\${c}") list);
|
||||
|
||||
/* Escape occurence of the element of `list` in `string` by
|
||||
converting to its ASCII value and prefixing it with \\x.
|
||||
Only works for printable ascii characters.
|
||||
|
||||
Type: escapeC = [string] -> string -> string
|
||||
|
||||
Example:
|
||||
escapeC [" "] "foo bar"
|
||||
=> "foo\\x20bar"
|
||||
|
||||
*/
|
||||
escapeC = list: replaceChars list (map (c: "\\x${ toLower (lib.toHexString (charToInt c))}") list);
|
||||
|
||||
/* Quote string to be used safely within the Bourne shell.
|
||||
|
||||
Type: escapeShellArg :: string -> string
|
||||
|
|
Loading…
Reference in a new issue