[balsa/wip/gtk4] Use g_str_has_prefix()
- From: Peter Bloomfield <peterb src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [balsa/wip/gtk4] Use g_str_has_prefix()
- Date: Sun, 3 Jun 2018 21:16:16 +0000 (UTC)
commit ad0916c55fce3d5a478221a7c9e37e5e958efc5c
Author: Peter Bloomfield <PeterBloomfield bellsouth net>
Date: Sun Jun 3 17:15:01 2018 -0400
Use g_str_has_prefix()
to, well, check whether a string has a given prefix.
libbalsa/gmime-part-rfc2440.c | 8 ++++----
libbalsa/html.c | 2 +-
libbalsa/mailbox.c | 2 +-
libbalsa/mailbox_imap.c | 2 +-
libbalsa/mailbox_maildir.c | 4 ++--
libbalsa/mailbox_mbox.c | 2 +-
libbalsa/mailbox_pop3.c | 12 +++---------
libbalsa/mime.c | 6 +++---
libbalsa/misc.c | 2 +-
libbalsa/send.c | 2 +-
libbalsa/url.c | 2 +-
libnetclient/net-client-pop.c | 8 ++++----
libnetclient/net-client-smtp.c | 2 +-
src/folder-conf.c | 9 ++++-----
src/sendmsg-window.c | 10 +++++-----
15 files changed, 33 insertions(+), 40 deletions(-)
---
diff --git a/libbalsa/gmime-part-rfc2440.c b/libbalsa/gmime-part-rfc2440.c
index 199dfe04..4a7772f2 100644
--- a/libbalsa/gmime-part-rfc2440.c
+++ b/libbalsa/gmime-part-rfc2440.c
@@ -72,10 +72,10 @@ g_mime_part_check_rfc2440(GMimePart * part)
g_mime_stream_read(stream, buf, slen);
buf[slen] = '\0';
- if (!strncmp(buf, "-----BEGIN PGP MESSAGE-----", 27) &&
+ if (g_str_has_prefix(buf, "-----BEGIN PGP MESSAGE-----") &&
strstr(buf, "-----END PGP MESSAGE-----"))
retval = GMIME_PART_RFC2440_ENCRYPTED;
- else if (!strncmp(buf, "-----BEGIN PGP SIGNED MESSAGE-----", 34)) {
+ else if (g_str_has_prefix(buf, "-----BEGIN PGP SIGNED MESSAGE-----")) {
gchar *p1, *p2;
p1 = strstr(buf, "-----BEGIN PGP SIGNATURE-----");
@@ -88,12 +88,12 @@ g_mime_part_check_rfc2440(GMimePart * part)
g_mime_stream_read(stream, buf, 34);
g_mime_stream_seek(stream, 1 - RFC2440_BUF_LEN,
GMIME_STREAM_SEEK_END);
- if (!strncmp(buf, "-----BEGIN PGP MESSAGE-----", 27)) {
+ if (g_str_has_prefix(buf, "-----BEGIN PGP MESSAGE-----")) {
g_mime_stream_read(stream, buf, RFC2440_BUF_LEN - 1);
buf[RFC2440_BUF_LEN - 1] = '\0';
if (strstr(buf, "-----END PGP MESSAGE-----"))
retval = GMIME_PART_RFC2440_ENCRYPTED;
- } else if (!strncmp(buf, "-----BEGIN PGP SIGNED MESSAGE-----", 34)) {
+ } else if (g_str_has_prefix(buf, "-----BEGIN PGP SIGNED MESSAGE-----")) {
gchar *p1, *p2;
g_mime_stream_read(stream, buf, RFC2440_BUF_LEN - 1);
diff --git a/libbalsa/html.c b/libbalsa/html.c
index ada13747..3def3d45 100644
--- a/libbalsa/html.c
+++ b/libbalsa/html.c
@@ -1825,7 +1825,7 @@ libbalsa_html_url_requested(GtkWidget * html, const gchar * url,
LibBalsaMessageBody *body;
GMimeStream *mime_stream;
- if (strncmp(url, "cid:", 4)) {
+ if (!g_str_has_prefix(url, "cid:")) {
/* printf("non-local URL request ignored: %s\n", url); */
return FALSE;
}
diff --git a/libbalsa/mailbox.c b/libbalsa/mailbox.c
index 96b654ae..013634df 100644
--- a/libbalsa/mailbox.c
+++ b/libbalsa/mailbox.c
@@ -1221,7 +1221,7 @@ libbalsa_mailbox_type_from_path(const gchar *path)
{
struct stat st;
- if (strncmp(path, "imap://", 7) == 0) {
+ if (g_str_has_prefix(path, "imap://")) {
return LIBBALSA_TYPE_MAILBOX_IMAP;
}
diff --git a/libbalsa/mailbox_imap.c b/libbalsa/mailbox_imap.c
index 964914c9..9941d5e9 100644
--- a/libbalsa/mailbox_imap.c
+++ b/libbalsa/mailbox_imap.c
@@ -3771,7 +3771,7 @@ libbalsa_mailbox_imap_messages_copy(LibBalsaMailbox *mailbox,
while ((filename = g_dir_read_name(dir)) != NULL) {
unsigned msg_uid;
gchar *tail;
- if (strncmp(encoded_path, filename, prefix_length)) {
+ if (!g_str_has_prefix(filename, encoded_path)) {
continue;
}
msg_uid = strtol(filename + prefix_length, &tail, 10);
diff --git a/libbalsa/mailbox_maildir.c b/libbalsa/mailbox_maildir.c
index f410ed90..27885002 100644
--- a/libbalsa/mailbox_maildir.c
+++ b/libbalsa/mailbox_maildir.c
@@ -356,7 +356,7 @@ parse_filename(const gchar *subdir,
flags |= LIBBALSA_MESSAGE_FLAG_RECENT;
}
- if (((p = strrchr (filename, ':')) != NULL) && (strncmp (p + 1, "2,", 2) == 0)) {
+ if (((p = strrchr (filename, ':')) != NULL) && g_str_has_prefix (p + 1, "2,")) {
p += 3;
while (*p) {
switch (*p) {
@@ -417,7 +417,7 @@ lbm_maildir_parse(LibBalsaMailboxMaildir *mdir,
key = g_strdup(filename);
/* strip flags of filename */
- if ((p = strrchr(key, ':')) && !strncmp(p, ":2,", 3)) {
+ if ((p = strrchr(key, ':')) && g_str_has_prefix(p, ":2,")) {
*p = '\0';
}
diff --git a/libbalsa/mailbox_mbox.c b/libbalsa/mailbox_mbox.c
index 8f600a5b..e258b671 100644
--- a/libbalsa/mailbox_mbox.c
+++ b/libbalsa/mailbox_mbox.c
@@ -942,7 +942,7 @@ lbm_mbox_check_file(LibBalsaMailboxMbox *mbox,
* by an embedded Content-Length header, we may be misled, but a
* full GMime parse takes too long. */
while (lbm_mbox_readln(buffer, line)
- && strncmp((gchar *) line->data, "From ", 5) != 0) {
+ && !g_str_has_prefix((gchar *) line->data, "From ")) {
/* Nothing. */
}
if (line->len == 0) {
diff --git a/libbalsa/mailbox_pop3.c b/libbalsa/mailbox_pop3.c
index 9560165c..28dd1109 100644
--- a/libbalsa/mailbox_pop3.c
+++ b/libbalsa/mailbox_pop3.c
@@ -168,14 +168,12 @@ mp_load_uids(const gchar *prefix)
if (read_res) {
gchar **lines;
- size_t prefix_len;
guint n;
lines = g_strsplit(contents, "\n", -1);
g_free(contents);
- prefix_len = strlen(prefix);
for (n = 0; lines[n] != NULL; n++) {
- if (strncmp(lines[n], prefix, prefix_len) == 0) {
+ if (g_str_has_prefix(lines[n], prefix)) {
g_hash_table_insert(res, g_strdup(lines[n]), GINT_TO_POINTER(1));
}
}
@@ -219,14 +217,12 @@ mp_save_uids(GHashTable *uids,
if (out != NULL) {
if (read_res) {
gchar **lines;
- size_t prefix_len;
guint n;
lines = g_strsplit(contents, "\n", -1);
g_free(contents);
- prefix_len = strlen(prefix);
for (n = 0; lines[n] != NULL; n++) {
- if ((lines[n][0] != '\0') && (strncmp(lines[n], prefix, prefix_len) != 0)) {
+ if ((lines[n][0] != '\0') && (!g_str_has_prefix(lines[n], prefix))) {
fputs(lines[n], out);
fputc('\n', out);
}
@@ -594,7 +590,6 @@ update_msg_list(struct fetch_data *fd,
{
GHashTable *uids = NULL;
gchar *uid_prefix = NULL;
- size_t prefix_len = 0U;
GList *p;
/* load uid's if messages shall be left on the server */
@@ -603,7 +598,6 @@ update_msg_list(struct fetch_data *fd,
"@",
libbalsa_server_get_host(server),
NULL);
- prefix_len = strlen(uid_prefix);
uids = mp_load_uids(uid_prefix);
*current_uids = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL);
}
@@ -659,7 +653,7 @@ update_msg_list(struct fetch_data *fd,
g_hash_table_iter_init(&iter, uids);
while (g_hash_table_iter_next(&iter, &key, NULL)) {
- if (strncmp((const char *) key, uid_prefix, prefix_len) != 0) {
+ if (!g_str_has_prefix((const char *) key, uid_prefix)) {
g_hash_table_insert(*current_uids, key, GINT_TO_POINTER(1));
}
}
diff --git a/libbalsa/mime.c b/libbalsa/mime.c
index b090933c..33a3306d 100644
--- a/libbalsa/mime.c
+++ b/libbalsa/mime.c
@@ -354,7 +354,7 @@ dowrap_rfc2646(GList * list, gint width, gboolean to_screen,
* - ...but we mustn't stuff `-- ' */
if (((!to_screen
&& (*str == ' ' || *str == QUOTE_CHAR
- || !strncmp(str, "From ", 5))) || len > 0)
+ || g_str_has_prefix(str, "From "))) || len > 0)
&& strcmp(str, "-- ")) {
g_string_append_c(result, ' ');
++len;
@@ -390,7 +390,7 @@ dowrap_rfc2646(GList * list, gint width, gboolean to_screen,
* */
if ((str - start) < max_width && *str
&& (*str == QUOTE_CHAR
- || !strncmp(str, "From ", 5)))
+ || g_str_has_prefix(str, "From ")))
continue;
if (!*str || len > width || (str - start) >= max_width) {
@@ -598,7 +598,7 @@ get_quote_tag(GtkTextIter * iter)
gchar *name;
g_object_get(G_OBJECT(tag), "name", &name, NULL);
if (name) {
- if (!strncmp(name, "quote-", 6))
+ if (g_str_has_prefix(name, "quote-"))
quote_tag = tag_list->data;
g_free(name);
}
diff --git a/libbalsa/misc.c b/libbalsa/misc.c
index 4f6063c2..0eeecb42 100644
--- a/libbalsa/misc.c
+++ b/libbalsa/misc.c
@@ -65,7 +65,7 @@ getdnsdomainname (char *s, size_t l)
{
p = tmp;
while ( g_ascii_isspace (*p)) p++;
- if (strncmp ("domain", p, 6) == 0 || strncmp ("search", p, 6) == 0)
+ if (g_str_has_prefix(p, "domain") || g_str_has_prefix(p, "search"))
{
p += 6;
diff --git a/libbalsa/send.c b/libbalsa/send.c
index 39b36801..d972814b 100644
--- a/libbalsa/send.c
+++ b/libbalsa/send.c
@@ -1264,7 +1264,7 @@ libbalsa_message_create_mime_message(LibBalsaMessage *message,
g_mime_object_set_content_type(mime_part, content_type);
g_mime_part_set_content_encoding(GMIME_PART(mime_part),
GMIME_CONTENT_ENCODING_7BIT);
- if (body->filename && !strncmp(body->filename, "URL", 3)) {
+ if (body->filename && g_str_has_prefix(body->filename, "URL")) {
g_mime_object_set_content_type_parameter(mime_part,
"access-type", "URL");
g_mime_object_set_content_type_parameter(mime_part,
diff --git a/libbalsa/url.c b/libbalsa/url.c
index fa2f1798..de4fb000 100644
--- a/libbalsa/url.c
+++ b/libbalsa/url.c
@@ -161,7 +161,7 @@ static char *ciss_parse_userhost (ciss_url_t *ciss, char *src)
ciss->host = NULL;
ciss->port = 0;
- if (strncmp (src, "//", 2))
+ if (!g_str_has_prefix (src, "//"))
return src;
src += 2;
diff --git a/libnetclient/net-client-pop.c b/libnetclient/net-client-pop.c
index 4871515d..999656d5 100644
--- a/libnetclient/net-client-pop.c
+++ b/libnetclient/net-client-pop.c
@@ -442,11 +442,11 @@ net_client_pop_read_reply(NetClientPop *client, gchar **reply, GError **error)
result = net_client_read_line(NET_CLIENT(client), &reply_buf, error);
if (result) {
- if (strncmp(reply_buf, "+OK", 3U) == 0) {
+ if (g_str_has_prefix(reply_buf, "+OK")) {
if ((strlen(reply_buf) > 3U) && (reply != NULL)) {
*reply = g_strdup(&reply_buf[4]);
}
- } else if (strncmp(reply_buf, "-ERR", 4U) == 0) {
+ } else if (g_str_has_prefix(reply_buf, "-ERR")) {
if (strlen(reply_buf) > 4U) {
g_set_error(error, NET_CLIENT_POP_ERROR_QUARK, (gint)
NET_CLIENT_ERROR_POP_SERVER_ERR, _("error: %s"),
&reply_buf[5]);
@@ -723,7 +723,7 @@ net_client_pop_execute_sasl(NetClientPop *client, const gchar *request_fmt, gcha
result = net_client_read_line(NET_CLIENT(client), &reply_buf, error);
if (result) {
- if (strncmp(reply_buf, "+ ", 2U) == 0) {
+ if (g_str_has_prefix(reply_buf, "+ ")) {
if (challenge != NULL) {
*challenge = g_strdup(&reply_buf[2]);
}
@@ -762,7 +762,7 @@ net_client_pop_get_capa(NetClientPop *client, guint *auth_supported)
done = TRUE;
} else if (strcmp(reply, "USER") == 0) {
*auth_supported |= NET_CLIENT_POP_AUTH_USER_PASS;
- } else if (strncmp(reply, "SASL ", 5U) == 0) {
+ } else if (g_str_has_prefix(reply, "SASL ")) {
gchar **auth;
guint n;
diff --git a/libnetclient/net-client-smtp.c b/libnetclient/net-client-smtp.c
index 59aae371..488ea80c 100644
--- a/libnetclient/net-client-smtp.c
+++ b/libnetclient/net-client-smtp.c
@@ -627,7 +627,7 @@ net_client_smtp_ehlo(NetClientSmtp *client, guint *auth_supported, gboolean *can
priv->can_dsn = TRUE;
} else if (strcmp(&endptr[1], "STARTTLS") == 0) {
*can_starttls = TRUE;
- } else if ((strncmp(&endptr[1], "AUTH ", 5U) == 0) || (strncmp(&endptr[1],
"AUTH=", 5U) == 0)) {
+ } else if (g_str_has_prefix(&endptr[1], "AUTH ") ||
g_str_has_prefix(&endptr[1], "AUTH=")) {
gchar **auth;
guint n;
diff --git a/src/folder-conf.c b/src/folder-conf.c
index cb0da941..4a2d9a1b 100644
--- a/src/folder-conf.c
+++ b/src/folder-conf.c
@@ -686,8 +686,8 @@ folder, parent);
balsa_mailbox_node_set_dir(sdd->mbnode, parent);
/* Rescan as little of the tree as possible. */
- if (sdd->old_parent
- && !strncmp(parent, sdd->old_parent, strlen(parent))) {
+ if (sdd->old_parent != NULL
+ && g_str_has_prefix(sdd->old_parent, parent)) {
/* moved it up the tree */
BalsaMailboxNode *mbnode =
balsa_mailbox_node_find_from_dir(balsa_mailbox_node_get_server(sdd->parent), parent);
@@ -696,9 +696,8 @@ folder, parent);
g_object_unref(mbnode);
} else
printf("Parent not found!?\n");
- } else if (sdd->old_parent
- && !strncmp(parent, sdd->old_parent,
- strlen(sdd->old_parent))) {
+ } else if (sdd->old_parent != NULL
+ && g_str_has_prefix(parent, sdd->old_parent)) {
/* moved it down the tree */
BalsaMailboxNode *mbnode =
balsa_mailbox_node_find_from_dir(balsa_mailbox_node_get_server(sdd->parent),
sdd->old_parent);
diff --git a/src/sendmsg-window.c b/src/sendmsg-window.c
index f6659439..b2968f1b 100644
--- a/src/sendmsg-window.c
+++ b/src/sendmsg-window.c
@@ -1293,13 +1293,13 @@ update_bsmsg_identity(BalsaSendmsg *bsmsg,
old_reply_string = libbalsa_identity_get_reply_string(old_ident);
old_forward_string = libbalsa_identity_get_forward_string(old_ident);
- if (((replen = strlen(old_forward_string)) > 0) &&
- (strncmp(subject, old_reply_string, replen) == 0)) {
+ if (((replen = strlen(old_reply_string)) > 0) &&
+ g_str_has_prefix(subject, old_reply_string)) {
tmpstr = g_strconcat(reply_string, &(subject[replen]), NULL);
gtk_entry_set_text(GTK_ENTRY(bsmsg->subject[1]), tmpstr);
g_free(tmpstr);
} else if (((fwdlen = strlen(old_forward_string)) > 0) &&
- (strncmp(subject, old_forward_string, fwdlen) == 0)) {
+ g_str_has_prefix(subject, old_forward_string)) {
tmpstr = g_strconcat(forward_string, &(subject[fwdlen]), NULL);
gtk_entry_set_text(GTK_ENTRY(bsmsg->subject[1]), tmpstr);
g_free(tmpstr);
@@ -1913,8 +1913,8 @@ add_attachment(BalsaSendmsg *bsmsg,
const gchar *uri_utf8 = libbalsa_vfs_get_uri_utf8(file_uri);
const gchar *home = g_getenv("HOME");
- if (home && !strncmp(uri_utf8, "file://", 7) &&
- !strncmp(uri_utf8 + 7, home, strlen(home)))
+ if (home != NULL && g_str_has_prefix(uri_utf8, "file://") &&
+ g_str_has_prefix(uri_utf8 + 7, home))
utf8name = g_strdup_printf("~%s", uri_utf8 + 7 + strlen(home));
else
utf8name = g_strdup(uri_utf8);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]