wordPattern.cpp (cb2bib-2.0.0) | : | wordPattern.cpp (cb2bib-2.0.1) | ||
---|---|---|---|---|
/*************************************************************************** | /*************************************************************************** | |||
* Copyright (C) 2004-2019 by Pere Constans | * Copyright (C) 2004-2021 by Pere Constans | |||
* constans@molspaces.com | * constans@molspaces.com | |||
* cb2Bib version 2.0.0. Licensed under the GNU GPL version 3. | * cb2Bib version 2.0.1. Licensed under the GNU GPL version 3. | |||
* See the LICENSE file that comes with this distribution. | * See the LICENSE file that comes with this distribution. | |||
***************************************************************************/ | ***************************************************************************/ | |||
#include "wordPattern.h" | #include "wordPattern.h" | |||
#include "cb2bib_utilities.h" | #include "cb2bib_utilities.h" | |||
#include "triads.h" | #include "triads.h" | |||
wordPattern::wordPattern() : compositePattern(), _type(AllWords) {} | wordPattern::wordPattern() : compositePattern(), _type(AllWords) {} | |||
wordPattern::wordPattern(const QString& pattern, const Type type, const Qt::Case Sensitivity cs) | wordPattern::wordPattern(const QString& pattern, const Type type, const Qt::Case Sensitivity cs) | |||
: compositePattern(pattern, cs), _type(type) | : compositePattern(pattern, cs), _type(type) | |||
{ | { | |||
setPattern(pattern, type, cs); | setPattern(pattern, type, cs); | |||
} | } | |||
void wordPattern::setPattern(const QString& pattern, const Type type, const Qt:: CaseSensitivity cs) | void wordPattern::setPattern(const QString& pattern, const Type type, const Qt:: CaseSensitivity cs) | |||
{ | { | |||
_string = pattern.simplified(); | _string = pattern; | |||
_type = type; | _type = type; | |||
_case_sensitivity = cs; | _case_sensitivity = cs; | |||
_is_multipattern = false; | _is_multipattern = false; | |||
_matched_length = -1; | _matched_length = -1; | |||
const QStringList words(_string.split(c2bUtils::nonLetter, QString::SkipEmpt yParts)); | const QStringList words(_string.split(c2bUtils::nonLetter, QString::SkipEmpt yParts)); | |||
_subpattern_count = words.count(); | _subpattern_count = words.count(); | |||
if (_subpattern_count == 0) | if (_subpattern_count == 0) | |||
return; | return; | |||
skipping to change at line 55 | skipping to change at line 55 | |||
if (_subpattern_count == 1) | if (_subpattern_count == 1) | |||
_regexp.setPattern(escape(_string, _case_sensitivity)); | _regexp.setPattern(escape(_string, _case_sensitivity)); | |||
else | else | |||
_regexp.setPattern(QString("(?:%1)").arg(subpattern.join("|"))); | _regexp.setPattern(QString("(?:%1)").arg(subpattern.join("|"))); | |||
_submatchers.resize(_subpattern_count); | _submatchers.resize(_subpattern_count); | |||
_subregexps.resize(_subpattern_count); | _subregexps.resize(_subpattern_count); | |||
_substrings.clear(); | _substrings.clear(); | |||
for (int i = 0; i < _subpattern_count; ++i) | for (int i = 0; i < _subpattern_count; ++i) | |||
{ | { | |||
const int ii(_index.at(i)); | const int ii(_index.at(i)); | |||
_submatchers[i] = QStringMatcher(substring.at(ii), _case_sensitivity); | _submatchers[i] = txtmatcher(substring.at(ii), _case_sensitivity); | |||
_subregexps[i].setPattern(subpattern.at(ii)); | _subregexps[i].setPattern(subpattern.at(ii)); | |||
_substrings.append(substring.at(ii)); | _substrings.append(substring.at(ii)); | |||
} | } | |||
_is_multipattern = _subpattern_count > 1; | _is_multipattern = _subpattern_count > 1; | |||
} | } | |||
End of changes. 4 change blocks. | ||||
4 lines changed or deleted | 4 lines changed or added |