lib.strings: add `replicate`

`strings.replicate` returns n copies of a string, concatenated into a new
string

Co-authored-by: Silvan Mosberger <github@infinisil.com>

h7x4 206d2042 f320b0d4

Changed files
+19
lib
+14
lib/strings.nix
···
*/
concatLines = concatMapStrings (s: s + "\n");
+
/*
+
Replicate a string n times,
+
and concatenate the parts into a new string.
+
+
Type: replicate :: int -> string -> string
+
+
Example:
+
replicate 3 "v"
+
=> "vvv"
+
replicate 5 "hello"
+
=> "hellohellohellohellohello"
+
*/
+
replicate = n: s: concatStrings (lib.lists.replicate n s);
+
/* Construct a Unix-style, colon-separated search path consisting of
the given `subDir` appended to each of the given paths.
+5
lib/tests/misc.nix
···
expected = "a\nb\nc\n";
};
+
testReplicateString = {
+
expr = strings.replicate 5 "hello";
+
expected = "hellohellohellohellohello";
+
};
+
testSplitStringsSimple = {
expr = strings.splitString "." "a.b.c.d";
expected = [ "a" "b" "c" "d" ];