aboutsummaryrefslogtreecommitdiffstats
path: root/epan/wmem
diff options
context:
space:
mode:
authorAndersBroman <anders.broman@ericsson.com>2014-03-25 11:00:50 +0100
committerEvan Huus <eapache@gmail.com>2014-03-25 16:10:43 +0000
commit86d65a0758d46fa48015344f7ca30ae53bd0438e (patch)
treebf456d59d810e4753431c11c118719a4e8f7838a /epan/wmem
parenta99a0360c47c689abdf1ef09e09dea02749824d2 (diff)
Introduce wmem_ascii_strdown()
Change-Id: Icdc5a0d5033f3ab709fbf19a33ab26f609d4b1f0 Reviewed-on: https://code.wireshark.org/review/824 Reviewed-by: Evan Huus <eapache@gmail.com>
Diffstat (limited to 'epan/wmem')
-rw-r--r--epan/wmem/wmem_strutl.c20
-rw-r--r--epan/wmem/wmem_strutl.h19
-rw-r--r--epan/wmem/wmem_test.c5
3 files changed, 44 insertions, 0 deletions
diff --git a/epan/wmem/wmem_strutl.c b/epan/wmem/wmem_strutl.c
index 257b89ab40..9ad7ca2937 100644
--- a/epan/wmem/wmem_strutl.c
+++ b/epan/wmem/wmem_strutl.c
@@ -201,6 +201,26 @@ wmem_strsplit(wmem_allocator_t *allocator, const gchar *src,
}
/*
+ * wmem_ascii_strdown:
+ * based on g_ascii_strdown.
+ */
+gchar*
+wmem_ascii_strdown(wmem_allocator_t *allocator, const gchar *str, gssize len)
+{
+ gchar *result, *s;
+
+ g_return_val_if_fail (str != NULL, NULL);
+
+ if (len < 0)
+ len = strlen (str);
+
+ result = wmem_strndup(allocator, str, len);
+ for (s = result; *s; s++)
+ *s = g_ascii_tolower (*s);
+
+ return result;
+}
+/*
* Editor modelines - http://www.wireshark.org/tools/modelines.html
*
* Local variables:
diff --git a/epan/wmem/wmem_strutl.h b/epan/wmem/wmem_strutl.h
index 764d4bf950..b4c66c00fa 100644
--- a/epan/wmem/wmem_strutl.h
+++ b/epan/wmem/wmem_strutl.h
@@ -76,6 +76,25 @@ gchar **
wmem_strsplit(wmem_allocator_t *allocator, const gchar *src,
const gchar *delimiter, int max_tokens);
+
+/**
+ * wmem_ascii_strdown:
+ * Based on g_ascii_strdown
+ * @allocator: An enumeration of the different types of available allocators.
+ * @str: a string.
+ * @len: length of @str in bytes, or -1 if @str is nul-terminated.
+ *
+ * Converts all upper case ASCII letters to lower case ASCII letters.
+ *
+ * Return value: a newly-allocated string, with all the upper case
+ * characters in @str converted to lower case, with
+ * semantics that exactly match g_ascii_tolower(). (Note
+ * that this is unlike the old g_strdown(), which modified
+ * the string in place.)
+ **/
+WS_DLL_PUBLIC
+gchar*
+wmem_ascii_strdown(wmem_allocator_t *allocator, const gchar *str, gssize len);
/** @}
* @} */
diff --git a/epan/wmem/wmem_test.c b/epan/wmem/wmem_test.c
index 78287b40d3..2aac1b36d0 100644
--- a/epan/wmem/wmem_test.c
+++ b/epan/wmem/wmem_test.c
@@ -435,6 +435,11 @@ wmem_test_strutls(void)
g_assert_cmpstr(split_str[0], ==, "aslkf");
g_assert_cmpstr(split_str[1], ==, "asio");
g_assert_cmpstr(split_str[2], ==, "-asfj-as--");
+ wmem_strict_check_canaries(allocator);
+
+ orig_str = "TeStAsCiIsTrDoWn";
+ new_str = wmem_ascii_strdown(allocator, orig_str, -1);
+ g_assert_cmpstr(new_str, ==, "testasciistrdown");
wmem_destroy_allocator(allocator);
}