From 43d623a086877ff5331cc0e4ed56080bd4480da5 Mon Sep 17 00:00:00 2001 From: Patrick McDermott Date: Sat, 28 Oct 2017 23:34:47 -0400 Subject: MqWebView: Factor out extension detection code into functions --- (limited to 'src') diff --git a/src/web-view.c b/src/web-view.c index 970cc96..31540b3 100644 --- a/src/web-view.c +++ b/src/web-view.c @@ -911,6 +911,32 @@ get_clean_title(MqWebView *web_view) '_'); } +static gboolean +extension_is_html(const gchar *extension) +{ + return + extension[0] == 'h' && + extension[1] == 't' && + extension[2] == 'm' && + (extension[3] == '\0' || + (extension[3] == 'l' && + extension[4] == '\0')); +} + +static gboolean +extension_is_mhtml(const gchar *extension) +{ + return + extension[0] == 'm' && + extension[1] == 'h' && + extension[2] == 't' && + (extension[3] == '\0' || + (extension[3] == 'm' && + (extension[4] == '\0' || + (extension[4] == 'l' && + extension[5] == '\0')))); +} + static void save_type_changed_cb(GtkComboBox *combo_box, GtkFileChooser *chooser) { @@ -924,14 +950,7 @@ save_type_changed_cb(GtkComboBox *combo_box, GtkFileChooser *chooser) active_id = gtk_combo_box_get_active_id(combo_box); if (g_strcmp0(active_id, "html") == 0) { - if (!( - ext[0] == 'h' && - ext[1] == 't' && - ext[2] == 'm' && - (ext[3] == '\0' || - (ext[3] == 'l' && - ext[4] == '\0' - )))) { + if (!extension_is_html(ext)) { /* Extension is not "htm" or "html". */ ext[0] = '\0'; /* Remove extension. */ new_name = g_strconcat(name, "html", NULL); @@ -939,16 +958,7 @@ save_type_changed_cb(GtkComboBox *combo_box, GtkFileChooser *chooser) g_free(new_name); } } else if (g_strcmp0(active_id, "mhtml") == 0) { - if (!( - ext[0] == 'm' && - ext[1] == 'h' && - ext[2] == 't' && - (ext[3] == '\0' || - (ext[3] == 'm' && - (ext[4] == '\0' || - (ext[4] == 'l' && - ext[5] == '\0' - )))))) { + if (!extension_is_mhtml(ext)) { /* Extension is not "mht", "mhtm", or "mhtml". */ ext[0] = '\0'; /* Remove extension. */ new_name = g_strconcat(name, "mhtml", NULL); -- cgit v0.9.1