forked from osmocom/wireshark
Introduce wmem_ascii_strdown()
Change-Id: Icdc5a0d5033f3ab709fbf19a33ab26f609d4b1f0 Reviewed-on: https://code.wireshark.org/review/824 Reviewed-by: Evan Huus <eapache@gmail.com>
This commit is contained in:
parent
a99a0360c4
commit
86d65a0758
|
@ -200,6 +200,26 @@ wmem_strsplit(wmem_allocator_t *allocator, const gchar *src,
|
|||
return vec;
|
||||
}
|
||||
|
||||
/*
|
||||
* 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
|
||||
*
|
||||
|
|
|
@ -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);
|
||||
/** @}
|
||||
* @} */
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue