From 9e91bd01603a27abf218280ad4f300ad44909352 Mon Sep 17 00:00:00 2001 From: Jinhao Date: Fri, 19 Apr 2019 02:07:47 +0800 Subject: [PATCH] recover the behavior of treebox path which starts with separater(#422) --- include/nana/gui/widgets/detail/tree_cont.hpp | 67 ++++++++++--------- 1 file changed, 37 insertions(+), 30 deletions(-) diff --git a/include/nana/gui/widgets/detail/tree_cont.hpp b/include/nana/gui/widgets/detail/tree_cont.hpp index 3aa3b4f9..e2373bb5 100644 --- a/include/nana/gui/widgets/detail/tree_cont.hpp +++ b/include/nana/gui/widgets/detail/tree_cont.hpp @@ -1,6 +1,6 @@ /* * A Tree Container class implementation - * Copyright(C) 2003-2018 Jinhao(cnjinhao@hotmail.com) + * Copyright(C) 2003-2019 Jinhao(cnjinhao@hotmail.com) * * Distributed under the Boost Software License, Version 1.0. * (See accompanying file LICENSE_1_0.txt or copy at @@ -193,6 +193,11 @@ namespace detail node_type* insert(const std::string& key, const element_type& elem) { auto node = _m_locate(key); + + //Doesn't return the root node + if (node == &root_) + return nullptr; + if(node) node->value.second = elem; return node; @@ -206,12 +211,14 @@ namespace detail node_type* find(const std::string& path) const { - return _m_locate(path); + auto p = _m_locate(path); + return (&root_ == p ? nullptr : p); } node_type* ref(const std::string& path) { - return _m_locate(path); + auto p = _m_locate(path); + return (&root_ == p ? nullptr : p); } unsigned indent_size(const node_type* node) const @@ -479,42 +486,42 @@ namespace detail return nullptr; } - // foreach elements of key. - // the root name "/" and "\\" are treated as a node. This is a feature that can easily support the UNIX-like path. template void _m_for_each(const ::std::string& key, Function function) const { - if(key.size()) + //Ignores separaters at the begin of key. + ::std::string::size_type beg = key.find_first_not_of("\\/"); + if (key.npos == beg) + return; + + auto end = key.find_first_of("\\/", beg); + + + while(end != ::std::string::npos) { - ::std::string::size_type beg = 0; - auto end = key.find_first_of("\\/"); - - while(end != ::std::string::npos) + if(beg != end) { - if(beg != end) - { - if(!function(key.substr(beg, end - beg))) - return; - } - - auto next = key.find_first_not_of("\\/", end); - - if ((next == ::std::string::npos) && end) + if(!function(key.substr(beg, end - beg))) return; - - if (0 == end) - { - if ((!function(key.substr(0, 1))) || (next == ::std::string::npos)) - return; - } - - beg = next; - end = key.find_first_of("\\/", beg); - } - function(key.substr(beg, key.size() - beg)); + auto next = key.find_first_not_of("\\/", end); + + if ((next == ::std::string::npos) && end) + return; + + if (0 == end) + { + if ((!function(key.substr(0, 1))) || (next == ::std::string::npos)) + return; + } + + beg = next; + end = key.find_first_of("\\/", beg); + } + + function(key.substr(beg, key.size() - beg)); } template