不一致的地方:
- 注释中提到`…`放在字符串尾可以让搜索从父节点开始,实际判断的是`/…`
- 注释中说明添加后从父节点开始搜索,代码实现却是从孙子节点搜索。
例:
场景树:scene - node1 - node2 - node3(从左到右父子关系, name和变量名相同)
node1-> enumerateChildren("[[:alnum:]]+..", [](Node* node){ log("%s", node->getName().c_str()); return false; });
根据注释,此时应该输出scene(搜索移动到父节点),实际无输出
根据代码,将条件改为"[[:alnum:]]+/…",此时应该输出scene,实际输出node3(实际搜索孙子节点)
注释:
`…`: The search should move up to the node’s parent. Can only be placed at the end of string.
代码:
// End with '/..'? bool searchFromParent = false; if (length > 3 && name[length-3] == '/' && name[length-2] == '.' && name[length-1] == '.') { searchFromParent = true; subStrlength -= 3; } // Remove '//', '/..' if exist std::string newName = name.substr(subStrStartPos, subStrlength); if (searchFromParent) { //虽然写是从父节点查找,但是这里添加的是跳过子节点,然后就从孙子节点查找了 newName.insert(0, "[[:alnum:]]+/"); }
不知道是我的理解有误还是文档/代码有误,希望能解答一下