Skip to content

Commit

Permalink
UI: RuleTextParser: Simplify nextCharType()
Browse files Browse the repository at this point in the history
  • Loading branch information
tnodir committed Jun 13, 2024
1 parent 8a060e9 commit b390940
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 13 deletions.
39 changes: 26 additions & 13 deletions src/ui/util/conf/ruletextparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -210,22 +210,35 @@ RuleCharType RuleTextParser::nextCharType(quint32 expectedCharTypes, const char

charType = processCharType(charType, c, extraChars);

switch (charType) {
case CharNone: {
setErrorMessage(tr("Bad symbol: %1").arg(c));
return CharNone;
} break;
default:
if ((charType & expectedCharTypes) == 0) {
if (cp == m_p) {
setErrorMessage(tr("Unexpected symbol: %1").arg(c));
}
return CharNone;
}

if (!checkNextCharType(expectedCharTypes, charType, cp, c)) {
return charType;
}
}

return CharNone;
}

bool RuleTextParser::checkNextCharType(
quint32 expectedCharTypes, RuleCharType &charType, const QChar *cp, const QChar c)
{
switch (charType) {
case CharNone: {
setErrorMessage(tr("Bad symbol: %1").arg(c));

charType = CharNone;
return false;
} break;
default:
if ((charType & expectedCharTypes) == 0) {
if (cp == m_p) {
setErrorMessage(tr("Unexpected symbol: %1").arg(c));
}

charType = CharNone;
}

return false;
}

return true;
}
2 changes: 2 additions & 0 deletions src/ui/util/conf/ruletextparser.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ class RuleTextParser : public QObject
RuleExpr &listNode(int listIndex) { return m_ruleExprArray[listIndex]; }

RuleCharType nextCharType(quint32 expectedCharTypes, const char *extraChars = nullptr);
bool checkNextCharType(
quint32 expectedCharTypes, RuleCharType &charType, const QChar *cp, const QChar c);

private:
bool m_isNot = false;
Expand Down

0 comments on commit b390940

Please sign in to comment.