blob: 08c101cf84b67e8c3be7ca928ff6f575a5b7c887 [file] [log] [blame]
Yingdi Yu5e974202014-01-29 16:59:06 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
2/**
Alexander Afanasyevdfa52c42014-04-24 21:10:11 -07003 * Copyright (c) 2013-2014, Regents of the University of California.
4 * All rights reserved.
5 *
6 * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
7 * See AUTHORS.md for complete list of ndn-cxx authors and contributors.
8 *
9 * This file licensed under New BSD License. See COPYING for detailed information about
10 * ndn-cxx library copyright, permissions, and redistribution restrictions.
11 *
12 * @author Yingdi Yu <http://irl.cs.ucla.edu/~yingdi/>
Yingdi Yu5e974202014-01-29 16:59:06 -080013 */
14
Alexander Afanasyev36b84cf2014-02-17 19:34:18 -080015#ifndef NDN_UTIL_REGEX_REGEX_BACKREF_MATCHER_HPP
16#define NDN_UTIL_REGEX_REGEX_BACKREF_MATCHER_HPP
17
18#include "../../common.hpp"
Yingdi Yu5e974202014-01-29 16:59:06 -080019
20#include "regex-matcher.hpp"
21
Alexander Afanasyev36b84cf2014-02-17 19:34:18 -080022namespace ndn {
Yingdi Yu5e974202014-01-29 16:59:06 -080023
24class RegexBackrefMatcher : public RegexMatcher
25{
26public:
Alexander Afanasyevb6b21b32014-04-28 22:38:03 -070027 RegexBackrefMatcher(const std::string& expr, shared_ptr<RegexBackrefManager> backrefManager);
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070028
Alexander Afanasyevb6b21b32014-04-28 22:38:03 -070029 virtual
30 ~RegexBackrefMatcher()
31 {
32 }
Yingdi Yu5e974202014-01-29 16:59:06 -080033
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070034 void
Yingdi Yu5e974202014-01-29 16:59:06 -080035 lateCompile()
36 {
37 compile();
38 }
39
40protected:
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070041 virtual void
Yingdi Yu5e974202014-01-29 16:59:06 -080042 compile();
Yingdi Yu5e974202014-01-29 16:59:06 -080043};
44
Alexander Afanasyev36b84cf2014-02-17 19:34:18 -080045} // namespace ndn
Yingdi Yu5e974202014-01-29 16:59:06 -080046
Alexander Afanasyev36b84cf2014-02-17 19:34:18 -080047#include "regex-pattern-list-matcher.hpp"
48
49namespace ndn {
50
Alexander Afanasyevb6b21b32014-04-28 22:38:03 -070051inline
52RegexBackrefMatcher::RegexBackrefMatcher(const std::string& expr,
53 shared_ptr<RegexBackrefManager> backrefManager)
54 : RegexMatcher(expr, EXPR_BACKREF, backrefManager)
Alexander Afanasyev36b84cf2014-02-17 19:34:18 -080055{
56 // compile();
57}
58
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070059inline void
Alexander Afanasyev36b84cf2014-02-17 19:34:18 -080060RegexBackrefMatcher::compile()
61{
Alexander Afanasyevb6b21b32014-04-28 22:38:03 -070062 if (m_expr.size() < 2)
63 throw RegexMatcher::Error("Unrecognized format: " + m_expr);
64
65 size_t lastIndex = m_expr.size() - 1;
66 if ('(' == m_expr[0] && ')' == m_expr[lastIndex]) {
Alexander Afanasyev36b84cf2014-02-17 19:34:18 -080067 // m_backRefManager->pushRef(this);
68
Alexander Afanasyevdfa52c42014-04-24 21:10:11 -070069 shared_ptr<RegexMatcher> matcher(new RegexPatternListMatcher(m_expr.substr(1, lastIndex - 1),
70 m_backrefManager));
Alexander Afanasyevb6b21b32014-04-28 22:38:03 -070071 m_matchers.push_back(matcher);
Alexander Afanasyev36b84cf2014-02-17 19:34:18 -080072 }
73 else
Alexander Afanasyevb6b21b32014-04-28 22:38:03 -070074 throw RegexMatcher::Error("Unrecognized format: " + m_expr);
Alexander Afanasyev36b84cf2014-02-17 19:34:18 -080075}
76
77
78} // namespace ndn
79
80#endif // NDN_UTIL_REGEX_REGEX_BACKREF_MATCHER_HPP