#include <errno.h>
#include <ctype.h> /* For tolower() */
-#ifdef HAVE_XLOCALE_H\r
-/* Needed on BSD/OS X for e.g. strtod_l */\r
-#include <xlocale.h>\r
+#ifdef HAVE_XLOCALE_H
+/* Needed on BSD/OS X for e.g. strtod_l */
+#include <xlocale.h>
#endif
#ifdef G_OS_WIN32
const guint16 * const g_ascii_table = ascii_table_data;
-#ifdef HAVE_NEWLOCALE
+#if defined (HAVE_NEWLOCALE) && \
+ defined (HAVE_USELOCALE) && \
+ defined (HAVE_STRTOD_L) && \
+ defined (HAVE_STRTOULL_L) && \
+ defined (HAVE_STRTOLL_L)
+#define USE_XLOCALE 1
+#endif
+
+#ifdef USE_XLOCALE
static locale_t
get_C_locale (void)
{
g_ascii_strtod (const gchar *nptr,
gchar **endptr)
{
-#ifdef HAVE_STRTOD_L
+#ifdef USE_XLOCALE
g_return_val_if_fail (nptr != NULL, 0);
gchar *fail_pos;
gdouble val;
+#ifndef __BIONIC__
struct lconv *locale_data;
+#endif
const char *decimal_point;
int decimal_point_len;
const char *p, *decimal_point_pos;
fail_pos = NULL;
+#ifndef __BIONIC__
locale_data = localeconv ();
decimal_point = locale_data->decimal_point;
decimal_point_len = strlen (decimal_point);
+#else
+ decimal_point = ".";
+ decimal_point_len = 1;
+#endif
g_assert (decimal_point_len != 0);
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
const gchar *format,
gdouble d)
{
-#ifdef HAVE_USELOCALE
+#ifdef USE_XLOCALE
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;
#else
+#ifndef __BIONIC__
struct lconv *locale_data;
+#endif
const char *decimal_point;
int decimal_point_len;
gchar *p;
_g_snprintf (buffer, buf_len, format, d);
+#ifndef __BIONIC__
locale_data = localeconv ();
decimal_point = locale_data->decimal_point;
decimal_point_len = strlen (decimal_point);
+#else
+ decimal_point = ".";
+ decimal_point_len = 1;
+#endif
g_assert (decimal_point_len != 0);
return buffer;
#endif
}
+#pragma GCC diagnostic pop
#define ISSPACE(c) ((c) == ' ' || (c) == '\f' || (c) == '\n' || \
(c) == '\r' || (c) == '\t' || (c) == '\v')
#define TOUPPER(c) (ISLOWER (c) ? (c) - 'a' + 'A' : (c))
#define TOLOWER(c) (ISUPPER (c) ? (c) - 'A' + 'a' : (c))
-#if !defined(HAVE_STRTOLL_L) || !defined(HAVE_STRTOULL_L)
+#ifndef USE_XLOCALE
static guint64
g_parse_long_long (const gchar *nptr,
}
return 0;
}
-#endif
+#endif /* !USE_XLOCALE */
/**
* g_ascii_strtoull:
gchar **endptr,
guint base)
{
-#ifdef HAVE_STRTOULL_L
+#ifdef USE_XLOCALE
return strtoull_l (nptr, endptr, base, get_C_locale ());
#else
gboolean negative;
gchar **endptr,
guint base)
{
-#ifdef HAVE_STRTOLL_L
+#ifdef USE_XLOCALE
return strtoll_l (nptr, endptr, base, get_C_locale ());
#else
gboolean negative;
}
/**
+ * 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.
*
* 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,
/**
* g_strdelimit:
* @string: the string to convert
- * @delimiters: a string containing the current delimiters, or %NULL
+ * @delimiters: (allow-none): a string containing the current delimiters, or %NULL
* to use the standard delimiters defined in #G_STR_DELIMITERS
* @new_delimiter: the new delimiter character
*
g_strcompress (const gchar *source)
{
const gchar *p = source, *octal;
- gchar *dest = g_malloc (strlen (source) + 1);
- gchar *q = dest;
+ gchar *dest;
+ gchar *q;
+
+ g_return_val_if_fail (source != NULL, NULL);
+
+ dest = g_malloc (strlen (source) + 1);
+ q = dest;
while (*p)
{
case 't':
*q++ = '\t';
break;
+ case 'v':
+ *q++ = '\v';
+ break;
default: /* Also handles \" and \\ */
*q++ = *p;
break;
* @source: a string to escape
* @exceptions: a string of characters not to escape in @source
*
- * Escapes the special characters '\b', '\f', '\n', '\r', '\t', '\'
+ * Escapes the special characters '\b', '\f', '\n', '\r', '\t', '\v', '\'
* and '"' in the string @source by inserting a '\' before
* them. Additionally all characters in the range 0x01-0x1F (everything
* below SPACE) and in the range 0x7F-0xFF (all non-ASCII chars) are
*q++ = '\\';
*q++ = 't';
break;
+ case '\v':
+ *q++ = '\\';
+ *q++ = 'v';
+ break;
case '\\':
*q++ = '\\';
*q++ = '\\';
/**
* g_strjoinv:
- * @separator: a string to insert between each of the strings, or %NULL
+ * @separator: (allow-none): a string to insert between each of the strings, or %NULL
* @str_array: a %NULL-terminated array of strings to join
*
* Joins a number of strings together to form one long string, with the
/**
* g_strjoin:
- * @separator: a string to insert between each of the strings, or %NULL
+ * @separator: (allow-none): a string to insert between each of the strings, or %NULL
* @...: a %NULL-terminated list of strings to join
*
* Joins a number of strings together to form one long string, with the