Esempio n. 1
0
std::string build_path(const_inspection_branch_t main, const_inspection_branch_t current)
{
#if !BOOST_WINDOWS
    using std::isalpha;
#endif

    std::vector<std::string> result_set;

    result_set.reserve(10);

    while (true)
    {
        std::string path_segment;
        bool        is_array_element(current->get_flag(is_array_element_k));

        if (is_array_element)
        {
            boost::uint64_t index(node_value(current, ARRAY_ELEMENT_VALUE_INDEX));

            // REVISIT (fbrereto) : String concatenation here.
            path_segment += "[" + boost::lexical_cast<std::string>(index) + "]";
        }
        else
        {
            adobe::name_t name(node_property(current, NODE_PROPERTY_NAME));

            if (name)
                path_segment = name.c_str();
        }

        if (!path_segment.empty())
            result_set.push_back(path_segment);

        current.edge() = adobe::forest_leading_edge;

        if (current == main)
            break;

        current = adobe::find_parent(current);
    }

    std::string result;
    bool        first(true);

    for (std::vector<std::string>::reverse_iterator iter(result_set.rbegin()), last(result_set.rend()); iter != last; ++iter)
    {
        if (!first && isalpha((*iter)[0]))
            result += ".";

        result += *iter;

        first = false;
    }

    return result;
}
Esempio n. 2
0
inline const_inspection_branch_t property_node_for(const_inspection_branch_t branch) {
    return branch->get_flag(is_array_element_k) ? property_node_for(adobe::find_parent(branch)) :
                                                  branch;
}