~autopilot/xpathselect/1.4

« back to all changes in this revision

Viewing changes to lib/xpathquerypart.h

  • Committer: Tarmac
  • Author(s): Christopher Lee, Thomi Richards
  • Date: 2013-04-25 09:42:38 UTC
  • mfrom: (33.1.6 parser-rejig)
  • Revision ID: tarmac-20130425094238-drswy0ypbnp6n389
Update parser to allow spaces in object names, spaces and periods in param values, and fix several other bugs in the parser. Fixes: https://bugs.launchpad.net/bugs/1150276.

Approved by Christopher Lee, Allan LeSage, PS Jenkins bot.

Show diffs side-by-side

added added

removed removed

Lines of Context:
35
35
        std::string param_value;
36
36
    };
37
37
 
 
38
    typedef std::vector<XPathQueryParam> ParamList;
 
39
 
38
40
    // Stores a part of an XPath query.
39
41
    struct XPathQueryPart
40
42
    {
41
43
    public:
 
44
        XPathQueryPart() {}
 
45
        XPathQueryPart(std::string node_name)
 
46
        : node_name_(node_name)
 
47
        {}
 
48
 
42
49
        enum class QueryPartType {Normal, Search};
43
50
 
44
51
        bool Matches(Node::Ptr const& node) const
45
52
        {
46
53
            bool matches = (node_name_ == "*" || node->GetName() == node_name_);
47
 
            if (parameter)
 
54
            if (!parameter.empty())
48
55
            {
49
 
                matches &= node->MatchProperty(parameter->param_name, parameter->param_value);
 
56
                for (auto param : parameter)
 
57
                {
 
58
                    matches &= node->MatchProperty(param.param_name, param.param_value);
 
59
 
 
60
                }
50
61
            }
51
62
 
52
63
            return matches;
54
65
 
55
66
        QueryPartType Type() const { return (node_name_ == "") ? QueryPartType::Search :  QueryPartType::Normal; }
56
67
 
 
68
        void Dump() const
 
69
        {
 
70
            if (Type() == QueryPartType::Search)
 
71
                std::cout << "<search> ";
 
72
            else
 
73
                std::cout << "[" << node_name_ << "] ";
 
74
        }
 
75
 
57
76
        std::string node_name_;
58
 
        boost::optional<XPathQueryParam> parameter;
 
77
        ParamList parameter;
59
78
    };
60
79
 
61
80