| 6 | { |
| 7 | std::stringstream ss(keyPath); |
| 8 | std::string item; |
| 9 |
| 10 | while (getline(ss, item, '.')) { |
| 11 | mKeys.push_back(item); |
| 12 | } |
| 13 | } |
| 14 |
| 15 | bool LOTKeyPath::matches(const std::string &key, uint depth) |
| 16 | { |
| 17 | if (skip(key)) { |
| 18 | // This is an object we programatically create. |
| 19 | return true; |
| 20 | } |
| 21 | if (depth > size()) { |
| 22 | return false; |
| 23 | } |
| 24 | if ((mKeys[depth] == key) || (mKeys[depth] == "*") || |
| 25 | (mKeys[depth] == "**")) { |
| 26 | return true; |
| 27 | } |
| 28 | return false; |
| 29 | } |
| 30 |
| 31 | uint LOTKeyPath::nextDepth(const std::string key, uint depth) |
| 32 | { |
| 33 | if (skip(key)) { |
| 34 | // If it's a container then we added programatically and it isn't a part |
| 35 | // of the keypath. |
| 36 | return depth; |
| 37 | } |
| 38 | if (mKeys[depth] != "**") { |
| 39 | // If it's not a globstar then it is part of the keypath. |
| 40 | return depth + 1; |
| 41 | } |
| 42 | if (depth == size()) { |
| 43 | // The last key is a globstar. |
| 44 | return depth; |
| 45 | } |
| 46 | if (mKeys[depth + 1] == key) { |
| 47 | // We are a globstar and the next key is our current key so consume |
| 48 | // both. |
| 49 | return depth + 2; |
| 50 | } |
| 51 | return depth; |
| 52 | } |
| 53 |
| 54 | bool LOTKeyPath::fullyResolvesTo(const std::string key, uint depth) |
| 55 | { |
| 56 | if (depth > mKeys.size()) { |
| 57 | return false; |
| 58 | } |
| 59 |
| 60 | bool isLastDepth = (depth == size()); |
| 61 |
| 62 | if (!isGlobstar(depth)) { |
| 63 | bool matches = (mKeys[depth] == key) || isGlob(depth); |
| 64 | return (isLastDepth || (depth == size() - 1 && endsWithGlobstar())) && |
| 65 | matches; |
| 66 | } |
| 67 |
| 68 | bool isGlobstarButNextKeyMatches = !isLastDepth && mKeys[depth + 1] == key; |
| 69 | if (isGlobstarButNextKeyMatches) { |
| 70 | return depth == size() - 1 || |
| 71 | (depth == size() - 2 && endsWithGlobstar()); |
| 72 | } |
| 73 |
| 74 | if (isLastDepth) { |
| 75 | return true; |
| 76 | } |
| 77 |
| 78 | if (depth + 1 < size()) { |
| 79 | // We are a globstar but there is more than 1 key after the globstar we |
| 80 | // we can't fully match. |
| 81 | return false; |
| 82 | } |
| 83 | // Return whether the next key (which we now know is the last one) is the |
| 84 | // same as the current key. |
| 85 | return mKeys[depth + 1] == key; |
| 86 | } |
| 87 |