X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=lib%2Fmbchar.h;h=ccbcb827e5de2086768361788223ed10f4d8e47c;hb=d0ea2a12f6fb377f930886d404f3dfc2a732537d;hp=52b1075786a49e1f2c5b15ea61d2c06b44a957d4;hpb=006f345f21c7de64843458145be7c2e1504e1a5b;p=gnulib.git diff --git a/lib/mbchar.h b/lib/mbchar.h index 52b107578..ccbcb827e 100644 --- a/lib/mbchar.h +++ b/lib/mbchar.h @@ -1,10 +1,10 @@ /* Multibyte character data type. - Copyright (C) 2001, 2005-2006 Free Software Foundation, Inc. + Copyright (C) 2001, 2005-2007, 2009-2012 Free Software Foundation, Inc. - This program is free software; you can redistribute it and/or modify + 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 - the Free Software Foundation; either version 2, or (at your option) - any later version. + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of @@ -12,8 +12,7 @@ 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 . */ /* Written by Bruno Haible . */ @@ -115,31 +114,31 @@ Here are the function prototypes of the macros. - extern const char * mb_ptr (const mbchar_t mbc); - extern size_t mb_len (const mbchar_t mbc); - extern bool mb_iseq (const mbchar_t mbc, char sc); - extern bool mb_isnul (const mbchar_t mbc); - extern int mb_cmp (const mbchar_t mbc1, const mbchar_t mbc2); - extern int mb_casecmp (const mbchar_t mbc1, const mbchar_t mbc2); - extern bool mb_equal (const mbchar_t mbc1, const mbchar_t mbc2); - extern bool mb_caseequal (const mbchar_t mbc1, const mbchar_t mbc2); - extern bool mb_isalnum (const mbchar_t mbc); - extern bool mb_isalpha (const mbchar_t mbc); - extern bool mb_isascii (const mbchar_t mbc); - extern bool mb_isblank (const mbchar_t mbc); - extern bool mb_iscntrl (const mbchar_t mbc); - extern bool mb_isdigit (const mbchar_t mbc); - extern bool mb_isgraph (const mbchar_t mbc); - extern bool mb_islower (const mbchar_t mbc); - extern bool mb_isprint (const mbchar_t mbc); - extern bool mb_ispunct (const mbchar_t mbc); - extern bool mb_isspace (const mbchar_t mbc); - extern bool mb_isupper (const mbchar_t mbc); - extern bool mb_isxdigit (const mbchar_t mbc); - extern int mb_width (const mbchar_t mbc); - extern void mb_putc (const mbchar_t mbc, FILE *stream); + extern const char * mb_ptr (const mbchar_t mbc); + extern size_t mb_len (const mbchar_t mbc); + extern bool mb_iseq (const mbchar_t mbc, char sc); + extern bool mb_isnul (const mbchar_t mbc); + extern int mb_cmp (const mbchar_t mbc1, const mbchar_t mbc2); + extern int mb_casecmp (const mbchar_t mbc1, const mbchar_t mbc2); + extern bool mb_equal (const mbchar_t mbc1, const mbchar_t mbc2); + extern bool mb_caseequal (const mbchar_t mbc1, const mbchar_t mbc2); + extern bool mb_isalnum (const mbchar_t mbc); + extern bool mb_isalpha (const mbchar_t mbc); + extern bool mb_isascii (const mbchar_t mbc); + extern bool mb_isblank (const mbchar_t mbc); + extern bool mb_iscntrl (const mbchar_t mbc); + extern bool mb_isdigit (const mbchar_t mbc); + extern bool mb_isgraph (const mbchar_t mbc); + extern bool mb_islower (const mbchar_t mbc); + extern bool mb_isprint (const mbchar_t mbc); + extern bool mb_ispunct (const mbchar_t mbc); + extern bool mb_isspace (const mbchar_t mbc); + extern bool mb_isupper (const mbchar_t mbc); + extern bool mb_isxdigit (const mbchar_t mbc); + extern int mb_width (const mbchar_t mbc); + extern void mb_putc (const mbchar_t mbc, FILE *stream); extern void mb_setascii (mbchar_t *new, char sc); - extern void mb_copy (mbchar_t *new, const mbchar_t *old); + extern void mb_copy (mbchar_t *new, const mbchar_t *old); */ #ifndef _MBCHAR_H @@ -155,140 +154,16 @@ #include #include #include - #include -/* FreeBSD 4.4 to 4.11 has but lacks the functions. - Assume all 12 functions are implemented the same way, or not at all. */ -#if !defined iswalnum && !HAVE_ISWCNTRL -static inline int -iswalnum (wint_t wc) -{ - return (wc >= 0 && wc < 128 - ? (wc >= '0' && wc <= '9') || ((wc & ~0x20) >= 'A' && (wc & ~0x20) <= 'Z') - : 0); -} -# define iswalnum iswalnum -#endif -#if !defined iswalpha && !HAVE_ISWCNTRL -static inline int -iswalpha (wint_t wc) -{ - return (wc >= 0 && wc < 128 - ? (wc & ~0x20) >= 'A' && (wc & ~0x20) <= 'Z' - : 0); -} -# define iswalpha iswalpha -#endif -#if !defined iswblank && !HAVE_ISWCNTRL -static inline int -iswblank (wint_t wc) -{ - return (wc >= 0 && wc < 128 - ? wc == ' ' || wc == '\t' - : 0); -} -# define iswblank iswblank -#endif -#if !defined iswcntrl && !HAVE_ISWCNTRL -static inline int -iswcntrl (wint_t wc) -{ - return (wc >= 0 && wc < 128 - ? (wc & ~0x1f) == 0 || wc == 0x7f - : 0); -} -# define iswcntrl iswcntrl -#endif -#if !defined iswdigit && !HAVE_ISWCNTRL -static inline int -iswdigit (wint_t wc) -{ - return (wc >= '0' && wc <= '9'); -} -# define iswdigit iswdigit -#endif -#if !defined iswgraph && !HAVE_ISWCNTRL -static inline int -iswgraph (wint_t wc) -{ - return (wc >= 0 && wc < 128 - ? wc >= '!' && wc <= '~' - : 1); -} -# define iswgraph iswgraph -#endif -#if !defined iswlower && !HAVE_ISWCNTRL -static inline int -iswlower (wint_t wc) -{ - return (wc >= 0 && wc < 128 - ? wc >= 'a' && wc <= 'z' - : 0); -} -# define iswlower iswlower -#endif -#if !defined iswprint && !HAVE_ISWCNTRL -static inline int -iswprint (wint_t wc) -{ - return (wc >= 0 && wc < 128 - ? wc >= ' ' && wc <= '~' - : 1); -} -# define iswprint iswprint -#endif -#if !defined iswpunct && !HAVE_ISWCNTRL -static inline int -iswpunct (wint_t wc) -{ - return (wc >= 0 && wc < 128 - ? wc >= '!' && wc <= '~' - && !((wc >= '0' && wc <= '9') - || ((wc & ~0x20) >= 'A' && (wc & ~0x20) <= 'Z')) - : 1); -} -# define iswpunct iswpunct -#endif -#if !defined iswspace && !HAVE_ISWCNTRL -static inline int -iswspace (wint_t wc) -{ - return (wc >= 0 && wc < 128 - ? wc == ' ' || wc == '\t' - || wc == '\n' || wc == '\v' || wc == '\f' || wc == '\r' - : 0); -} -# define iswspace iswspace -#endif -#if !defined iswupper && !HAVE_ISWCNTRL -static inline int -iswupper (wint_t wc) -{ - return (wc >= 0 && wc < 128 - ? wc >= 'A' && wc <= 'Z' - : 0); -} -# define iswupper iswupper -#endif -#if !defined iswxdigit && !HAVE_ISWCNTRL -static inline int -iswxdigit (wint_t wc) -{ - return (wc >= '0' && wc <= '9') || ((wc & ~0x20) >= 'A' && (wc & ~0x20) <= 'F'); -} -# define iswxdigit iswxdigit -#endif - -#include "wcwidth.h" #define MBCHAR_BUF_SIZE 24 struct mbchar { - const char *ptr; /* pointer to current character */ - size_t bytes; /* number of bytes of current character, > 0 */ - bool wc_valid; /* true if wc is a valid wide character */ - wchar_t wc; /* if wc_valid: the current character */ + const char *ptr; /* pointer to current character */ + size_t bytes; /* number of bytes of current character, > 0 */ + bool wc_valid; /* true if wc is a valid wide character */ + wchar_t wc; /* if wc_valid: the current character */ char buf[MBCHAR_BUF_SIZE]; /* room for the bytes, used for file input only */ }; @@ -305,38 +180,38 @@ typedef struct mbchar mbchar_t; #define mb_iseq(mbc, sc) ((mbc).wc_valid && (mbc).wc == (sc)) #define mb_isnul(mbc) ((mbc).wc_valid && (mbc).wc == 0) #define mb_cmp(mbc1, mbc2) \ - ((mbc1).wc_valid \ - ? ((mbc2).wc_valid \ - ? (int) (mbc1).wc - (int) (mbc2).wc \ - : -1) \ - : ((mbc2).wc_valid \ - ? 1 \ - : (mbc1).bytes == (mbc2).bytes \ - ? memcmp ((mbc1).ptr, (mbc2).ptr, (mbc1).bytes) \ - : (mbc1).bytes < (mbc2).bytes \ + ((mbc1).wc_valid \ + ? ((mbc2).wc_valid \ + ? (int) (mbc1).wc - (int) (mbc2).wc \ + : -1) \ + : ((mbc2).wc_valid \ + ? 1 \ + : (mbc1).bytes == (mbc2).bytes \ + ? memcmp ((mbc1).ptr, (mbc2).ptr, (mbc1).bytes) \ + : (mbc1).bytes < (mbc2).bytes \ ? (memcmp ((mbc1).ptr, (mbc2).ptr, (mbc1).bytes) > 0 ? 1 : -1) \ : (memcmp ((mbc1).ptr, (mbc2).ptr, (mbc2).bytes) >= 0 ? 1 : -1))) #define mb_casecmp(mbc1, mbc2) \ - ((mbc1).wc_valid \ - ? ((mbc2).wc_valid \ - ? (int) towlower ((mbc1).wc) - (int) towlower ((mbc2).wc) \ - : -1) \ - : ((mbc2).wc_valid \ - ? 1 \ - : (mbc1).bytes == (mbc2).bytes \ - ? memcmp ((mbc1).ptr, (mbc2).ptr, (mbc1).bytes) \ - : (mbc1).bytes < (mbc2).bytes \ + ((mbc1).wc_valid \ + ? ((mbc2).wc_valid \ + ? (int) towlower ((mbc1).wc) - (int) towlower ((mbc2).wc) \ + : -1) \ + : ((mbc2).wc_valid \ + ? 1 \ + : (mbc1).bytes == (mbc2).bytes \ + ? memcmp ((mbc1).ptr, (mbc2).ptr, (mbc1).bytes) \ + : (mbc1).bytes < (mbc2).bytes \ ? (memcmp ((mbc1).ptr, (mbc2).ptr, (mbc1).bytes) > 0 ? 1 : -1) \ : (memcmp ((mbc1).ptr, (mbc2).ptr, (mbc2).bytes) >= 0 ? 1 : -1))) #define mb_equal(mbc1, mbc2) \ - ((mbc1).wc_valid && (mbc2).wc_valid \ - ? (mbc1).wc == (mbc2).wc \ - : (mbc1).bytes == (mbc2).bytes \ + ((mbc1).wc_valid && (mbc2).wc_valid \ + ? (mbc1).wc == (mbc2).wc \ + : (mbc1).bytes == (mbc2).bytes \ && memcmp ((mbc1).ptr, (mbc2).ptr, (mbc1).bytes) == 0) #define mb_caseequal(mbc1, mbc2) \ - ((mbc1).wc_valid && (mbc2).wc_valid \ - ? towlower ((mbc1).wc) == towlower ((mbc2).wc) \ - : (mbc1).bytes == (mbc2).bytes \ + ((mbc1).wc_valid && (mbc2).wc_valid \ + ? towlower ((mbc1).wc) == towlower ((mbc2).wc) \ + : (mbc1).bytes == (mbc2).bytes \ && memcmp ((mbc1).ptr, (mbc2).ptr, (mbc1).bytes) == 0) /* , classification. */ @@ -382,18 +257,18 @@ mb_width_aux (wint_t wc) /* Copying a character. */ static inline void -mb_copy (mbchar_t *new, const mbchar_t *old) +mb_copy (mbchar_t *new_mbc, const mbchar_t *old_mbc) { - if (old->ptr == &old->buf[0]) + if (old_mbc->ptr == &old_mbc->buf[0]) { - memcpy (&new->buf[0], &old->buf[0], old->bytes); - new->ptr = &new->buf[0]; + memcpy (&new_mbc->buf[0], &old_mbc->buf[0], old_mbc->bytes); + new_mbc->ptr = &new_mbc->buf[0]; } else - new->ptr = old->ptr; - new->bytes = old->bytes; - if ((new->wc_valid = old->wc_valid)) - new->wc = old->wc; + new_mbc->ptr = old_mbc->ptr; + new_mbc->bytes = old_mbc->bytes; + if ((new_mbc->wc_valid = old_mbc->wc_valid)) + new_mbc->wc = old_mbc->wc; } @@ -427,13 +302,13 @@ mb_copy (mbchar_t *new, const mbchar_t *old) /* The character set is ISO-646, not EBCDIC. */ # define IS_BASIC_ASCII 1 -extern unsigned int is_basic_table[]; +extern const unsigned int is_basic_table[]; static inline bool is_basic (char c) { return (is_basic_table [(unsigned char) c >> 5] >> ((unsigned char) c & 31)) - & 1; + & 1; } #else