diff --git a/docs/reference/glib/glib-overrides.txt b/docs/reference/glib/glib-overrides.txt
index 80fe2f100..2905b1edb 100644
--- a/docs/reference/glib/glib-overrides.txt
+++ b/docs/reference/glib/glib-overrides.txt
@@ -219,3 +219,71 @@ GPrivate *private_key, gpointer data
G_OS_BEOS
#define G_OS_BEOS
+
+# g_ascii_isxxx
+
+
+g_ascii_isalnum
+gboolean
+gchar c
+
+
+
+g_ascii_isalpha
+gboolean
+gchar c
+
+
+
+g_ascii_iscntrl
+gboolean
+gchar c
+
+
+
+g_ascii_isdigit
+gboolean
+gchar c
+
+
+
+g_ascii_isgraph
+gboolean
+gchar c
+
+
+
+g_ascii_islower
+gboolean
+gchar c
+
+
+
+g_ascii_isprint
+gboolean
+gchar c
+
+
+
+g_ascii_ispunct
+gboolean
+gchar c
+
+
+
+g_ascii_isspace
+gboolean
+gchar c
+
+
+
+g_ascii_isupper
+gboolean
+gchar c
+
+
+
+g_ascii_isxdigit
+gboolean
+gchar c
+
diff --git a/docs/reference/glib/glib-sections.txt b/docs/reference/glib/glib-sections.txt
index a58270172..7840cbe48 100644
--- a/docs/reference/glib/glib-sections.txt
+++ b/docs/reference/glib/glib-sections.txt
@@ -851,6 +851,39 @@ g_snprintf
g_vsnprintf
g_printf_string_upper_bound
+
+g_ascii_isalnum
+g_ascii_isalpha
+g_ascii_iscntrl
+g_ascii_isdigit
+g_ascii_isgraph
+g_ascii_islower
+g_ascii_isprint
+g_ascii_ispunct
+g_ascii_isspace
+g_ascii_isupper
+g_ascii_isxdigit
+
+
+g_ascii_digit_value
+g_ascii_xdigit_value
+
+
+g_ascii_strcasecmp
+g_ascii_strncasecmp
+
+
+g_ascii_strup
+g_ascii_strdown
+
+
+g_ascii_tolower
+g_ascii_toupper
+
+
+g_string_ascii_up
+g_string_ascii_down
+
g_strup
g_strdown
diff --git a/docs/reference/glib/tmpl/string_utils.sgml b/docs/reference/glib/tmpl/string_utils.sgml
index 3dc908068..0c2be0c8d 100644
--- a/docs/reference/glib/tmpl/string_utils.sgml
+++ b/docs/reference/glib/tmpl/string_utils.sgml
@@ -193,6 +193,286 @@ documentation.
@Returns: the maximum space needed to store the formatted string.
+
+
+Determines whether a character is alphanumeric.
+
+
+Unlike the standard C library isalnum function, this only
+recognizes standard ASCII letters and ignores the locale, returning
+%FALSE for all non-ASCII characters. Also unlike the standard
+library function, this takes a char, not an int, so don't call it
+on EOF but no need to cast to guchar before passing a possibly
+non-ASCII character in.
+
+
+@c: any characted
+@Returns: %TRUE if @c is an ASCII alphanumeric character
+
+
+
+
+Determines whether a character is alphabetic (i.e. a letter).
+
+
+Unlike the standard C library isalpha function, this only
+recognizes standard ASCII letters and ignores the locale, returning
+%FALSE for all non-ASCII characters. Also unlike the standard
+library function, this takes a char, not an int, so don't call it
+on EOF but no need to cast to guchar before passing a possibly
+non-ASCII character in.
+
+
+@c: any characted
+@Returns: %TRUE if @c is an ASCII alphabetic character
+
+
+
+
+Determines whether a character is a control character.
+
+
+Unlike the standard C library iscntrl function, this only
+recognizes standard ASCII control characters and ignores the locale,
+returning%FALSE for all non-ASCII characters. Also unlike the standard
+library function, this takes a char, not an int, so don't call it
+on EOF but no need to cast to guchar before passing a possibly
+non-ASCII character in.
+
+
+@c: any characted
+@Returns: %TRUE if @c is an ASCII control character.
+
+
+
+
+Determines whether a character is digit (0-9).
+
+
+Unlike the standard C library isdigit function, this only
+recognizes standard ASCII digits and ignores the locale, returning
+%FALSE for all non-ASCII characters. Also unlike the standard
+library function, this takes a char, not an int, so don't call it
+on EOF but no need to cast to guchar before passing a possibly
+non-ASCII character in.
+
+
+@c: any characted
+@Returns: %TRUE if @c is an ASCII digit.
+
+
+
+
+Determines whether a character is a printing character and not a space.
+
+
+Unlike the standard C library isgraph function, this only
+recognizes standard ASCII characters and ignores the locale, returning
+%FALSE for all non-ASCII characters. Also unlike the standard
+library function, this takes a char, not an int, so don't call it
+on EOF but no need to cast to guchar before passing a possibly
+non-ASCII character in.
+
+
+@c: any characted
+@Returns: %TRUE if @c is an ASCII printing character other than space.
+
+
+
+
+Determines whether a character is an ASCII lower case letter.
+
+
+Unlike the standard C library islower function, this only
+recognizes standard ASCII letters and ignores the locale, returning
+%FALSE for all non-ASCII characters. Also unlike the standard
+library function, this takes a char, not an int, so don't call it
+on EOF but no need to worry about casting to guchar before passing
+a possibly non-ASCII character in.
+
+
+@c: any characted
+@Returns: %TRUE if @c is an ASCII lower case letter
+
+
+
+
+Determines whether a character is a printing character.
+
+
+Unlike the standard C library isprint function, this only
+recognizes standard ASCII characters and ignores the locale, returning
+%FALSE for all non-ASCII characters. Also unlike the standard
+library function, this takes a char, not an int, so don't call it
+on EOF but no need to cast to guchar before passing a possibly
+non-ASCII character in.
+
+
+@c: any characted
+@Returns: %TRUE if @c is an ASCII printing character.
+
+
+
+
+Determines whether a character is a punctuation character.
+
+
+Unlike the standard C library ispunct function, this only
+recognizes standard ASCII letters and ignores the locale, returning
+%FALSE for all non-ASCII characters. Also unlike the standard
+library function, this takes a char, not an int, so don't call it
+on EOF but no need to cast to guchar before passing a possibly
+non-ASCII character in.
+
+
+@c: any characted
+@Returns: %TRUE if @c is an ASCII punctuation character.
+
+
+
+
+Determines whether a character is a white-space character.
+
+
+Unlike the standard C library isspace function, this only
+recognizes standard ASCII white-space and ignores the locale, returning
+%FALSE for all non-ASCII characters. Also unlike the standard
+library function, this takes a char, not an int, so don't call it
+on EOF but no need to cast to guchar before passing a possibly
+non-ASCII character in.
+
+
+@c: any characted
+@Returns: %TRUE if @c is an ASCII white-space character
+
+
+
+
+Determines whether a character is an ASCII upper case letter.
+
+
+Unlike the standard C library isupper function, this only
+recognizes standard ASCII letters and ignores the locale, returning
+%FALSE for all non-ASCII characters. Also unlike the standard
+library function, this takes a char, not an int, so don't call it
+on EOF but no need to worry about casting to guchar before passing
+a possibly non-ASCII character in.
+
+
+@c: any characted
+@Returns: %TRUE if @c is an ASCII upper case letter
+
+
+
+
+Determines whether a character is a hexadecimal-digit character.
+
+
+Unlike the standard C library isxdigit function, this only
+recognizes standard ASCII hexadecimal digits and ignores the
+locale, returning %FALSE for all non-ASCII characters. Also unlike
+the standard library function, this takes a char, not an int, so
+don't call it on EOF but no need to cast to guchar before passing a
+possibly non-ASCII character in.
+
+
+@c: any characted
+@Returns: %TRUE if @c is an ASCII hexadecimal-digit character.
+
+
+
+
+
+
+
+@c:
+@Returns:
+
+
+
+
+
+
+
+@c:
+@Returns:
+
+
+
+
+
+
+
+@s1:
+@s2:
+@Returns:
+
+
+
+
+
+
+
+@s1:
+@s2:
+@n:
+@Returns:
+
+
+
+
+
+
+
+@string:
+@Returns:
+
+
+
+
+
+
+
+@string:
+@Returns:
+
+
+
+
+
+
+
+@c:
+@Returns:
+
+
+
+
+
+
+
+@c:
+@Returns:
+
+
+
+
+
+
+
+@string:
+@Returns:
+
+
+
+
+
+
+
+@string:
+@Returns:
+
+
Converts a string to upper case.
diff --git a/glib/gstrfuncs.c b/glib/gstrfuncs.c
index 45dfe956b..eb0393d9e 100644
--- a/glib/gstrfuncs.c
+++ b/glib/gstrfuncs.c
@@ -53,6 +53,26 @@
* inteferes with g_strsignal() on some OSes
*/
+const guint16 g_ascii_table[256] = {
+ 0x004, 0x004, 0x004, 0x004, 0x004, 0x004, 0x004, 0x004,
+ 0x004, 0x104, 0x104, 0x004, 0x104, 0x104, 0x004, 0x004,
+ 0x004, 0x004, 0x004, 0x004, 0x004, 0x004, 0x004, 0x004,
+ 0x004, 0x004, 0x004, 0x004, 0x004, 0x004, 0x004, 0x004,
+ 0x140, 0x0d0, 0x0d0, 0x0d0, 0x0d0, 0x0d0, 0x0d0, 0x0d0,
+ 0x0d0, 0x0d0, 0x0d0, 0x0d0, 0x0d0, 0x0d0, 0x0d0, 0x0d0,
+ 0x459, 0x459, 0x459, 0x459, 0x459, 0x459, 0x459, 0x459,
+ 0x459, 0x459, 0x0d0, 0x0d0, 0x0d0, 0x0d0, 0x0d0, 0x0d0,
+ 0x0d0, 0x653, 0x653, 0x653, 0x653, 0x653, 0x653, 0x253,
+ 0x253, 0x253, 0x253, 0x253, 0x253, 0x253, 0x253, 0x253,
+ 0x253, 0x253, 0x253, 0x253, 0x253, 0x253, 0x253, 0x253,
+ 0x253, 0x253, 0x253, 0x0d0, 0x0d0, 0x0d0, 0x0d0, 0x0d0,
+ 0x0d0, 0x473, 0x473, 0x473, 0x473, 0x473, 0x473, 0x073,
+ 0x073, 0x073, 0x073, 0x073, 0x073, 0x073, 0x073, 0x073,
+ 0x073, 0x073, 0x073, 0x073, 0x073, 0x073, 0x073, 0x073,
+ 0x073, 0x073, 0x073, 0x0d0, 0x0d0, 0x0d0, 0x0d0, 0x004
+ /* the upper 128 are all zeroes */
+};
+
gchar*
g_strdup (const gchar *str)
{
@@ -1080,91 +1100,6 @@ g_strreverse (gchar *string)
return string;
}
-/**
- * g_ascii_isalpha:
- * @c: any character
- *
- * Determines whether a character is alphabetic (i.e. a letter).
- *
- * Unlike the standard C library isalpha function, this only
- * recognizes standard ASCII letters and ignores the locale, returning
- * %FALSE for all non-ASCII characters. Also unlike the standard
- * library function, this takes a char, not an int, so don't call it
- * on EOF but no need to cast to guchar before passing a possibly
- * non-ASCII character in.
- *
- * Return value: %TRUE if @c is an ASCII alphabetic character
- **/
-gboolean
-g_ascii_isalpha (gchar c)
-{
- return g_ascii_islower (c) || g_ascii_isupper (c);
-}
-
-/**
- * g_ascii_isalnum:
- * @c: any character
- *
- * Determines whether a character is alphanumeric.
- *
- * Unlike the standard C library isalnum function, this only
- * recognizes standard ASCII letters and ignores the locale, returning
- * %FALSE for all non-ASCII characters. Also unlike the standard
- * library function, this takes a char, not an int, so don't call it
- * on EOF but no need to cast to guchar before passing a possibly
- * non-ASCII character in.
- *
- * Return value: %TRUE if @c is an ASCII alphanumeric character
- **/
-gboolean
-g_ascii_isalnum (gchar c)
-{
- return g_ascii_isalpha (c) || isdigit (c);
-}
-
-
-/**
- * g_ascii_islower:
- * @c: any character
- *
- * Determines whether a character is an ASCII lower case letter.
- *
- * Unlike the standard C library islower function, this only
- * recognizes standard ASCII letters and ignores the locale, returning
- * %FALSE for all non-ASCII characters. Also unlike the standard
- * library function, this takes a char, not an int, so don't call it
- * on EOF but no need to worry about casting to guchar before passing
- * a possibly non-ASCII character in.
- *
- * Return value: %TRUE if @c is an ASCII lower case letter
- **/
-gboolean
-g_ascii_islower (gchar c)
-{
- return c >= 'a' && c <= 'z';
-}
-
-/**
- * g_ascii_isupper:
- * @c: any character
- *
- * Determines whether a character is an ASCII upper case letter.
- *
- * Unlike the standard C library isupper function, this only
- * recognizes standard ASCII letters and ignores the locale, returning
- * %FALSE for all non-ASCII characters. Also unlike the standard
- * library function, this takes a char, not an int, so don't call it
- * on EOF but no need to worry about casting to guchar before passing
- * a possibly non-ASCII character in.
- *
- * Return value: %TRUE if @c is an ASCII upper case letter
- **/
-gboolean
-g_ascii_isupper (gchar c)
-{
- return c >= 'A' && c <= 'Z';
-}
-
/**
* g_ascii_tolower:
* @c: any character
@@ -1213,6 +1148,48 @@ g_ascii_toupper (gchar c)
return g_ascii_islower (c) ? c - 'a' + 'A' : c;
}
+/**
+ * g_ascii_digit_value:
+ * @c: an ASCII character
+ *
+ * Determines the numeric value of a character as a decimal
+ * digit. Differs from g_unichar_digit_value because it takes
+ * a char, so there's no worry about sign extension if characters
+ * are signed.
+ *
+ * Return value: If @c is a decimal digit (according to
+ * `g_ascii_isdigit'), its numeric value. Otherwise, -1.
+ **/
+int
+g_ascii_digit_value (gchar c)
+{
+ if (g_ascii_isdigit (c))
+ return c - '0';
+ return -1;
+}
+
+/**
+ * g_ascii_xdigit_value:
+ * @c: an ASCII character
+ *
+ * Determines the numeric value of a character as a hexidecimal
+ * digit. Differs from g_unichar_xdigit_value because it takes
+ * a char, so there's no worry about sign extension if characters
+ * are signed.
+ *
+ * Return value: If @c is a hex digit (according to
+ * `g_ascii_isxdigit'), its numeric value. Otherwise, -1.
+ **/
+int
+g_ascii_xdigit_value (gchar c)
+{
+ if (c >= 'A' && c <= 'F')
+ return c - 'A' + 10;
+ if (c >= 'a' && c <= 'f')
+ return c - 'a' + 10;
+ return g_ascii_digit_value (c);
+}
+
/**
* g_ascii_strcasecmp:
* @s1: string to compare with @s2
diff --git a/glib/gstrfuncs.h b/glib/gstrfuncs.h
index 434626639..95667aa99 100644
--- a/glib/gstrfuncs.h
+++ b/glib/gstrfuncs.h
@@ -33,13 +33,61 @@
G_BEGIN_DECLS
/* Functions like the ones in that are not affected by locale. */
-gboolean g_ascii_isalpha (gchar c) G_GNUC_CONST;
-gboolean g_ascii_isalnum (gchar c) G_GNUC_CONST;
-gboolean g_ascii_islower (gchar c) G_GNUC_CONST;
-gboolean g_ascii_isupper (gchar c) G_GNUC_CONST;
+typedef enum {
+ G_ASCII_ALNUM = 1 << 0,
+ G_ASCII_ALPHA = 1 << 1,
+ G_ASCII_CNTRL = 1 << 2,
+ G_ASCII_DIGIT = 1 << 3,
+ G_ASCII_GRAPH = 1 << 4,
+ G_ASCII_LOWER = 1 << 5,
+ G_ASCII_PRINT = 1 << 6,
+ G_ASCII_PUNCT = 1 << 7,
+ G_ASCII_SPACE = 1 << 8,
+ G_ASCII_UPPER = 1 << 9,
+ G_ASCII_XDIGIT = 1 << 10
+} GAsciiType;
+
+extern const guint16 g_ascii_table[256];
+
+#define g_ascii_isalnum(c) \
+ ((g_ascii_table[(guchar) (c)] & G_ASCII_ALNUM) != 0)
+
+#define g_ascii_isalpha(c) \
+ ((g_ascii_table[(guchar) (c)] & G_ASCII_ALPHA) != 0)
+
+#define g_ascii_iscntrl(c) \
+ ((g_ascii_table[(guchar) (c)] & G_ASCII_CNTRL) != 0)
+
+#define g_ascii_isdigit(c) \
+ ((g_ascii_table[(guchar) (c)] & G_ASCII_DIGIT) != 0)
+
+#define g_ascii_isgraph(c) \
+ ((g_ascii_table[(guchar) (c)] & G_ASCII_GRAPH) != 0)
+
+#define g_ascii_islower(c) \
+ ((g_ascii_table[(guchar) (c)] & G_ASCII_LOWER) != 0)
+
+#define g_ascii_isprint(c) \
+ ((g_ascii_table[(guchar) (c)] & G_ASCII_PRINT) != 0)
+
+#define g_ascii_ispunct(c) \
+ ((g_ascii_table[(guchar) (c)] & G_ASCII_PUNCT) != 0)
+
+#define g_ascii_isspace(c) \
+ ((g_ascii_table[(guchar) (c)] & G_ASCII_SPACE) != 0)
+
+#define g_ascii_isupper(c) \
+ ((g_ascii_table[(guchar) (c)] & G_ASCII_UPPER) != 0)
+
+#define g_ascii_isxdigit(c) \
+ ((g_ascii_table[(guchar) (c)] & G_ASCII_XDIGIT) != 0)
+
gchar g_ascii_tolower (gchar c) G_GNUC_CONST;
gchar g_ascii_toupper (gchar c) G_GNUC_CONST;
+gint g_ascii_digit_value (gchar c) G_GNUC_CONST;
+gint g_ascii_xdigit_value (gchar c) G_GNUC_CONST;
+
/* String utility functions that modify a string argument or
* return a constant string that must not be freed.
*/
diff --git a/glib/guniprop.c b/glib/guniprop.c
index 45bc1869f..4eb637078 100644
--- a/glib/guniprop.c
+++ b/glib/guniprop.c
@@ -190,11 +190,11 @@ g_unichar_isprint (gunichar c)
* g_unichar_ispunct:
* @c: a Unicode character
*
- * Determines whether a character is punctuation.
+ * Determines whether a character is punctuation or a symbol.
* Given some UTF-8 text, obtain a character value with
* g_utf8_get_char().
*
- * Return value: %TRUE if @c is a punctuation character
+ * Return value: %TRUE if @c is a punctuation or symbol character
**/
gboolean
g_unichar_ispunct (gunichar c)
@@ -203,7 +203,9 @@ g_unichar_ispunct (gunichar c)
return (t == G_UNICODE_CONNECT_PUNCTUATION || t == G_UNICODE_DASH_PUNCTUATION
|| t == G_UNICODE_CLOSE_PUNCTUATION || t == G_UNICODE_FINAL_PUNCTUATION
|| t == G_UNICODE_INITIAL_PUNCTUATION || t == G_UNICODE_OTHER_PUNCTUATION
- || t == G_UNICODE_OPEN_PUNCTUATION);
+ || t == G_UNICODE_OPEN_PUNCTUATION || t == G_UNICODE_CURRENCY_SYMBOL
+ || t == G_UNICODE_MODIFIER_SYMBOL || t == G_UNICODE_MATH_SYMBOL
+ || t == G_UNICODE_OTHER_SYMBOL);
}
/**
@@ -230,7 +232,6 @@ g_unichar_isspace (gunichar c)
case '\n':
case '\r':
case '\f':
- case '\v': /* vertical tab - as if anyone has ever used this... */
return TRUE;
break;
@@ -444,7 +445,7 @@ g_unichar_totitle (gunichar c)
* @c: a unicode character
*
* Determines the numeric value of a character as a decimal
- * degital.
+ * digit.
*
* Return value: If @c is a decimal digit (according to
* `g_unichar_isdigit'), its numeric value. Otherwise, -1.
@@ -462,7 +463,7 @@ g_unichar_digit_value (gunichar c)
* @c: a unicode character
*
* Determines the numeric value of a character as a hexidecimal
- * degital.
+ * digit.
*
* Return value: If @c is a hex digit (according to
* `g_unichar_isxdigit'), its numeric value. Otherwise, -1.
diff --git a/tests/shell-test.c b/tests/shell-test.c
index 378c918c7..e960412e9 100644
--- a/tests/shell-test.c
+++ b/tests/shell-test.c
@@ -95,25 +95,23 @@ print_test (const gchar *cmdline, gint argc, gchar **argv,
{
gint i;
- printf ("\nCommand line was: '%s'\n", cmdline);
+ fprintf (stderr, "Command line was: '%s'\n", cmdline);
- printf ("Expected result (%d args):\n", result->argc);
+ fprintf (stderr, "Expected result (%d args):\n", result->argc);
i = 0;
while (result->argv[i])
{
- printf (" %3d '%s'\n", i, result->argv[i]);
-
+ fprintf (stderr, " %3d '%s'\n", i, result->argv[i]);
++i;
}
- printf ("Actual result (%d args):\n", argc);
+ fprintf (stderr, "Actual result (%d args):\n", argc);
i = 0;
while (argv[i])
{
- printf (" %3d '%s'\n", i, argv[i]);
-
+ fprintf (stderr, " %3d '%s'\n", i, argv[i]);
++i;
}
}
@@ -170,10 +168,7 @@ run_tests (void)
i = 0;
while (test_command_lines[i])
{
- printf ("g_shell_parse_argv() test %d - ", i);
do_argv_test (test_command_lines[i], &correct_results[i]);
- printf ("ok (%s)\n", test_command_lines[i]);
-
++i;
}
}
diff --git a/tests/strfunc-test.c b/tests/strfunc-test.c
index 9255233cf..30ff11680 100644
--- a/tests/strfunc-test.c
+++ b/tests/strfunc-test.c
@@ -30,6 +30,7 @@
#include
#include "glib.h"
#include
+#include
static gboolean any_failed = FALSE;
static gboolean failed = FALSE;
@@ -37,15 +38,17 @@ static gboolean failed = FALSE;
#define TEST(m,cond) G_STMT_START { failed = !(cond); \
if (failed) \
{ if (!m) \
- g_print ("\n(%s:%d) failed for: %s\n", __FILE__, __LINE__, ( # cond )); \
+ g_print ("(%s:%d) failed for: %s\n", __FILE__, __LINE__, ( # cond )); \
else \
- g_print ("\n(%s:%d) failed for: %s: (%s)\n", __FILE__, __LINE__, ( # cond ), (gchar*)m); \
- any_failed = TRUE; \
+ g_print ("(%s:%d) failed for: %s: (%s)\n", __FILE__, __LINE__, ( # cond ), (gchar*)m); \
+ fflush (stdout); \
+ any_failed = TRUE; \
} \
-else \
- g_print ("."); fflush (stdout); \
} G_STMT_END
+#define TEST_FAILED(message) \
+ G_STMT_START { g_print ("Error: "); g_print message; g_print ("\n"); any_failed = TRUE; } G_STMT_END
+
#define GLIB_TEST_STRING "el dorado "
static gboolean
@@ -77,6 +80,156 @@ strv_check (gchar **strv, ...)
return ok;
}
+static gboolean
+test_isalnum (gchar c)
+{
+ return g_ascii_isalnum (c);
+}
+
+static gboolean
+test_isalpha (gchar c)
+{
+ return g_ascii_isalpha (c);
+}
+
+static gboolean
+test_iscntrl (gchar c)
+{
+ return g_ascii_iscntrl (c);
+}
+
+static gboolean
+test_isdigit (gchar c)
+{
+ return g_ascii_isdigit (c);
+}
+
+static gboolean
+test_isgraph (gchar c)
+{
+ return g_ascii_isgraph (c);
+}
+
+static gboolean
+test_islower (gchar c)
+{
+ return g_ascii_islower (c);
+}
+
+static gboolean
+test_isprint (gchar c)
+{
+ return g_ascii_isprint (c);
+}
+
+static gboolean
+test_ispunct (gchar c)
+{
+ return g_ascii_ispunct (c);
+}
+
+static gboolean
+test_isspace (gchar c)
+{
+ return g_ascii_isspace (c);
+}
+
+static gboolean
+test_isupper (gchar c)
+{
+ return g_ascii_isupper (c);
+}
+
+static gboolean
+test_isxdigit (gchar c)
+{
+ return g_ascii_isxdigit (c);
+}
+
+
+
+static void
+test_is_function (const char *name,
+ gboolean (* ascii_function) (gchar),
+ int (* c_library_function) (int),
+ gboolean (* unicode_function) (gunichar))
+{
+ int c;
+
+ for (c = 0; c <= 0x7F; c++)
+ {
+ gboolean ascii_result = ascii_function ((gchar)c);
+ gboolean c_library_result = c_library_function (c) != 0;
+ gboolean unicode_result = unicode_function ((gunichar) c);
+ if (ascii_result != c_library_result && c != '\v')
+ TEST_FAILED (("g_ascii_%s returned %d and %s returned %d for 0x%X",
+ name, ascii_result, name, c_library_result, c));
+ if (ascii_result != unicode_result)
+ TEST_FAILED (("g_ascii_%s returned %d and g_unichar_%s returned %d for 0x%X",
+ name, ascii_result, name, unicode_result, c));
+ }
+ for (c = 0x80; c <= 0xFF; c++)
+ {
+ gboolean ascii_result = ascii_function ((gchar)c);
+ if (ascii_result)
+ TEST_FAILED (("g_ascii_%s returned TRUE for 0x%X",
+ name, c));
+ }
+}
+
+static void
+test_to_function (const char *name,
+ gchar (* ascii_function) (gchar),
+ int (* c_library_function) (int),
+ gunichar (* unicode_function) (gunichar))
+{
+ int c;
+
+ for (c = 0; c <= 0x7F; c++)
+ {
+ int ascii_result = (guchar) ascii_function ((gchar) c);
+ int c_library_result = c_library_function (c);
+ int unicode_result = unicode_function ((gunichar) c);
+ if (ascii_result != c_library_result)
+ TEST_FAILED (("g_ascii_%s returned 0x%X and %s returned 0x%X for 0x%X",
+ name, ascii_result, name, c_library_result, c));
+ if (ascii_result != unicode_result)
+ TEST_FAILED (("g_ascii_%s returned 0x%X and g_unichar_%s returned 0x%X for 0x%X",
+ name, ascii_result, name, unicode_result, c));
+ }
+ for (c = 0x80; c <= 0xFF; c++)
+ {
+ int ascii_result = (guchar) ascii_function ((gchar) c);
+ if (ascii_result != c)
+ TEST_FAILED (("g_ascii_%s returned 0x%X for 0x%X",
+ name, ascii_result, c));
+ }
+}
+
+static void
+test_digit_function (const char *name,
+ int (* ascii_function) (gchar),
+ int (* unicode_function) (gunichar))
+{
+ int c;
+
+ for (c = 0; c <= 0x7F; c++)
+ {
+ int ascii_result = ascii_function ((gchar) c);
+ int unicode_result = unicode_function ((gunichar) c);
+ if (ascii_result != unicode_result)
+ TEST_FAILED (("g_ascii_%s_value returned %d and g_unichar_%s_value returned %d for 0x%X",
+ name, ascii_result, name, unicode_result, c));
+ }
+ for (c = 0x80; c <= 0xFF; c++)
+ {
+ int ascii_result = ascii_function ((gchar) c);
+ if (ascii_result != -1)
+ TEST_FAILED (("g_ascii_%s_value returned %d for 0x%X",
+ name, ascii_result, c));
+ }
+}
+
int
main (int argc,
char *argv[])
@@ -171,7 +324,35 @@ main (int argc,
TEST (NULL, strv_check (g_strsplit (",,x,,y,,z,,", ",", 2), "", ",x,,y,,z,,", NULL));
TEST (NULL, strv_check (g_strsplit (",,x,,y,,z,,", ",,", 2), "", "x,,y,,z,,", NULL));
- g_print ("\n");
+ #define TEST_IS(name) test_is_function (#name, test_##name, name, g_unichar_##name)
+
+ TEST_IS (isalnum);
+ TEST_IS (isalpha);
+ TEST_IS (iscntrl);
+ TEST_IS (isdigit);
+ TEST_IS (isgraph);
+ TEST_IS (islower);
+ TEST_IS (isprint);
+ TEST_IS (ispunct);
+ TEST_IS (isspace);
+ TEST_IS (isupper);
+ TEST_IS (isxdigit);
+
+ #undef TEST_IS
+
+ #define TEST_TO(name) test_to_function (#name, g_ascii_##name, name, g_unichar_##name)
+
+ TEST_TO (tolower);
+ TEST_TO (toupper);
+
+ #undef TEST_TO
+
+ #define TEST_DIGIT(name) test_digit_function (#name, g_ascii_##name##_value, g_unichar_##name##_value)
+
+ TEST_DIGIT (digit);
+ TEST_DIGIT (xdigit);
+
+ #undef TEST_DIGIT
return any_failed;
}