lix/src/libutil
Eelco Dolstra 976df480c9 Add a primop for regular expression pattern matching
The function ‘builtins.match’ takes a POSIX extended regular
expression and an arbitrary string. It returns ‘null’ if the string
does not match the regular expression. Otherwise, it returns a list
containing substring matches corresponding to parenthesis groups in
the regex. The regex must match the entire string (i.e. there is an
implied "^<pat>$" around the regex).  For example:

  match "foo" "foobar" => null
  match "foo" "foo" => []
  match "f(o+)(.*)" "foooobar" => ["oooo" "bar"]
  match "(.*/)?([^/]*)" "/dir/file.nix" => ["/dir/" "file.nix"]
  match "(.*/)?([^/]*)" "file.nix" => [null "file.nix"]

The following example finds all regular files with extension .nix or
.patch underneath the current directory:

  let

    findFiles = pat: dir: concatLists (mapAttrsToList (name: type:
      if type == "directory" then
        findFiles pat (dir + "/" + name)
      else if type == "regular" && match pat name != null then
        [(dir + "/" + name)]
      else []) (readDir dir));

  in findFiles ".*\\.(nix|patch)" (toString ./.)
2014-11-25 11:47:06 +01:00
..
affinity.cc Don't apply the CPU affinity hack to nix-shell (and other Perl programs) 2013-09-06 16:36:56 +02:00
affinity.hh Run the daemon worker on the same CPU as the client 2013-08-07 14:02:04 +02:00
archive.cc Use proper quotes everywhere 2014-08-20 18:03:48 +02:00
archive.hh Handle case collisions on case-insensitive systems 2014-07-16 16:02:05 +02:00
hash.cc Use proper quotes everywhere 2014-08-20 18:03:48 +02:00
hash.hh If hashes do not match, print them in base-32 for SHA-1/SHA-256 2012-10-23 18:05:50 +02:00
local.mk Update Makefile variable names 2014-02-01 13:54:38 +01:00
md5.c * Optional switch "--with-openssl=<PATH>" to use OpenSSL's 2006-02-13 19:52:43 +00:00
md5.h * Some Cygwin fixes. 2006-05-24 13:23:20 +00:00
md32_common.h
monitor-fd.hh Use pthread_cancel instead of a signal 2014-07-24 11:47:51 +02:00
regex.cc Add a primop for regular expression pattern matching 2014-11-25 11:47:06 +01:00
regex.hh Add a primop for regular expression pattern matching 2014-11-25 11:47:06 +01:00
serialise.cc Print a warning when loading a large path into memory 2014-06-10 13:30:09 +02:00
serialise.hh Don't use member initialisers 2014-06-12 17:30:37 +02:00
sha1.c * Optional switch "--with-openssl=<PATH>" to use OpenSSL's 2006-02-13 19:52:43 +00:00
sha1.h * Optional switch "--with-openssl=<PATH>" to use OpenSSL's 2006-02-13 19:52:43 +00:00
sha256.c
sha256.h
types.hh Fix build on gcc < 4.7 2014-10-20 12:15:50 -04:00
util.cc nix-daemon: Call exit(), not _exit() 2014-11-19 17:09:27 +01:00
util.hh nix-daemon: Call exit(), not _exit() 2014-11-19 17:09:27 +01:00
xml-writer.cc And another one 2014-02-26 18:55:18 +01:00
xml-writer.hh And another one 2014-02-26 18:55:18 +01:00