hasInfix
lib.strings.hasInfix
Docs pulled from | This Revision | 14 minutes ago
Determine whether a string contains the given infix
Inputs
infix
- 1. Function argument
content
- 2. Function argument
Type
hasInfix :: string -> string -> bool
Examples
lib.strings.hasInfix
usage example
hasInfix "bc" "abcd"
=> true
hasInfix "ab" "abcd"
=> true
hasInfix "cd" "abcd"
=> true
hasInfix "foo" "abcd"
=> false
Noogle detected
Implementation
The following is the current implementation of this function.
hasInfix = infix: content:
# Before 23.05, paths would be copied to the store before converting them
# to strings and comparing. This was surprising and confusing.
warnIf
(isPath infix)
''
lib.strings.hasInfix: The first argument (${toString infix}) is a path value, but only strings are supported.
There is almost certainly a bug in the calling code, since this function always returns `false` in such a case.
This function also copies the path to the Nix store, which may not be what you want.
This behavior is deprecated and will throw an error in the future.''
(builtins.match ".*${escapeRegex infix}.*" "${content}" != null);