summaryrefslogtreecommitdiff
path: root/glib/gstrfuncs.c
diff options
context:
space:
mode:
authorAlexander Larsson <alla@lysator.liu.se>2001-08-25 22:29:40 +0000
committerAlexander Larsson <alexl@src.gnome.org>2001-08-25 22:29:40 +0000
commita7a76cfac798e3a924b3899d89398f2f4b9539b6 (patch)
tree5039eafd3d25ce89a2661ffee7e4fe3da15bbcf6 /glib/gstrfuncs.c
parent3ff815fd7c60bef7dadb6b8f9bf4cf6f858e8b4e (diff)
downloadglib-a7a76cfac798e3a924b3899d89398f2f4b9539b6.tar.gz
Implement and document g_ascii_isxxx.
2001-08-25 Alexander Larsson <alla@lysator.liu.se> * glib/gstrfuncs.[ch]: * docs/reference/glib/glib-overrides.txt: * docs/reference/glib/glib-sections.txt: * docs/reference/glib/tmpl/string_utils.sgml: Implement and document g_ascii_isxxx. * tests/strfunc-test.c: Add tests for g_ascii_isxxx * glib/guniprop.c (g_unichar_ispunct): include symbols, not just punctuation. (g_unichar_isspace): Vertical tab is not considered whitespace. * tests/shell-test.c: Output errors on stderr
Diffstat (limited to 'glib/gstrfuncs.c')
-rw-r--r--glib/gstrfuncs.c147
1 files changed, 62 insertions, 85 deletions
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)
{
@@ -1081,91 +1101,6 @@ g_strreverse (gchar *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
*
@@ -1214,6 +1149,48 @@ g_ascii_toupper (gchar 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
* @s2: string to compare with @s1