blob: a1ae322838365f05ca044c76e02c34bcc9cddd39 [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_TOP_MATCHER_HPP
16#define NDN_UTIL_REGEX_REGEX_TOP_MATCHER_HPP
Yingdi Yu5e974202014-01-29 16:59:06 -080017
Alexander Afanasyev36b84cf2014-02-17 19:34:18 -080018#include "../../common.hpp"
Yingdi Yu5e974202014-01-29 16:59:06 -080019
20#include "regex-matcher.hpp"
Yingdi Yu5e974202014-01-29 16:59:06 -080021
Alexander Afanasyev36b84cf2014-02-17 19:34:18 -080022namespace ndn {
23
24class RegexPatternListMatcher;
25class RegexBackrefManager;
26
Yingdi Yu5e974202014-01-29 16:59:06 -080027class RegexTopMatcher: public RegexMatcher
28{
29public:
Yingdi Yu48e8c0c2014-03-19 12:01:55 -070030 RegexTopMatcher(const std::string& expr, const std::string& expand = "");
31
Alexander Afanasyev36b84cf2014-02-17 19:34:18 -080032 virtual
33 ~RegexTopMatcher();
Yingdi Yu5e974202014-01-29 16:59:06 -080034
Yingdi Yu48e8c0c2014-03-19 12:01:55 -070035 bool
Alexander Afanasyev36b84cf2014-02-17 19:34:18 -080036 match(const Name& name);
Yingdi Yu5e974202014-01-29 16:59:06 -080037
38 virtual bool
Yingdi Yu48e8c0c2014-03-19 12:01:55 -070039 match(const Name& name, const int& offset, const int& length);
Yingdi Yu5e974202014-01-29 16:59:06 -080040
Yingdi Yu48e8c0c2014-03-19 12:01:55 -070041 virtual Name
42 expand(const std::string& expand = "");
Yingdi Yu5e974202014-01-29 16:59:06 -080043
Alexander Afanasyev36b84cf2014-02-17 19:34:18 -080044 static shared_ptr<RegexTopMatcher>
Yingdi Yu5e974202014-01-29 16:59:06 -080045 fromName(const Name& name, bool hasAnchor=false);
46
47protected:
Yingdi Yu48e8c0c2014-03-19 12:01:55 -070048 virtual void
Yingdi Yu5e974202014-01-29 16:59:06 -080049 compile();
50
51private:
52 std::string
Alexander Afanasyev1dd95c52014-03-22 19:11:36 -070053 getItemFromExpand(const std::string& expand, size_t& offset);
Yingdi Yu5e974202014-01-29 16:59:06 -080054
55 static std::string
56 convertSpecialChar(const std::string& str);
57
58private:
59 const std::string m_expand;
Alexander Afanasyev36b84cf2014-02-17 19:34:18 -080060 shared_ptr<RegexPatternListMatcher> m_primaryMatcher;
61 shared_ptr<RegexPatternListMatcher> m_secondaryMatcher;
62 shared_ptr<RegexBackrefManager> m_primaryBackRefManager;
63 shared_ptr<RegexBackrefManager> m_secondaryBackRefManager;
Yingdi Yu5e974202014-01-29 16:59:06 -080064 bool m_secondaryUsed;
65};
66
Alexander Afanasyev36b84cf2014-02-17 19:34:18 -080067} // namespace ndn
Yingdi Yu5e974202014-01-29 16:59:06 -080068
Alexander Afanasyev36b84cf2014-02-17 19:34:18 -080069#endif // NDN_UTIL_REGEX_REGEX_TOP_MATCHER_HPP