mirror of
https://github.com/NixOS/nixpkgs.git
synced 2024-11-18 03:30:45 +00:00
Merge pull request #261676 from h7x4/lib-add-replicatestring
lib.strings: add `replicate`
This commit is contained in:
commit
17012aa0d2
|
@ -144,6 +144,20 @@ rec {
|
|||
*/
|
||||
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.
|
||||
|
||||
|
|
|
@ -191,6 +191,11 @@ runTests {
|
|||
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" ];
|
||||
|
|
Loading…
Reference in a new issue