Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */ |
| 2 | /** |
Alexander Afanasyev | dfa52c4 | 2014-04-24 21:10:11 -0700 | [diff] [blame] | 3 | * 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 Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 13 | */ |
| 14 | |
Alexander Afanasyev | 36b84cf | 2014-02-17 19:34:18 -0800 | [diff] [blame] | 15 | #ifndef NDN_UTIL_REGEX_REGEX_BACKREF_MATCHER_HPP |
| 16 | #define NDN_UTIL_REGEX_REGEX_BACKREF_MATCHER_HPP |
| 17 | |
| 18 | #include "../../common.hpp" |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 19 | |
| 20 | #include "regex-matcher.hpp" |
| 21 | |
Alexander Afanasyev | 36b84cf | 2014-02-17 19:34:18 -0800 | [diff] [blame] | 22 | namespace ndn { |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 23 | |
| 24 | class RegexBackrefMatcher : public RegexMatcher |
| 25 | { |
| 26 | public: |
Alexander Afanasyev | b6b21b3 | 2014-04-28 22:38:03 -0700 | [diff] [blame] | 27 | RegexBackrefMatcher(const std::string& expr, shared_ptr<RegexBackrefManager> backrefManager); |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 28 | |
Alexander Afanasyev | b6b21b3 | 2014-04-28 22:38:03 -0700 | [diff] [blame] | 29 | virtual |
| 30 | ~RegexBackrefMatcher() |
| 31 | { |
| 32 | } |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 33 | |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 34 | void |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 35 | lateCompile() |
| 36 | { |
| 37 | compile(); |
| 38 | } |
| 39 | |
| 40 | protected: |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 41 | virtual void |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 42 | compile(); |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 43 | }; |
| 44 | |
Alexander Afanasyev | 36b84cf | 2014-02-17 19:34:18 -0800 | [diff] [blame] | 45 | } // namespace ndn |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 46 | |
Alexander Afanasyev | 36b84cf | 2014-02-17 19:34:18 -0800 | [diff] [blame] | 47 | #include "regex-pattern-list-matcher.hpp" |
| 48 | |
| 49 | namespace ndn { |
| 50 | |
Alexander Afanasyev | b6b21b3 | 2014-04-28 22:38:03 -0700 | [diff] [blame] | 51 | inline |
| 52 | RegexBackrefMatcher::RegexBackrefMatcher(const std::string& expr, |
| 53 | shared_ptr<RegexBackrefManager> backrefManager) |
| 54 | : RegexMatcher(expr, EXPR_BACKREF, backrefManager) |
Alexander Afanasyev | 36b84cf | 2014-02-17 19:34:18 -0800 | [diff] [blame] | 55 | { |
| 56 | // compile(); |
| 57 | } |
| 58 | |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 59 | inline void |
Alexander Afanasyev | 36b84cf | 2014-02-17 19:34:18 -0800 | [diff] [blame] | 60 | RegexBackrefMatcher::compile() |
| 61 | { |
Alexander Afanasyev | b6b21b3 | 2014-04-28 22:38:03 -0700 | [diff] [blame] | 62 | 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 Afanasyev | 36b84cf | 2014-02-17 19:34:18 -0800 | [diff] [blame] | 67 | // m_backRefManager->pushRef(this); |
| 68 | |
Alexander Afanasyev | dfa52c4 | 2014-04-24 21:10:11 -0700 | [diff] [blame] | 69 | shared_ptr<RegexMatcher> matcher(new RegexPatternListMatcher(m_expr.substr(1, lastIndex - 1), |
| 70 | m_backrefManager)); |
Alexander Afanasyev | b6b21b3 | 2014-04-28 22:38:03 -0700 | [diff] [blame] | 71 | m_matchers.push_back(matcher); |
Alexander Afanasyev | 36b84cf | 2014-02-17 19:34:18 -0800 | [diff] [blame] | 72 | } |
| 73 | else |
Alexander Afanasyev | b6b21b3 | 2014-04-28 22:38:03 -0700 | [diff] [blame] | 74 | throw RegexMatcher::Error("Unrecognized format: " + m_expr); |
Alexander Afanasyev | 36b84cf | 2014-02-17 19:34:18 -0800 | [diff] [blame] | 75 | } |
| 76 | |
| 77 | |
| 78 | } // namespace ndn |
| 79 | |
| 80 | #endif // NDN_UTIL_REGEX_REGEX_BACKREF_MATCHER_HPP |