Skip to content

Commit

Permalink
Use const REGEX flags and compile-options for scripting
Browse files Browse the repository at this point in the history
  • Loading branch information
ErikReider committed Feb 21, 2023
1 parent 7054140 commit c264d44
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions src/configModel/configModel.vala
Original file line number Diff line number Diff line change
Expand Up @@ -75,52 +75,58 @@ namespace SwayNotificationCenter {
public string ? urgency { get; set; default = null; }
public string ? category { get; set; default = null; }

private const RegexCompileFlags REGEX_COMPILE_OPTIONS =
RegexCompileFlags.MULTILINE
| RegexCompileFlags.JAVASCRIPT_COMPAT;

private const RegexMatchFlags REGEX_MATCH_FLAGS = RegexMatchFlags.NOTEMPTY;

public virtual bool matches_notification (NotifyParams param) {
if (app_name != null) {
if (param.app_name == null) return false;
bool result = Regex.match_simple (
app_name, param.app_name,
0,
RegexMatchFlags.NOTEMPTY);
REGEX_COMPILE_OPTIONS,
REGEX_MATCH_FLAGS);
if (!result) return false;
}
if (desktop_entry != null) {
if (param.desktop_entry == null) return false;
bool result = Regex.match_simple (
desktop_entry, param.desktop_entry,
0,
RegexMatchFlags.NOTEMPTY);
REGEX_COMPILE_OPTIONS,
REGEX_MATCH_FLAGS);
if (!result) return false;
}
if (summary != null) {
if (param.summary == null) return false;
bool result = Regex.match_simple (
summary, param.summary,
0,
RegexMatchFlags.NOTEMPTY);
REGEX_COMPILE_OPTIONS,
REGEX_MATCH_FLAGS);
if (!result) return false;
}
if (body != null) {
if (param.body == null) return false;
bool result = Regex.match_simple (
body, param.body,
0,
RegexMatchFlags.NOTEMPTY);
REGEX_MATCH_FLAGS);
if (!result) return false;
}
if (urgency != null) {
bool result = Regex.match_simple (
urgency, param.urgency.to_string (),
0,
RegexMatchFlags.NOTEMPTY);
REGEX_COMPILE_OPTIONS,
REGEX_MATCH_FLAGS);
if (!result) return false;
}
if (category != null) {
if (param.category == null) return false;
bool result = Regex.match_simple (
category, param.category,
0,
RegexMatchFlags.NOTEMPTY);
REGEX_COMPILE_OPTIONS,
REGEX_MATCH_FLAGS);
if (!result) return false;
}
return true;
Expand Down

0 comments on commit c264d44

Please sign in to comment.