Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit c7fa2de

Browse files
authoredApr 8, 2025··
Merge pull request #30 from Tervicke/main
Added the fix for #28 and also added a if condition to check validity of the color
2 parents 29e0742 + 6b9014c commit c7fa2de

File tree

1 file changed

+32
-2
lines changed

1 file changed

+32
-2
lines changed
 

‎src/Syntax.cpp

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,40 @@ void Syntax::loadSyntaxRules(const YAML::Node &config)
4646
// Iterate through each rule in the category
4747
for (const auto &rule : rules)
4848
{
49-
QString regex = QString::fromStdString(rule["regex"].as<std::string>());
50-
QColor color(QString::fromStdString(rule["color"].as<std::string>()));
49+
50+
QString regex;
51+
try
52+
{
53+
std::string regexStr = rule["regex"].as<std::string>(); //will throw exception if the key does not exist
54+
regex = QString::fromStdString(regexStr);
55+
}
56+
catch(const YAML::Exception e)
57+
{
58+
qWarning() << " YAML exception when parsion the regex in syntax file" << e.what();
59+
continue;
60+
}
61+
5162
qDebug() << "regex: " << regex;
5263

64+
QColor color;
65+
try
66+
{
67+
std::string colorStr = rule["color"].as<std::string>();
68+
color = QColor(QString::fromStdString(colorStr));
69+
}
70+
catch(const YAML::Exception e)
71+
{
72+
qWarning() << " YAML exception when parsion the color in syntax file" << e.what();
73+
continue;
74+
}
75+
76+
//checks if the color is a valid color
77+
if(!color.isValid())
78+
{
79+
qWarning() << "Invalid COlor : Skipping...";
80+
continue;
81+
}
82+
5383
// Create a QTextCharFormat for the rule
5484
QTextCharFormat format;
5585
format.setForeground(color);

0 commit comments

Comments
 (0)
Please sign in to comment.