"Fossies" - the Fresh Open Source Software Archive 
Member "cb2bib-2.0.1/src/c2b/approximatePattern.h" (12 Feb 2021, 3034 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 "approximatePattern.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 * Class implementation of the approximate search algorithm
8 * P. Constans. Approximate textual retrieval. arXiv:0705.0751, 2007.
9 ***************************************************************************/
10 #ifndef APPROXIMATEPATTERN_H
11 #define APPROXIMATEPATTERN_H
12
13 #include "compositePattern.h"
14
15 #include "substringMatcher.h"
16
17 #define C2B_DEBUG_APPROXIMATEPATTERN 0
18
19
20 class approximatePattern : public compositePattern
21 {
22
23 public:
24 approximatePattern();
25 approximatePattern(const QString& pattern, const Qt::CaseSensitivity cs);
26 inline ~approximatePattern() {}
27
28 void setPattern(const QString& pattern, const Qt::CaseSensitivity cs = Qt::CaseSensitive);
29
30 inline bool matches(const QString& str) const override
31 {
32 _matched_length = -1;
33 if (str.length() == 0)
34 return false;
35 if (_is_multipattern)
36 {
37 for (int i = 0; i < _subpattern_count; ++i)
38 if (_submatchers.at(i).indexIn(str) != -1)
39 return true;
40 return false;
41 }
42 else
43 return _regexp.match(str).hasMatch();
44 }
45 inline int indexIn(const QString& str, const int from = 0) const override
46 {
47 _matched_length = -1;
48 if (str.length() == 0)
49 return -1;
50 int index;
51 if (_is_multipattern)
52 {
53 for (int i = 0; i < _subpattern_count; ++i)
54 {
55 _p0[i] = _submatchers.at(i).indexIn(str, from);
56 _pn[i] = _p0.at(i) + _submatchers.at(i).matchedLength();
57 }
58 mergeIndices(&index, str);
59 }
60 else
61 {
62 _regexp_match = _regexp.match(str, from);
63 _matched_length = _regexp_match.capturedLength();
64 index = _regexp_match.capturedStart();
65 }
66 return index;
67 }
68 inline const QVector<substringMatcher>& submatchers() const
69 {
70 return _submatchers;
71 }
72 inline const QStringList& subpatternStrings() const
73 {
74 return _subpatterns;
75 }
76
77
78 private:
79 const QStringList splitWord(const QString& word) const;
80 int stretch(int piece_i, int piece_j) const;
81 static QString wordPattern(const QString& word, Qt::CaseSensitivity cs);
82 static int wordCount(const QString& str);
83 static void splitPattern(const QString& p, QStringList* w, QList<int>* ws, QList<int>* we);
84 void mergeIndices(int* index_in, const QString& str) const;
85 void splitPattern();
86
87 QList<int> _piece_ends;
88 QList<int> _piece_starts;
89 QStringList _prefixes;
90 QStringList _string_pieces;
91 QStringList _subpatterns;
92 QStringList _suffixes;
93 QVector<substringMatcher> _submatchers;
94 mutable QRegularExpressionMatch _regexp_match;
95 };
96
97 #endif