"Fossies" - the Fresh Open Source Software Archive

Member "recoll-1.26.3/utils/strmatcher.h" (4 Sep 2019, 2560 Bytes) of package /linux/privat/recoll-1.26.3.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "strmatcher.h" see the Fossies "Dox" file reference documentation.

    1 /* Copyright (C) 2012 J.F.Dockes
    2  *   This program is free software; you can redistribute it and/or modify
    3  *   it under the terms of the GNU General Public License as published by
    4  *   the Free Software Foundation; either version 2 of the License, or
    5  *   (at your option) any later version.
    6  *
    7  *   This program is distributed in the hope that it will be useful,
    8  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
    9  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   10  *   GNU General Public License for more details.
   11  *
   12  *   You should have received a copy of the GNU General Public License
   13  *   along with this program; if not, write to the
   14  *   Free Software Foundation, Inc.,
   15  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
   16  */
   17 #ifndef _STRMATCHER_H_INCLUDED_
   18 #define _STRMATCHER_H_INCLUDED_
   19 
   20 #include <string>
   21 #include "smallut.h"
   22 
   23 // Encapsulating simple wildcard/regexp string matching.
   24 
   25 // Matcher class. Interface to either wildcard or regexp yes/no matcher
   26 class StrMatcher {
   27 public:
   28     StrMatcher(const std::string& exp) 
   29         : m_sexp(exp) {}
   30     virtual ~StrMatcher() {};
   31     virtual bool match(const std::string &val) const = 0;
   32     virtual std::string::size_type baseprefixlen() const = 0;
   33     virtual bool setExp(const std::string& newexp) {
   34     m_sexp = newexp;
   35     return true;
   36     }
   37     virtual bool ok() const {
   38     return true;
   39     }
   40     virtual const std::string& exp() const {
   41     return m_sexp;
   42     }
   43     virtual StrMatcher *clone() const = 0;
   44     const std::string& getreason() const {
   45     return m_reason;
   46     }
   47 protected:
   48     std::string m_sexp;
   49     std::string m_reason;
   50 };
   51 
   52 class StrWildMatcher : public StrMatcher {
   53 public:
   54     StrWildMatcher(const std::string& exp)
   55         : StrMatcher(exp) {}
   56     virtual ~StrWildMatcher() {}
   57     virtual bool match(const std::string& val) const override;
   58     virtual std::string::size_type baseprefixlen() const override;
   59     virtual StrWildMatcher *clone() const override {
   60     return new StrWildMatcher(m_sexp);
   61     }
   62 };
   63 
   64 class StrRegexpMatcher : public StrMatcher {
   65 public:
   66     StrRegexpMatcher(const std::string& exp);
   67     virtual bool setExp(const std::string& newexp) override;
   68     virtual ~StrRegexpMatcher() {};
   69     virtual bool match(const std::string& val) const override;
   70     virtual std::string::size_type baseprefixlen() const override;
   71     virtual bool ok() const override;
   72     virtual StrRegexpMatcher *clone() const override {
   73     return new StrRegexpMatcher(m_sexp);
   74     }
   75 private:
   76     SimpleRegexp m_re;
   77 };
   78 
   79 #endif /* _STRMATCHER_H_INCLUDED_ */