blob: f5b30c134bbf660cf3c2570263dfd5b849fd961e [file] [log] [blame]
Yingdi Yu5e974202014-01-29 16:59:06 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
2/**
3 * Copyright (C) 2013 Regents of the University of California.
4 * @author: Yingdi Yu <yingdi@cs.ucla.edu>
5 * See COPYING for copyright and distribution information.
6 */
7
Alexander Afanasyev36b84cf2014-02-17 19:34:18 -08008#ifndef NDN_UTIL_REGEX_REGEX_TOP_MATCHER_HPP
9#define NDN_UTIL_REGEX_REGEX_TOP_MATCHER_HPP
Yingdi Yu5e974202014-01-29 16:59:06 -080010
Alexander Afanasyev36b84cf2014-02-17 19:34:18 -080011#include "../../common.hpp"
Yingdi Yu5e974202014-01-29 16:59:06 -080012
13#include "regex-matcher.hpp"
Yingdi Yu5e974202014-01-29 16:59:06 -080014
Alexander Afanasyev36b84cf2014-02-17 19:34:18 -080015namespace ndn {
16
17class RegexPatternListMatcher;
18class RegexBackrefManager;
19
Yingdi Yu5e974202014-01-29 16:59:06 -080020class RegexTopMatcher: public RegexMatcher
21{
22public:
Yingdi Yu48e8c0c2014-03-19 12:01:55 -070023 RegexTopMatcher(const std::string& expr, const std::string& expand = "");
24
Alexander Afanasyev36b84cf2014-02-17 19:34:18 -080025 virtual
26 ~RegexTopMatcher();
Yingdi Yu5e974202014-01-29 16:59:06 -080027
Yingdi Yu48e8c0c2014-03-19 12:01:55 -070028 bool
Alexander Afanasyev36b84cf2014-02-17 19:34:18 -080029 match(const Name& name);
Yingdi Yu5e974202014-01-29 16:59:06 -080030
31 virtual bool
Yingdi Yu48e8c0c2014-03-19 12:01:55 -070032 match(const Name& name, const int& offset, const int& length);
Yingdi Yu5e974202014-01-29 16:59:06 -080033
Yingdi Yu48e8c0c2014-03-19 12:01:55 -070034 virtual Name
35 expand(const std::string& expand = "");
Yingdi Yu5e974202014-01-29 16:59:06 -080036
Alexander Afanasyev36b84cf2014-02-17 19:34:18 -080037 static shared_ptr<RegexTopMatcher>
Yingdi Yu5e974202014-01-29 16:59:06 -080038 fromName(const Name& name, bool hasAnchor=false);
39
40protected:
Yingdi Yu48e8c0c2014-03-19 12:01:55 -070041 virtual void
Yingdi Yu5e974202014-01-29 16:59:06 -080042 compile();
43
44private:
45 std::string
Alexander Afanasyev1dd95c52014-03-22 19:11:36 -070046 getItemFromExpand(const std::string& expand, size_t& offset);
Yingdi Yu5e974202014-01-29 16:59:06 -080047
48 static std::string
49 convertSpecialChar(const std::string& str);
50
51private:
52 const std::string m_expand;
Alexander Afanasyev36b84cf2014-02-17 19:34:18 -080053 shared_ptr<RegexPatternListMatcher> m_primaryMatcher;
54 shared_ptr<RegexPatternListMatcher> m_secondaryMatcher;
55 shared_ptr<RegexBackrefManager> m_primaryBackRefManager;
56 shared_ptr<RegexBackrefManager> m_secondaryBackRefManager;
Yingdi Yu5e974202014-01-29 16:59:06 -080057 bool m_secondaryUsed;
58};
59
Alexander Afanasyev36b84cf2014-02-17 19:34:18 -080060} // namespace ndn
Yingdi Yu5e974202014-01-29 16:59:06 -080061
Alexander Afanasyev36b84cf2014-02-17 19:34:18 -080062#endif // NDN_UTIL_REGEX_REGEX_TOP_MATCHER_HPP