Add removePrefix function.

svn path=/nixpkgs/trunk/; revision=17667
This commit is contained in:
Nicolas Pierron 2009-10-06 09:21:39 +00:00
parent c3d328ca48
commit 1f68748a8b

View File

@ -106,4 +106,18 @@ rec {
cutUntil sLen;
in
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;
}