X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=lib%2Fc-ctype.h;h=a9886a09516ab918653f6aac75e132812a9b8dd3;hb=f62a2da1390a78aebe7dcbc5753ba7a2b34cf1fd;hp=0f69e1071fd229540926519260fc6927b4a479ce;hpb=f02c0a8f143140d93e855ed7ccd31779e707381d;p=gnulib.git diff --git a/lib/c-ctype.h b/lib/c-ctype.h index 0f69e1071..a9886a095 100644 --- a/lib/c-ctype.h +++ b/lib/c-ctype.h @@ -5,7 +5,7 @@ functions' behaviour depends on the current locale set via setlocale. - Copyright (C) 2000-2003 Free Software Foundation, Inc. + Copyright (C) 2000-2003, 2006, 2008-2012 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -18,8 +18,7 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ +along with this program; if not, see . */ #ifndef C_CTYPE_H #define C_CTYPE_H @@ -27,6 +26,19 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include +#ifdef __cplusplus +extern "C" { +#endif + + +/* The functions defined in this file assume the "C" locale and a character + set without diacritics (ASCII-US or EBCDIC-US or something like that). + Even if the "C" locale on a particular system is an extension of the ASCII + character set (like on BeOS, where it is UTF-8, or on AmigaOS, where it + is ISO-8859-1), the functions in this file recognize only the ASCII + characters. */ + + /* Check whether the ASCII optimizations apply. */ /* ANSI C89 (and ISO C99 5.2.1.3 too) already guarantees that @@ -82,8 +94,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ && ('s' == 115) && ('t' == 116) && ('u' == 117) && ('v' == 118) \ && ('w' == 119) && ('x' == 120) && ('y' == 121) && ('z' == 122) \ && ('{' == 123) && ('|' == 124) && ('}' == 125) && ('~' == 126) -/* The character set is ISO646-US, not EBCDIC. - The test of '$' is important to distinguish it from other ISO646 variants. +/* The character set is ASCII or one of its variants or extensions, not EBCDIC. Testing the value of '\n' and '\r' is not relevant. */ #define C_CTYPE_ASCII 1 #endif @@ -91,43 +102,61 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* Function declarations. */ -extern bool c_isascii (int c); /* not locale dependent */ +/* Unlike the functions in , which require an argument in the range + of the 'unsigned char' type, the functions here operate on values that are + in the 'unsigned char' range or in the 'char' range. In other words, + when you have a 'char' value, you need to cast it before using it as + argument to a function: + + const char *s = ...; + if (isalpha ((unsigned char) *s)) ... -extern bool c_isalnum (int c); -extern bool c_isalpha (int c); -extern bool c_isblank (int c); -extern bool c_iscntrl (int c); -extern bool c_isdigit (int c); -extern bool c_islower (int c); -extern bool c_isgraph (int c); -extern bool c_isprint (int c); -extern bool c_ispunct (int c); -extern bool c_isspace (int c); -extern bool c_isupper (int c); -extern bool c_isxdigit (int c); + but you don't need to cast it for the functions defined in this file: -extern int c_tolower (int c); -extern int c_toupper (int c); + const char *s = ...; + if (c_isalpha (*s)) ... + */ +extern bool c_isascii (int c) _GL_ATTRIBUTE_CONST; /* not locale dependent */ -#if defined __GNUC__ && defined __OPTIMIZE__ && !defined __OPTIMIZE_SIZE__ +extern bool c_isalnum (int c) _GL_ATTRIBUTE_CONST; +extern bool c_isalpha (int c) _GL_ATTRIBUTE_CONST; +extern bool c_isblank (int c) _GL_ATTRIBUTE_CONST; +extern bool c_iscntrl (int c) _GL_ATTRIBUTE_CONST; +extern bool c_isdigit (int c) _GL_ATTRIBUTE_CONST; +extern bool c_islower (int c) _GL_ATTRIBUTE_CONST; +extern bool c_isgraph (int c) _GL_ATTRIBUTE_CONST; +extern bool c_isprint (int c) _GL_ATTRIBUTE_CONST; +extern bool c_ispunct (int c) _GL_ATTRIBUTE_CONST; +extern bool c_isspace (int c) _GL_ATTRIBUTE_CONST; +extern bool c_isupper (int c) _GL_ATTRIBUTE_CONST; +extern bool c_isxdigit (int c) _GL_ATTRIBUTE_CONST; + +extern int c_tolower (int c) _GL_ATTRIBUTE_CONST; +extern int c_toupper (int c) _GL_ATTRIBUTE_CONST; + + +#if defined __GNUC__ && defined __OPTIMIZE__ && !defined __OPTIMIZE_SIZE__ && !defined NO_C_CTYPE_MACROS /* ASCII optimizations. */ +#undef c_isascii #define c_isascii(c) \ ({ int __c = (c); \ - ((__c & ~0x7f) == 0); \ + (__c >= 0x00 && __c <= 0x7f); \ }) #if C_CTYPE_CONSECUTIVE_DIGITS \ && C_CTYPE_CONSECUTIVE_UPPERCASE && C_CTYPE_CONSECUTIVE_LOWERCASE #if C_CTYPE_ASCII +#undef c_isalnum #define c_isalnum(c) \ ({ int __c = (c); \ ((__c >= '0' && __c <= '9') \ || ((__c & ~0x20) >= 'A' && (__c & ~0x20) <= 'Z')); \ }) #else +#undef c_isalnum #define c_isalnum(c) \ ({ int __c = (c); \ ((__c >= '0' && __c <= '9') \ @@ -139,11 +168,13 @@ extern int c_toupper (int c); #if C_CTYPE_CONSECUTIVE_UPPERCASE && C_CTYPE_CONSECUTIVE_LOWERCASE #if C_CTYPE_ASCII +#undef c_isalpha #define c_isalpha(c) \ ({ int __c = (c); \ ((__c & ~0x20) >= 'A' && (__c & ~0x20) <= 'Z'); \ }) #else +#undef c_isalpha #define c_isalpha(c) \ ({ int __c = (c); \ ((__c >= 'A' && __c <= 'Z') || (__c >= 'a' && __c <= 'z')); \ @@ -151,12 +182,14 @@ extern int c_toupper (int c); #endif #endif +#undef c_isblank #define c_isblank(c) \ ({ int __c = (c); \ (__c == ' ' || __c == '\t'); \ }) #if C_CTYPE_ASCII +#undef c_iscntrl #define c_iscntrl(c) \ ({ int __c = (c); \ ((__c & ~0x1f) == 0 || __c == 0x7f); \ @@ -164,6 +197,7 @@ extern int c_toupper (int c); #endif #if C_CTYPE_CONSECUTIVE_DIGITS +#undef c_isdigit #define c_isdigit(c) \ ({ int __c = (c); \ (__c >= '0' && __c <= '9'); \ @@ -171,6 +205,7 @@ extern int c_toupper (int c); #endif #if C_CTYPE_CONSECUTIVE_LOWERCASE +#undef c_islower #define c_islower(c) \ ({ int __c = (c); \ (__c >= 'a' && __c <= 'z'); \ @@ -178,6 +213,7 @@ extern int c_toupper (int c); #endif #if C_CTYPE_ASCII +#undef c_isgraph #define c_isgraph(c) \ ({ int __c = (c); \ (__c >= '!' && __c <= '~'); \ @@ -185,6 +221,7 @@ extern int c_toupper (int c); #endif #if C_CTYPE_ASCII +#undef c_isprint #define c_isprint(c) \ ({ int __c = (c); \ (__c >= ' ' && __c <= '~'); \ @@ -192,12 +229,14 @@ extern int c_toupper (int c); #endif #if C_CTYPE_ASCII +#undef c_ispunct #define c_ispunct(c) \ ({ int _c = (c); \ (c_isgraph (_c) && ! c_isalnum (_c)); \ }) #endif +#undef c_isspace #define c_isspace(c) \ ({ int __c = (c); \ (__c == ' ' || __c == '\t' \ @@ -205,6 +244,7 @@ extern int c_toupper (int c); }) #if C_CTYPE_CONSECUTIVE_UPPERCASE +#undef c_isupper #define c_isupper(c) \ ({ int __c = (c); \ (__c >= 'A' && __c <= 'Z'); \ @@ -214,12 +254,14 @@ extern int c_toupper (int c); #if C_CTYPE_CONSECUTIVE_DIGITS \ && C_CTYPE_CONSECUTIVE_UPPERCASE && C_CTYPE_CONSECUTIVE_LOWERCASE #if C_CTYPE_ASCII +#undef c_isxdigit #define c_isxdigit(c) \ ({ int __c = (c); \ ((__c >= '0' && __c <= '9') \ || ((__c & ~0x20) >= 'A' && (__c & ~0x20) <= 'F')); \ }) #else +#undef c_isxdigit #define c_isxdigit(c) \ ({ int __c = (c); \ ((__c >= '0' && __c <= '9') \ @@ -230,10 +272,12 @@ extern int c_toupper (int c); #endif #if C_CTYPE_CONSECUTIVE_UPPERCASE && C_CTYPE_CONSECUTIVE_LOWERCASE +#undef c_tolower #define c_tolower(c) \ ({ int __c = (c); \ (__c >= 'A' && __c <= 'Z' ? __c - 'A' + 'a' : __c); \ }) +#undef c_toupper #define c_toupper(c) \ ({ int __c = (c); \ (__c >= 'a' && __c <= 'z' ? __c - 'a' + 'A' : __c); \ @@ -242,4 +286,9 @@ extern int c_toupper (int c); #endif /* optimizing for speed */ + +#ifdef __cplusplus +} +#endif + #endif /* C_CTYPE_H */