aboutsummaryrefslogtreecommitdiff
path: root/main/src/ui/util
diff options
context:
space:
mode:
authorhrxi <hrrrxi@gmail.com>2019-09-01 18:18:25 +0200
committerfiaxh <fiaxh@users.noreply.github.com>2019-09-10 19:36:11 +0200
commitd5d305193ce527f1cc3022c406de35d9a85d4ccb (patch)
treed12efc741319a7d71c13f7bf6c2c7579d25fdabe /main/src/ui/util
parent9950742bf1903291c271619aea101b0e2f81d19c (diff)
downloaddino-d5d305193ce527f1cc3022c406de35d9a85d4ccb.tar.gz
dino-d5d305193ce527f1cc3022c406de35d9a85d4ccb.zip
Fix some warnings
Instances of `RegexError` are just asserted as `assert_not_reached` as they cannot really fail except for allocation failure if the given regex is valid.
Diffstat (limited to 'main/src/ui/util')
-rw-r--r--main/src/ui/util/helper.vala44
1 files changed, 26 insertions, 18 deletions
diff --git a/main/src/ui/util/helper.vala b/main/src/ui/util/helper.vala
index 449936fc..c3353fb6 100644
--- a/main/src/ui/util/helper.vala
+++ b/main/src/ui/util/helper.vala
@@ -188,15 +188,19 @@ public static string parse_add_markup(string s_, string? highlight_word, bool pa
}
if (highlight_word != null) {
- Regex highlight_regex = new Regex("\\b" + Regex.escape_string(highlight_word.down()) + "\\b");
- MatchInfo match_info;
- highlight_regex.match(s.down(), 0, out match_info);
- if (match_info.matches()) {
- int start, end;
- match_info.fetch_pos(0, out start, out end);
- return parse_add_markup(s[0:start], highlight_word, parse_links, parse_text_markup, already_escaped) +
- "<b>" + s[start:end] + "</b>" +
- parse_add_markup(s[end:s.length], highlight_word, parse_links, parse_text_markup, already_escaped);
+ try {
+ Regex highlight_regex = new Regex("\\b" + Regex.escape_string(highlight_word.down()) + "\\b");
+ MatchInfo match_info;
+ highlight_regex.match(s.down(), 0, out match_info);
+ if (match_info.matches()) {
+ int start, end;
+ match_info.fetch_pos(0, out start, out end);
+ return parse_add_markup(s[0:start], highlight_word, parse_links, parse_text_markup, already_escaped) +
+ "<b>" + s[start:end] + "</b>" +
+ parse_add_markup(s[end:s.length], highlight_word, parse_links, parse_text_markup, already_escaped);
+ }
+ } catch (RegexError e) {
+ assert_not_reached();
}
}
@@ -206,15 +210,19 @@ public static string parse_add_markup(string s_, string? highlight_word, bool pa
for (int i = 0; i < markup_string.length; i++) {
string markup_esc = Regex.escape_string(markup_string[i]);
- Regex regex = new Regex("(^|\\s)" + markup_esc + "(\\S.*?\\S|\\S)" + markup_esc + "($|\\s)");
- MatchInfo match_info;
- regex.match(s.down(), 0, out match_info);
- if (match_info.matches()) {
- int start, end;
- match_info.fetch_pos(2, out start, out end);
- return parse_add_markup(s[0:start], highlight_word, parse_links, parse_text_markup, already_escaped) +
- @"<$(convenience_tag[i])>" + s[start:end] + @"</$(convenience_tag[i])>" +
- parse_add_markup(s[end:s.length], highlight_word, parse_links, parse_text_markup, already_escaped);
+ try {
+ Regex regex = new Regex("(^|\\s)" + markup_esc + "(\\S.*?\\S|\\S)" + markup_esc + "($|\\s)");
+ MatchInfo match_info;
+ regex.match(s.down(), 0, out match_info);
+ if (match_info.matches()) {
+ int start, end;
+ match_info.fetch_pos(2, out start, out end);
+ return parse_add_markup(s[0:start], highlight_word, parse_links, parse_text_markup, already_escaped) +
+ @"<$(convenience_tag[i])>" + s[start:end] + @"</$(convenience_tag[i])>" +
+ parse_add_markup(s[end:s.length], highlight_word, parse_links, parse_text_markup, already_escaped);
+ }
+ } catch (RegexError e) {
+ assert_not_reached();
}
}
}