fixup Fix some warnings

This commit is contained in:
fiaxh 2019-09-10 19:11:41 +02:00 committed by fiaxh
parent d5d305193c
commit bd7fde99af
7 changed files with 40 additions and 58 deletions

View file

@ -259,8 +259,7 @@ public class Database : Qlite.Database {
message.type=conversation.type+1 and message.type=conversation.type+1 and
(message.counterpart_resource=conversation.resource or message.type != 3)"""); (message.counterpart_resource=conversation.resource or message.type != 3)""");
} catch (Error e) { } catch (Error e) {
stderr.printf("Failed to upgrade to database version 8: %s\n", e.message); error("Failed to upgrade to database version 8: %s", e.message);
Process.exit(-1);
} }
} }
if (oldVersion < 9) { if (oldVersion < 9) {
@ -277,8 +276,7 @@ public class Database : Qlite.Database {
message.body in (select info from file_transfer where info not null) or message.body in (select info from file_transfer where info not null) or
message.id in (select info from file_transfer where info not null)"""); message.id in (select info from file_transfer where info not null)""");
} catch (Error e) { } catch (Error e) {
stderr.printf("Failed to upgrade to database version 8: %s\n", e.message); error("Failed to upgrade to database version 9: %s", e.message);
Process.exit(-1);
} }
} }
} }

View file

@ -136,11 +136,7 @@ public class ConversationSelectorRow : ListBoxRow {
nick_label.label = last_message.direction == Message.DIRECTION_SENT ? _("Me") + ": " : ""; nick_label.label = last_message.direction == Message.DIRECTION_SENT ? _("Me") + ": " : "";
} }
try { message_label.label = Util.summarize_whitespaces_to_space(last_message.body);
message_label.label = Markup.escape_text((/\s+/).replace_literal(last_message.body, -1, 0, " "));
} catch (RegexError e) {
assert_not_reached();
}
break; break;
case FileItem.TYPE: case FileItem.TYPE:
FileItem file_item = last_content_item as FileItem; FileItem file_item = last_content_item as FileItem;

View file

@ -205,8 +205,8 @@ public class GlobalSearch : Overlay {
regex_str += ")"; regex_str += ")";
// Color the keywords // Color the keywords
int elongated_by = 0;
try { try {
int elongated_by = 0;
Regex highlight_regex = new Regex(regex_str); Regex highlight_regex = new Regex(regex_str);
MatchInfo match_info; MatchInfo match_info;
string markup_text_bak = markup_text.down(); string markup_text_bak = markup_text.down();
@ -218,6 +218,9 @@ public class GlobalSearch : Overlay {
elongated_by += "<span bgcolor=\"yellow\">".length + "</span>".length; elongated_by += "<span bgcolor=\"yellow\">".length + "</span>".length;
} }
markup_text_bak += ""; // We need markup_text_bak to live until here because url_regex.match does not copy the string markup_text_bak += ""; // We need markup_text_bak to live until here because url_regex.match does not copy the string
} catch (RegexError e) {
assert_not_reached();
}
label.label = markup_text; label.label = markup_text;
grid.attach(label, 1, 1, 1, 1); grid.attach(label, 1, 1, 1, 1);
@ -228,9 +231,6 @@ public class GlobalSearch : Overlay {
}); });
button.add(grid); button.add(grid);
return button; return button;
} catch (RegexError e) {
assert_not_reached();
}
} }
private Grid get_context_message_widget(MessageItem item) { private Grid get_context_message_widget(MessageItem item) {

View file

@ -153,19 +153,11 @@ public class UnifiedWindowController : Object {
private void update_conversation_topic(string? subtitle = null) { private void update_conversation_topic(string? subtitle = null) {
if (subtitle != null) { if (subtitle != null) {
try { conversation_topic = Util.summarize_whitespaces_to_space(subtitle);
conversation_topic = (/\s+/).replace_literal(subtitle, -1, 0, " ");
} catch (RegexError e) {
assert_not_reached();
}
} else if (conversation.type_ == Conversation.Type.GROUPCHAT) { } else if (conversation.type_ == Conversation.Type.GROUPCHAT) {
string? subject = stream_interactor.get_module(MucManager.IDENTITY).get_groupchat_subject(conversation.counterpart, conversation.account); string? subject = stream_interactor.get_module(MucManager.IDENTITY).get_groupchat_subject(conversation.counterpart, conversation.account);
if (subject != null) { if (subject != null) {
try { conversation_topic = Util.summarize_whitespaces_to_space(subject);
conversation_topic = (/\s+/).replace_literal(subject, -1, 0, " ");
} catch (RegexError e) {
assert_not_reached();
}
} else { } else {
conversation_topic = null; conversation_topic = null;
} }

View file

@ -272,6 +272,14 @@ public int get_only_emoji_count(string markup_text) {
return emoji_no; return emoji_no;
} }
public string summarize_whitespaces_to_space(string s) {
try {
return (/\s+/).replace_literal(s, -1, 0, " ");
} catch (RegexError e) {
assert_not_reached();
}
}
public bool use_csd() { public bool use_csd() {
return (GLib.Application.get_default() as Application).use_csd(); return (GLib.Application.get_default() as Application).use_csd();
} }

View file

@ -220,9 +220,8 @@ namespace Signal {
[CCode (cname = "ec_public_key_serialize_")] [CCode (cname = "ec_public_key_serialize_")]
public uint8[] serialize() { public uint8[] serialize() {
Buffer buffer; Buffer buffer;
try { int code = serialize_(out buffer);
throw_by_code(serialize_(out buffer)); if (code < 0 && code > MIN_ERROR_CODE) {
} catch (GLib.Error e) {
// Can only throw for invalid arguments or out of memory. // Can only throw for invalid arguments or out of memory.
GLib.assert_not_reached(); GLib.assert_not_reached();
} }
@ -240,9 +239,8 @@ namespace Signal {
[CCode (cname = "ec_private_key_serialize_")] [CCode (cname = "ec_private_key_serialize_")]
public uint8[] serialize() throws GLib.Error { public uint8[] serialize() throws GLib.Error {
Buffer buffer; Buffer buffer;
try { int code = serialize_(out buffer);
throw_by_code(serialize_(out buffer)); if (code < 0 && code > MIN_ERROR_CODE) {
} catch (GLib.Error e) {
// Can only throw for invalid arguments or out of memory. // Can only throw for invalid arguments or out of memory.
GLib.assert_not_reached(); GLib.assert_not_reached();
} }

View file

@ -1,27 +1,17 @@
namespace Xmpp.Util { namespace Xmpp.Util {
// Parse a number from a hexadecimal representation. /**
// * Parse a number from a hexadecimal representation.
// Skips any whitespace at the start of the string, parses as many valid *
// characters as hexadecimal digits as possible (possibly zero) and returns * Skips any whitespace at the start of the string, parses as many valid
// them as an integer value. * characters as hexadecimal digits as possible (possibly zero) and returns
// * them as an integer value.
// ``` *
// // 0x0 * ```
// print("0x%lx\n", from_hex("")); * // 0xa
// * print("0x%lx\n", from_hex("A quick brown fox jumps over the lazy dog."));
// // 0x123abc * ```
// print("0x%lx\n", from_hex("123abc")); */
//
// // 0x0
// print("0x%lx\n", from_hex("0x123abc"));
//
// // 0xa
// print("0x%lx\n", from_hex("A quick brown fox jumps over the lazy dog."));
//
// // 0xfeed
// print("0x%lx\n", from_hex(" FEED ME "));
// ```
public long from_hex(string numeral) { public long from_hex(string numeral) {
long result = 0; long result = 0;