diff options
Diffstat (limited to 'libbuild2/functions-path.cxx')
-rw-r--r-- | libbuild2/functions-path.cxx | 54 |
1 files changed, 31 insertions, 23 deletions
diff --git a/libbuild2/functions-path.cxx b/libbuild2/functions-path.cxx index d6ff83f..72597ff 100644 --- a/libbuild2/functions-path.cxx +++ b/libbuild2/functions-path.cxx @@ -332,25 +332,30 @@ namespace build2 return ns; }; - // base + // leaf // - f["base"] += &path::base; + f["leaf"] += &path::leaf; - f["base"] += [](paths v) + f["leaf"] += [](path p, dir_path d) + { + return leaf (p, move (d)); + }; + + f["leaf"] += [](paths v, optional<dir_path> d) { for (path& p: v) - p = p.base (); + p = leaf (p, d); return v; }; - f["base"] += [](dir_paths v) + f["leaf"] += [](dir_paths v, optional<dir_path> d) { for (dir_path& p: v) - p = p.base (); + p = leaf (p, d); return v; }; - f[".base"] += [](names ns) + f[".leaf"] += [](names ns, optional<dir_path> d) { // For each path decide based on the presence of a trailing slash // whether it is a directory. Return as untyped list of (potentially @@ -359,37 +364,32 @@ namespace build2 for (name& n: ns) { if (n.directory ()) - n.dir = n.dir.base (); + n.dir = leaf (n.dir, d); else - n.value = convert<path> (move (n)).base ().string (); + n.value = leaf (convert<path> (move (n)), d).string (); } return ns; }; - // leaf + // base // - f["leaf"] += &path::leaf; - - f["leaf"] += [](path p, dir_path d) - { - return leaf (p, move (d)); - }; + f["base"] += &path::base; - f["leaf"] += [](paths v, optional<dir_path> d) + f["base"] += [](paths v) { for (path& p: v) - p = leaf (p, d); + p = p.base (); return v; }; - f["leaf"] += [](dir_paths v, optional<dir_path> d) + f["base"] += [](dir_paths v) { for (dir_path& p: v) - p = leaf (p, d); + p = p.base (); return v; }; - f[".leaf"] += [](names ns, optional<dir_path> d) + f[".base"] += [](names ns) { // For each path decide based on the presence of a trailing slash // whether it is a directory. Return as untyped list of (potentially @@ -398,9 +398,9 @@ namespace build2 for (name& n: ns) { if (n.directory ()) - n.dir = leaf (n.dir, d); + n.dir = n.dir.base (); else - n.value = leaf (convert<path> (move (n)), d).string (); + n.value = convert<path> (move (n)).base ().string (); } return ns; }; @@ -414,6 +414,14 @@ namespace build2 return extension (convert<path> (move (ns))); }; + // $size(<paths>) + // $size(<dir_paths>) + // + // Return the number of elements in the sequence. + // + f["size"] += [] (paths v) {return v.size ();}; + f["size"] += [] (dir_paths v) {return v.size ();}; + // $sort(<paths> [, <flags>]) // $sort(<dir_paths> [, <flags>]) // |