[gmime] Improved g_mime_content_encoding_from_string()
- From: Rico Tzschichholz <ricotz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gmime] Improved g_mime_content_encoding_from_string()
- Date: Wed, 28 Nov 2018 18:32:15 +0000 (UTC)
commit 036d72b841e7b47265c705079775c4ec4794bf3b
Author: Jeffrey Stedfast <jestedfa microsoft com>
Date: Sun Nov 25 10:13:09 2018 -0500
Improved g_mime_content_encoding_from_string()
GMimePart internally was copying the Content-Transfer-Encoding
header value to a temporary buffer in order to strip leading/trailing
whitespace characters.
With the new and improved version of g_mime_content_encoding_from_string(),
this is no longer necessary.
gmime/gmime-encodings.c | 31 +++++++++++++++++++++----------
gmime/gmime-part.c | 20 +-------------------
2 files changed, 22 insertions(+), 29 deletions(-)
---
diff --git a/gmime/gmime-encodings.c b/gmime/gmime-encodings.c
index 0138253e..1a90f5be 100644
--- a/gmime/gmime-encodings.c
+++ b/gmime/gmime-encodings.c
@@ -100,6 +100,14 @@ static unsigned char tohex[16] = {
};
+static gboolean
+is (const char *str, const char *value, size_t n)
+{
+ return g_ascii_strncasecmp (str, value, n) == 0 &&
+ (str[n] == '\0' || is_lwsp (str[n]);
+}
+
+
/**
* g_mime_content_encoding_from_string:
* @str: a string representing a Content-Transfer-Encoding value
@@ -113,25 +121,28 @@ static unsigned char tohex[16] = {
GMimeContentEncoding
g_mime_content_encoding_from_string (const char *str)
{
- if (!g_ascii_strcasecmp (str, "7bit"))
+ while (is_lwsp (*str))
+ str++;
+
+ if (is (str, "7bit", 4))
return GMIME_CONTENT_ENCODING_7BIT;
- else if (!g_ascii_strcasecmp (str, "8bit"))
+ else if (is (str, "8bit", 4))
return GMIME_CONTENT_ENCODING_8BIT;
- else if (!g_ascii_strcasecmp (str, "7-bit"))
+ else if (is (str, "7-bit", 5))
return GMIME_CONTENT_ENCODING_7BIT;
- else if (!g_ascii_strcasecmp (str, "8-bit"))
+ else if (is (str, "8-bit", 5))
return GMIME_CONTENT_ENCODING_8BIT;
- else if (!g_ascii_strcasecmp (str, "binary"))
+ else if (is (str, "binary", 6))
return GMIME_CONTENT_ENCODING_BINARY;
- else if (!g_ascii_strcasecmp (str, "base64"))
+ else if (is (str, "base64", 6))
return GMIME_CONTENT_ENCODING_BASE64;
- else if (!g_ascii_strcasecmp (str, "quoted-printable"))
+ else if (is (str, "quoted-printable", 16))
return GMIME_CONTENT_ENCODING_QUOTEDPRINTABLE;
- else if (!g_ascii_strcasecmp (str, "uuencode"))
+ else if (is (str, "uuencode", 8))
return GMIME_CONTENT_ENCODING_UUENCODE;
- else if (!g_ascii_strcasecmp (str, "x-uuencode"))
+ else if (is (str, "x-uuencode", 10))
return GMIME_CONTENT_ENCODING_UUENCODE;
- else if (!g_ascii_strcasecmp (str, "x-uue"))
+ else if (is (str, "x-uue", 5))
return GMIME_CONTENT_ENCODING_UUENCODE;
else
return GMIME_CONTENT_ENCODING_DEFAULT;
diff --git a/gmime/gmime-part.c b/gmime/gmime-part.c
index 7c4ff75c..e31473d6 100644
--- a/gmime/gmime-part.c
+++ b/gmime/gmime-part.c
@@ -165,28 +165,11 @@ static const char *content_headers[] = {
};
-static void
-copy_atom (const char *src, char *dest, size_t n)
-{
- register const char *inptr = src;
- register char *outptr = dest;
- char *outend = dest + n;
-
- while (is_lwsp (*inptr))
- inptr++;
-
- while (is_atom (*inptr) && outptr < outend)
- *outptr++ = *inptr++;
-
- *outptr = '\0';
-}
-
static gboolean
process_header (GMimeObject *object, GMimeHeader *header)
{
GMimePart *mime_part = (GMimePart *) object;
const char *name, *value;
- char encoding[32];
guint i;
name = g_mime_header_get_name (header);
@@ -202,8 +185,7 @@ process_header (GMimeObject *object, GMimeHeader *header)
switch (i) {
case HEADER_CONTENT_TRANSFER_ENCODING:
value = g_mime_header_get_value (header);
- copy_atom (value, encoding, sizeof (encoding) - 1);
- mime_part->encoding = g_mime_content_encoding_from_string (encoding);
+ mime_part->encoding = g_mime_content_encoding_from_string (value);
break;
case HEADER_CONTENT_DESCRIPTION:
value = g_mime_header_get_value (header);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]