bool UserFiltersModel::Add (const RuleOptionDialog& dia) { const auto& itemRx = dia.GetType () == FilterOption::MTRegexp ? RegExp (dia.GetString (), dia.GetCase ()) : RegExp (); FilterOption fo; fo.Case_ = dia.GetCase (); fo.MatchType_ = dia.GetType (); fo.Domains_ = dia.GetDomains (); fo.NotDomains_ = dia.GetNotDomains (); const FilterItem item { dia.GetString ().toUtf8 (), itemRx, fo.MatchType_ == FilterOption::MTPlain ? QByteArrayMatcher (dia.GetString ().toUtf8 ()) : QByteArrayMatcher (), fo }; auto& container = dia.IsException () ? Filter_.Exceptions_ : Filter_.Filters_; const int size = dia.IsException () ? Filter_.Exceptions_.size () : rowCount (); beginInsertRows (QModelIndex (), size, size); container << item; endInsertRows (); WriteSettings (); return !dia.IsException (); }
/*! * Update the cached tables of pregenerated encoded text with \a codec. */ void VersitUtils::changeCodec(QTextCodec* codec) { // Build m_encodingMap QChar qch; QTextCodec::ConverterState state(QTextCodec::IgnoreHeader); for (int c = 0; c < 256; c++) { qch = QLatin1Char(c); m_encodingMap[c] = codec->fromUnicode(&qch, 1, &state); } // Build m_newlineList if (m_newlineList != 0) delete m_newlineList; m_newlineList = new QList<QByteArrayMatcher>; m_newlineList->append(QByteArrayMatcher(encode("\r\n", codec))); m_newlineList->append(QByteArrayMatcher(encode("\n", codec))); m_newlineList->append(QByteArrayMatcher(encode("\r", codec))); m_previousCodec = codec; }
void tst_QByteArrayMatcher::interface() { const char needle[] = "abc123"; QByteArray haystack(500, 'a'); haystack.insert(6, "123"); haystack.insert(31, "abc"); haystack.insert(42, "abc123"); haystack.insert(84, "abc123"); matcher1 = QByteArrayMatcher(QByteArray(needle)); QByteArrayMatcher matcher2; matcher2.setPattern(QByteArray(needle)); QByteArrayMatcher matcher3 = QByteArrayMatcher(QByteArray(needle)); QByteArrayMatcher matcher4(needle, sizeof(needle) - 1); QByteArrayMatcher matcher5(matcher2); QByteArrayMatcher matcher6; matcher6 = matcher3; QCOMPARE(matcher1.indexIn(haystack), 42); QCOMPARE(matcher2.indexIn(haystack), 42); QCOMPARE(matcher3.indexIn(haystack), 42); QCOMPARE(matcher4.indexIn(haystack), 42); QCOMPARE(matcher5.indexIn(haystack), 42); QCOMPARE(matcher6.indexIn(haystack), 42); QCOMPARE(matcher1.indexIn(haystack.constData(), haystack.length()), 42); QCOMPARE(matcher1.indexIn(haystack, 43), 84); QCOMPARE(matcher1.indexIn(haystack.constData(), haystack.length(), 43), 84); QCOMPARE(matcher1.indexIn(haystack, 85), -1); QCOMPARE(matcher1.indexIn(haystack.constData(), haystack.length(), 85), -1); QByteArrayMatcher matcher7(QByteArray("123")); QCOMPARE(matcher7.indexIn(haystack), 6); matcher7 = QByteArrayMatcher(QByteArray("abc")); QCOMPARE(matcher7.indexIn(haystack), 31); matcher7.setPattern(matcher4.pattern()); QCOMPARE(matcher7.indexIn(haystack), 42); }
void tst_QByteArrayMatcher::indexIn() { const char p_data[] = { 0x0, 0x0, 0x1 }; QByteArray pattern(p_data, sizeof(p_data)); QByteArray haystack(8, '\0'); haystack[7] = 0x1; matcher = QByteArrayMatcher(pattern); QCOMPARE(matcher.indexIn(haystack, 0), 5); QCOMPARE(matcher.indexIn(haystack, 1), 5); QCOMPARE(matcher.indexIn(haystack, 2), 5); matcher.setPattern(pattern); QCOMPARE(matcher.indexIn(haystack, 0), 5); QCOMPARE(matcher.indexIn(haystack, 1), 5); QCOMPARE(matcher.indexIn(haystack, 2), 5); }