Add g_str_is_ascii()
[platform/upstream/glib.git] / glib / gstrfuncs.c
index 2e4f6ae..8303313 100644 (file)
@@ -881,6 +881,9 @@ g_ascii_dtostr (gchar       *buffer,
   return g_ascii_formatd (buffer, buf_len, "%.17g", d);
 }
 
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wformat-nonliteral"
+
 /**
  * g_ascii_formatd:
  * @buffer: A buffer to place the resulting string in
@@ -909,7 +912,7 @@ g_ascii_formatd (gchar       *buffer,
   locale_t old_locale;
 
   old_locale = uselocale (get_C_locale ());
-  _g_snprintf (buffer, buf_len, format, d);
+   _g_snprintf (buffer, buf_len, format, d);
   uselocale (old_locale);
 
   return buffer;
@@ -988,6 +991,7 @@ g_ascii_formatd (gchar       *buffer,
   return buffer;
 #endif
 }
+#pragma GCC diagnostic pop
 
 #define ISSPACE(c)              ((c) == ' ' || (c) == '\f' || (c) == '\n' || \
                                  (c) == '\r' || (c) == '\t' || (c) == '\v')
@@ -1524,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.
  *
@@ -1873,9 +1900,10 @@ g_strcasecmp (const gchar *s1,
  * it doesn't work on many encodings at all, including UTF-8, EUC-JP,
  * etc.
  *
- * There are therefore two replacement functions: g_ascii_strncasecmp(),
+ * There are therefore two replacement techniques: g_ascii_strncasecmp(),
  * which only works on ASCII and is not locale-sensitive, and
- * g_utf8_casefold(), which is good for case-insensitive sorting of UTF-8.
+ * g_utf8_casefold() followed by strcmp() on the resulting strings, which is
+ * good for case-insensitive sorting of UTF-8.
  **/
 gint
 g_strncasecmp (const gchar *s1,