aboutsummaryrefslogtreecommitdiff
path: root/build/prefix-map
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2015-02-24 06:27:57 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2015-02-24 06:27:57 +0200
commit52925684387496e83425c79f74b29a91943466a7 (patch)
tree02ba612b339e73625be28ab141fe11e358866404 /build/prefix-map
parent5fc53bd74c7635a292cef041180da4cd32b7fb12 (diff)
Make empty key to always be prefix in prefix_map
Diffstat (limited to 'build/prefix-map')
-rw-r--r--build/prefix-map10
1 files changed, 8 insertions, 2 deletions
diff --git a/build/prefix-map b/build/prefix-map
index d2ca9be..a385ca8 100644
--- a/build/prefix-map
+++ b/build/prefix-map
@@ -39,8 +39,9 @@ namespace build
prefix (const K& p, const K& k) const
{
size_type pn (p.size ());
- return compare (
- p.c_str (), pn, k.c_str (), pn == k.size () ? pn : pn + 1) == 0;
+ return pn == 0 || // Empty key is always a prefix.
+ compare (
+ p.c_str (), pn, k.c_str (), pn == k.size () ? pn : pn + 1) == 0;
}
int
@@ -76,6 +77,11 @@ namespace build
// the ability to retrieve a range of entries that have a specific
// prefix. The '.' and '/' above are the delimiter characters.
//
+ // Note that as a special rule, the default implementation of
+ // compare_prefix treats empty key as everyone's prefix even if
+ // the paths don't start with the delimiter (useful to represent
+ // a "root path").
+ //
// Implementation-wise, the idea is to pretend that each key ends
// with the delimiter. This way we automatically avoid matching
// 'foobar' as having a prefix 'foo'.