NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.5: NDN, CCN, CCNx, content centric networks
API Documentation
regex-component-matcher.cpp
Go to the documentation of this file.
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
* Copyright (c) 2013-2017 Regents of the University of California.
4
*
5
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
6
*
7
* ndn-cxx library is free software: you can redistribute it and/or modify it under the
8
* terms of the GNU Lesser General Public License as published by the Free Software
9
* Foundation, either version 3 of the License, or (at your option) any later version.
10
*
11
* ndn-cxx library is distributed in the hope that it will be useful, but WITHOUT ANY
12
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
13
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
14
*
15
* You should have received copies of the GNU General Public License and GNU Lesser
16
* General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see
17
* <http://www.gnu.org/licenses/>.
18
*
19
* See AUTHORS.md for complete list of ndn-cxx authors and contributors.
20
*
21
* @author Yingdi Yu <http://irl.cs.ucla.edu/~yingdi/>
22
*/
23
24
#include "
regex-component-matcher.hpp
"
25
#include "
regex-pseudo-matcher.hpp
"
26
27
namespace
ndn
{
28
29
// Re: http://www.boost.org/users/history/version_1_56_0.html
30
//
31
// Breaking change: corrected behavior of basic_regex<>::mark_count() to match existing
32
// documentation, basic_regex<>::subexpression(n) changed to match, see
33
// https://svn.boost.org/trac/boost/ticket/9227
34
//
35
static
constexpr
size_t
BOOST_REGEXP_MARK_COUNT_CORRECTION
=
36
#if BOOST_VERSION < 105600
37
1;
38
#else
39
0;
40
#endif
41
42
RegexComponentMatcher::RegexComponentMatcher
(
const
std::string& expr,
43
shared_ptr<RegexBackrefManager> backrefManager,
44
bool
isExactMatch)
45
:
RegexMatcher
(expr, EXPR_COMPONENT,
std
::move(backrefManager))
46
, m_isExactMatch(isExactMatch)
47
{
48
compile
();
49
}
50
51
void
52
RegexComponentMatcher::compile
()
53
{
54
m_componentRegex = boost::regex(
m_expr
);
55
56
m_pseudoMatchers.clear();
57
m_pseudoMatchers.push_back(make_shared<RegexPseudoMatcher>());
58
59
for
(
size_t
i = 1; i <= m_componentRegex.mark_count() -
BOOST_REGEXP_MARK_COUNT_CORRECTION
; i++) {
60
m_pseudoMatchers.push_back(make_shared<RegexPseudoMatcher>());
61
m_backrefManager
->pushRef(m_pseudoMatchers.back());
62
}
63
}
64
65
bool
66
RegexComponentMatcher::match
(
const
Name
&
name
,
size_t
offset,
size_t
len)
67
{
68
m_matchResult
.clear();
69
70
if
(
m_expr
.empty()) {
71
m_matchResult
.push_back(
name
.get(offset));
72
return
true
;
73
}
74
75
if
(!m_isExactMatch)
76
BOOST_THROW_EXCEPTION(
Error
(
"Non-exact component search is not supported yet"
));
77
78
boost::smatch subResult;
79
std::string targetStr =
name
.get(offset).toUri();
80
if
(boost::regex_match(targetStr, subResult, m_componentRegex)) {
81
for
(
size_t
i = 1; i <= m_componentRegex.mark_count() -
BOOST_REGEXP_MARK_COUNT_CORRECTION
; i++) {
82
m_pseudoMatchers[i]->resetMatchResult();
83
m_pseudoMatchers[i]->setMatchResult(subResult[i]);
84
}
85
m_matchResult
.push_back(
name
.get(offset));
86
return
true
;
87
}
88
89
return
false
;
90
}
91
92
}
// namespace ndn
ndn
Copyright (c) 2011-2015 Regents of the University of California.
Definition:
ndn-strategy-choice-helper.hpp:34
ndn::RegexComponentMatcher::match
bool match(const Name &name, size_t offset, size_t len=1) override
Definition:
regex-component-matcher.cpp:66
ndn::RegexComponentMatcher::RegexComponentMatcher
RegexComponentMatcher(const std::string &expr, shared_ptr< RegexBackrefManager > backrefManager, bool isExactMatch=true)
Create a RegexComponent matcher from expr.
Definition:
regex-component-matcher.cpp:42
std
STL namespace.
regex-pseudo-matcher.hpp
ndn::RegexMatcher::m_backrefManager
shared_ptr< RegexBackrefManager > m_backrefManager
Definition:
regex-matcher.hpp:94
ndn::RegexMatcher::m_matchResult
std::vector< name::Component > m_matchResult
Definition:
regex-matcher.hpp:96
ndn::Name
Represents an absolute name.
Definition:
name.hpp:42
ndn::RegexMatcher::m_expr
const std::string m_expr
Definition:
regex-matcher.hpp:92
ndn::BOOST_REGEXP_MARK_COUNT_CORRECTION
static constexpr size_t BOOST_REGEXP_MARK_COUNT_CORRECTION
Definition:
regex-component-matcher.cpp:35
ndn::RegexMatcher::Error
Definition:
regex-matcher.hpp:35
regex-component-matcher.hpp
ndn::RegexComponentMatcher::compile
void compile() override
Compile the regular expression to generate the more matchers when necessary.
Definition:
regex-component-matcher.cpp:52
ndn::name
Definition:
name-component.cpp:37
ndn::RegexMatcher
Definition:
regex-matcher.hpp:32
ndnSIM
ndn-cxx
src
util
regex
regex-component-matcher.cpp
Generated on Tue Aug 7 2018 16:19:17 for ndnSIM by
1.8.14