2 * Copyright (c) 2019 The Regents of the University of California
3 * Copyright (c) 2004-2005 The Regents of The University of Michigan
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are
8 * met: redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer;
10 * redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution;
13 * neither the name of the copyright holders nor the names of its
14 * contributors may be used to endorse or promote products derived from
15 * this software without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 #include "base/match.hh"
32 #include "base/str.hh"
36 ObjectMatch::ObjectMatch()
40 ObjectMatch::ObjectMatch(const string
&expr
)
46 ObjectMatch::add(const ObjectMatch
&other
)
48 tokens
.insert(tokens
.end(), other
.tokens
.begin(), other
.tokens
.end());
52 ObjectMatch::setExpression(const string
&expr
)
55 tokenize(tokens
[0], expr
, '.');
59 ObjectMatch::setExpression(const vector
<string
> &expr
)
64 tokens
.resize(expr
.size());
65 for (vector
<string
>::size_type i
= 0; i
< expr
.size(); ++i
)
66 tokenize(tokens
[i
], expr
[i
], '.');
71 * @todo this should probably be changed to just use regular
75 ObjectMatch::domatch(const string
&name
) const
77 vector
<string
> name_tokens
;
78 tokenize(name_tokens
, name
, '.');
79 int ntsize
= name_tokens
.size();
81 int num_expr
= tokens
.size();
82 for (int i
= 0; i
< num_expr
; ++i
) {
83 const vector
<string
> &token
= tokens
[i
];
84 int jstop
= token
.size();
87 for (int j
= 0; j
< jstop
; ++j
) {
91 const string
&var
= token
[j
];
92 if (var
!= "*" && var
!= name_tokens
[j
]) {
105 std::vector
<std::vector
<std::string
> >
106 ObjectMatch::getExpressions()
108 std::vector
<std::vector
<std::string
> > to_return
;
109 for (const auto &expression
: tokens
) {
110 std::vector
<std::string
> to_add
;
111 to_add
.insert(to_add
.end(), expression
.begin(), expression
.end());
112 to_return
.push_back(to_add
);