diff options
author | Patrick Hilhorst <git@hilhorst.be> | 2018-06-06 22:04:35 +0200 |
---|---|---|
committer | Patrick Hilhorst <git@hilhorst.be> | 2018-11-06 00:04:21 +0100 |
commit | 320c9c10de8489604c459127079f59a3ef4d8475 (patch) | |
tree | 1e8568c447c03ca9a21148630667accee8d2454b /lib/strings.nix | |
parent | 48caae504502d36c65e3aa9d9b6aee7d06085057 (diff) |
make-derivation: use pname-version as default name if both are present
Diffstat (limited to 'lib/strings.nix')
-rw-r--r-- | lib/strings.nix | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/lib/strings.nix b/lib/strings.nix index 4d7fa1e774d5..48420a367815 100644 --- a/lib/strings.nix +++ b/lib/strings.nix @@ -236,6 +236,26 @@ rec { in lenContent >= lenSuffix && substring (lenContent - lenSuffix) lenContent content == suffix; + /* Determine whether a string contains the given infix + + Type: hasInfix :: string -> string -> bool + + Example: + hasInfix "bc" "abcd" + => true + hasInfix "ab" "abcd" + => true + hasInfix "cd" "abcd" + => true + hasInfix "foo" "abcd" + => false + */ + hasInfix = infix: content: + let + drop = x: substring 1 (stringLength x) x; + in hasPrefix infix content + || content != "" && hasInfix infix (drop content); + /* Convert a string to a list of characters (i.e. singleton strings). This allows you to, e.g., map a function over each character. However, note that this will likely be horribly inefficient; Nix is not a |