| 248 | } |
| 249 | |
| 250 | void PathMatcher::matchWalk( const Node *node, const NameIterator &start, const NameIterator &end, unsigned &result ) const |
| 251 | { |
| 252 | // see if we've matched to the end of the path, and terminate the recursion if we have. |
| 253 | if( start == end ) |
| 254 | { |
| 255 | if( node->terminator ) |
| 256 | { |
| 257 | result |= ExactMatch; |
| 258 | } |
| 259 | if( node->children.size() ) |
| 260 | { |
| 261 | result |= DescendantMatch; |
| 262 | } |
| 263 | if( const Node *ellipsis = node->child( g_ellipsis ) ) |
| 264 | { |
| 265 | result |= DescendantMatch; |
| 266 | if( ellipsis->terminator ) |
| 267 | { |
| 268 | result |= ExactMatch; |
| 269 | } |
| 270 | } |
| 271 | return; |
| 272 | } |
| 273 | |
| 274 | // we haven't matched to the end of the path - there are still path elements |
| 275 | // to check. if this node is a terminator then we have found an ancestor match |
| 276 | // though. |
| 277 | if( node->terminator ) |
| 278 | { |
| 279 | result |= AncestorMatch; |
| 280 | } |
| 281 | |
| 282 | // now we can match the remainder of the path against child branches to see |
| 283 | // if we have any exact or descendant matches. |
| 284 | /////////////////////////////////////////////////////////////////////////// |
| 285 | |
| 286 | // first check for a child with the exact name we're looking for. |
| 287 | // we can use the specialised Name constructor to explicitly say we're |
| 288 | // not interested in finding a child with wildcards here - this avoids |
| 289 | // a call to hasWildcards() and gives us a decent little performance boost. |
| 290 | |
| 291 | Node::ConstChildMapIterator childIt = node->children.find( Name( *start, Name::Plain ) ); |
| 292 | const Node::ConstChildMapIterator childItEnd = node->children.end(); |
| 293 | if( childIt != childItEnd ) |
| 294 | { |
| 295 | NameIterator newStart = start + 1; |
| 296 | matchWalk( childIt->second.get(), newStart, end, result ); |
| 297 | // if we've found every kind of match then we can terminate early, |
| 298 | // but otherwise we need to keep going even though we may |
| 299 | // have found some of the match types already. |
| 300 | if( result == EveryMatch ) |
| 301 | { |
| 302 | return; |
| 303 | } |
| 304 | } |
| 305 | |
| 306 | // then check all the wildcarded children to see if they might match. |
| 307 | |