Add removePrefix function.
svn path=/nixpkgs/trunk/; revision=17667
This commit is contained in:
parent
c3d328ca48
commit
1f68748a8b
|
@ -106,4 +106,18 @@ rec {
|
||||||
cutUntil sLen;
|
cutUntil sLen;
|
||||||
in
|
in
|
||||||
recurse 0 0;
|
recurse 0 0;
|
||||||
|
|
||||||
|
# return the suffix of the second argument if the first argument match its
|
||||||
|
# prefix. e.g.,
|
||||||
|
# `removePrefix "foo." "foo.bar.baz"' returns "bar.baz".
|
||||||
|
removePrefix = pre: s:
|
||||||
|
let
|
||||||
|
preLen = stringLength pre;
|
||||||
|
sLen = stringLength s;
|
||||||
|
in
|
||||||
|
if pre == substring 0 preLen s then
|
||||||
|
substring preLen (sub sLen preLen) s
|
||||||
|
else
|
||||||
|
s;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue