diff options
Diffstat (limited to 'nixpkgs/lib/strings.nix')
-rw-r--r-- | nixpkgs/lib/strings.nix | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/nixpkgs/lib/strings.nix b/nixpkgs/lib/strings.nix index a111e1e2597b..de135d1c2746 100644 --- a/nixpkgs/lib/strings.nix +++ b/nixpkgs/lib/strings.nix @@ -362,6 +362,19 @@ rec { if match "[a-zA-Z_][a-zA-Z0-9_'-]*" s != null then s else escapeNixString s; + /* Escapes a string such that it is safe to include verbatim in an XML + document. + + Type: string -> string + + Example: + escapeXML ''"test" 'test' < & >'' + => "\\[\\^a-z]\\*" + */ + escapeXML = builtins.replaceStrings + ["\"" "'" "<" ">" "&"] + [""" "'" "<" ">" "&"]; + # Obsolete - use replaceStrings instead. replaceChars = builtins.replaceStrings or ( del: new: s: |