"Fossies" - the Fresh Open Source Software Archive

Member "cb2bib-2.0.1/src/c2b/wordPattern.h" (12 Feb 2021, 1838 Bytes) of package /linux/privat/cb2bib-2.0.1.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 "wordPattern.h" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes report: 2.0.0_vs_2.0.1.

    1 /***************************************************************************
    2  *   Copyright (C) 2004-2021 by Pere Constans
    3  *   constans@molspaces.com
    4  *   cb2Bib version 2.0.1. Licensed under the GNU GPL version 3.
    5  *   See the LICENSE file that comes with this distribution.
    6  ***************************************************************************/
    7 #ifndef WORDPATTERN_H
    8 #define WORDPATTERN_H
    9 
   10 #include "compositePattern.h"
   11 
   12 #include "txtmatcher.h"
   13 
   14 
   15 class wordPattern : public compositePattern
   16 {
   17 
   18 public:
   19     enum Type
   20     {
   21         AllWords,
   22         AnyWord
   23     };
   24 
   25     wordPattern();
   26     wordPattern(const QString& pattern, const Type type, const Qt::CaseSensitivity cs);
   27     inline ~wordPattern() {}
   28 
   29 
   30     void setPattern(const QString& pattern, const Type type, const Qt::CaseSensitivity cs = Qt::CaseSensitive);
   31 
   32     inline bool matches(const QString& str) const override
   33     {
   34         _matched_length = -1;
   35         if (str.length() == 0)
   36             return false;
   37         if (_type == AllWords)
   38         {
   39             for (int i = _subpattern_count - 1; i >= 0; --i)
   40                 if (_submatchers.at(i).indexIn(str) == -1)
   41                     return false;
   42             return true;
   43         }
   44         else
   45         {
   46             for (int i = 0; i < _subpattern_count; ++i)
   47                 if (_submatchers.at(i).indexIn(str) != -1)
   48                     return true;
   49             return false;
   50         }
   51     }
   52     inline int indexIn(const QString& str, const int from = 0) const override
   53     {
   54         const QRegularExpressionMatch rem(_regexp.match(str, from));
   55         _matched_length = rem.capturedLength();
   56         return rem.capturedStart();
   57     }
   58     inline const QVector<txtmatcher>& submatchers() const
   59     {
   60         return _submatchers;
   61     }
   62 
   63 
   64 private:
   65     QVector<txtmatcher> _submatchers;
   66     Type _type;
   67 };
   68 
   69 #endif