From: Ryan Lortie Date: Mon, 14 Oct 2013 18:36:34 +0000 (-0400) Subject: Add g_str_is_ascii() X-Git-Tag: 2.39.0~69 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=4c510801cfc8120d7dea7ae8121832e8d17d2453;p=platform%2Fupstream%2Fglib.git Add g_str_is_ascii() Add a function for checking if a string is pure ASCII. https://bugzilla.gnome.org/show_bug.cgi?id=709753 --- diff --git a/docs/reference/glib/glib-sections.txt b/docs/reference/glib/glib-sections.txt index 3b5170c..39c0814 100644 --- a/docs/reference/glib/glib-sections.txt +++ b/docs/reference/glib/glib-sections.txt @@ -1302,6 +1302,7 @@ g_vasprintf g_printf_string_upper_bound +g_str_is_ascii g_ascii_isalnum g_ascii_isalpha g_ascii_iscntrl diff --git a/glib/gstrfuncs.c b/glib/gstrfuncs.c index 4fcd91c..8303313 100644 --- a/glib/gstrfuncs.c +++ b/glib/gstrfuncs.c @@ -1528,6 +1528,29 @@ g_ascii_strup (const gchar *str, } /** + * g_str_is_ascii: + * @string: a string. + * + * Determines if a string is pure ASCII. A string is pure ASCII if it + * contains no bytes with the high bit set. + * + * Returns: %TRUE if @string is ascii + * + * Since: 2.40 + **/ +gboolean +g_str_is_ascii (const gchar *string) +{ + gint i; + + for (i = 0; string[i]; i++) + if (string[i] & 0x80) + return FALSE; + + return TRUE; +} + +/** * g_strdown: * @string: the string to convert. * diff --git a/glib/gstrfuncs.h b/glib/gstrfuncs.h index 510623a..43bc924 100644 --- a/glib/gstrfuncs.h +++ b/glib/gstrfuncs.h @@ -195,6 +195,8 @@ GLIB_AVAILABLE_IN_ALL gchar* g_ascii_strup (const gchar *str, gssize len) G_GNUC_MALLOC; +GLIB_AVAILABLE_IN_2_40 +gboolean g_str_is_ascii (const gchar *str); GLIB_DEPRECATED gint g_strcasecmp (const gchar *s1,