Changeset View
Changeset View
Standalone View
Standalone View
src/lib/rule.cpp
1 | /* | 1 | /* | ||
---|---|---|---|---|---|
2 | Copyright (C) 2016 Volker Krause <vkrause@kde.org> | 2 | Copyright (C) 2016 Volker Krause <vkrause@kde.org> | ||
3 | Copyright (C) 2018 Christoph Cullmann <cullmann@kde.org> | ||||
3 | 4 | | |||
4 | Permission is hereby granted, free of charge, to any person obtaining | 5 | Permission is hereby granted, free of charge, to any person obtaining | ||
5 | a copy of this software and associated documentation files (the | 6 | a copy of this software and associated documentation files (the | ||
6 | "Software"), to deal in the Software without restriction, including | 7 | "Software"), to deal in the Software without restriction, including | ||
7 | without limitation the rights to use, copy, modify, merge, publish, | 8 | without limitation the rights to use, copy, modify, merge, publish, | ||
8 | distribute, sublicense, and/or sell copies of the Software, and to | 9 | distribute, sublicense, and/or sell copies of the Software, and to | ||
9 | permit persons to whom the Software is furnished to do so, subject to | 10 | permit persons to whom the Software is furnished to do so, subject to | ||
10 | the following conditions: | 11 | the following conditions: | ||
▲ Show 20 Lines • Show All 83 Lines • ▼ Show 20 Line(s) | |||||
94 | Definition Rule::definition() const | 95 | Definition Rule::definition() const | ||
95 | { | 96 | { | ||
96 | return m_def.definition(); | 97 | return m_def.definition(); | ||
97 | } | 98 | } | ||
98 | 99 | | |||
99 | void Rule::setDefinition(const Definition &def) | 100 | void Rule::setDefinition(const Definition &def) | ||
100 | { | 101 | { | ||
101 | m_def = def; | 102 | m_def = def; | ||
103 | | ||||
104 | // cache for DefinitionData::wordDelimiters, is accessed VERY often | ||||
105 | m_wordDelimiter = &DefinitionData::get(m_def.definition())->wordDelimiters; | ||||
102 | } | 106 | } | ||
103 | 107 | | |||
104 | QString Rule::attribute() const | 108 | QString Rule::attribute() const | ||
105 | { | 109 | { | ||
106 | return m_attribute; | 110 | return m_attribute; | ||
107 | } | 111 | } | ||
108 | 112 | | |||
109 | ContextSwitch Rule::context() const | 113 | ContextSwitch Rule::context() const | ||
▲ Show 20 Lines • Show All 158 Lines • ▼ Show 20 Line(s) | 234 | { | |||
268 | else | 272 | else | ||
269 | qCWarning(Log) << "Unknown rule type:" << name; | 273 | qCWarning(Log) << "Unknown rule type:" << name; | ||
270 | 274 | | |||
271 | return Ptr(rule); | 275 | return Ptr(rule); | ||
272 | } | 276 | } | ||
273 | 277 | | |||
274 | bool Rule::isWordDelimiter(QChar c) const | 278 | bool Rule::isWordDelimiter(QChar c) const | ||
275 | { | 279 | { | ||
276 | auto defData = DefinitionData::get(m_def.definition()); | 280 | // perf tells contains is MUCH faster than binary search here, very short array | ||
277 | return defData->isWordDelimiter(c); | 281 | return m_wordDelimiter.contains(c); | ||
278 | } | 282 | } | ||
279 | 283 | | |||
280 | 284 | | |||
281 | bool AnyChar::doLoad(QXmlStreamReader& reader) | 285 | bool AnyChar::doLoad(QXmlStreamReader& reader) | ||
282 | { | 286 | { | ||
283 | m_chars = reader.attributes().value(QStringLiteral("String")).toString(); | 287 | m_chars = reader.attributes().value(QStringLiteral("String")).toString(); | ||
284 | if (m_chars.size() == 1) | 288 | if (m_chars.size() == 1) | ||
285 | qCDebug(Log) << "AnyChar rule with just one char: use DetectChar instead."; | 289 | qCDebug(Log) << "AnyChar rule with just one char: use DetectChar instead."; | ||
▲ Show 20 Lines • Show All 278 Lines • ▼ Show 20 Line(s) | 552 | { | |||
564 | 568 | | |||
565 | if (m_hasCaseSensitivityOverride) { | 569 | if (m_hasCaseSensitivityOverride) { | ||
566 | if (m_keywordList.contains(text.midRef(offset, newOffset - offset), m_caseSensitivityOverride)) | 570 | if (m_keywordList.contains(text.midRef(offset, newOffset - offset), m_caseSensitivityOverride)) | ||
567 | return newOffset; | 571 | return newOffset; | ||
568 | } else { | 572 | } else { | ||
569 | if (m_keywordList.contains(text.midRef(offset, newOffset - offset))) | 573 | if (m_keywordList.contains(text.midRef(offset, newOffset - offset))) | ||
570 | return newOffset; | 574 | return newOffset; | ||
571 | } | 575 | } | ||
572 | return offset; | 576 | | ||
577 | // we don't match, but we can skip until newOffset as we can't start a keyword in-between | ||||
578 | return MatchResult(offset, newOffset); | ||||
573 | } | 579 | } | ||
574 | 580 | | |||
575 | 581 | | |||
576 | bool LineContinue::doLoad(QXmlStreamReader& reader) | 582 | bool LineContinue::doLoad(QXmlStreamReader& reader) | ||
577 | { | 583 | { | ||
578 | const auto s = reader.attributes().value(QStringLiteral("char")); | 584 | const auto s = reader.attributes().value(QStringLiteral("char")); | ||
579 | if (s.isEmpty()) | 585 | if (s.isEmpty()) | ||
580 | m_char = QLatin1Char('\\'); | 586 | m_char = QLatin1Char('\\'); | ||
▲ Show 20 Lines • Show All 108 Lines • Show Last 20 Lines |