From de5be50b2d5a67dd1f969fc8f451ea7a74debac7 Mon Sep 17 00:00:00 2001 From: Michael Raskin <7c6f434c@mail.ru> Date: Thu, 13 Sep 2012 13:59:23 +0400 Subject: [PATCH] Adding a function capable of extracting the name with version out of url/file path --- pkgs/lib/strings.nix | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/pkgs/lib/strings.nix b/pkgs/lib/strings.nix index fb2752d97c19..4bd7a5bebde3 100644 --- a/pkgs/lib/strings.nix +++ b/pkgs/lib/strings.nix @@ -155,4 +155,14 @@ rec { # Return true iff string v1 denotes a version older than v2. versionOlder = v1: v2: builtins.compareVersions v2 v1 == 1; + # Extract name with version from URL. Ask for separator which is + # supposed to start extension + nameFromURL = url: sep: let + components = splitString "/" url; + filename = lib.last components; + name = builtins.head (splitString sep filename); + in + assert ! eqStrings name filename; + name; + }