195b7b453SJohn Marino /* Multibyte character data type. 2*09d4459fSDaniel Fojt Copyright (C) 2001, 2005-2007, 2009-2020 Free Software Foundation, Inc. 395b7b453SJohn Marino 495b7b453SJohn Marino This program is free software: you can redistribute it and/or modify 595b7b453SJohn Marino it under the terms of the GNU General Public License as published by 695b7b453SJohn Marino the Free Software Foundation; either version 3 of the License, or 795b7b453SJohn Marino (at your option) any later version. 895b7b453SJohn Marino 995b7b453SJohn Marino This program is distributed in the hope that it will be useful, 1095b7b453SJohn Marino but WITHOUT ANY WARRANTY; without even the implied warranty of 1195b7b453SJohn Marino MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1295b7b453SJohn Marino GNU General Public License for more details. 1395b7b453SJohn Marino 1495b7b453SJohn Marino You should have received a copy of the GNU General Public License 15*09d4459fSDaniel Fojt along with this program. If not, see <https://www.gnu.org/licenses/>. */ 1695b7b453SJohn Marino 1795b7b453SJohn Marino /* Written by Bruno Haible <bruno@clisp.org>. */ 1895b7b453SJohn Marino 1995b7b453SJohn Marino /* A multibyte character is a short subsequence of a char* string, 2095b7b453SJohn Marino representing a single wide character. 2195b7b453SJohn Marino 2295b7b453SJohn Marino We use multibyte characters instead of wide characters because of 2395b7b453SJohn Marino the following goals: 2495b7b453SJohn Marino 1) correct multibyte handling, i.e. operate according to the LC_CTYPE 2595b7b453SJohn Marino locale, 2695b7b453SJohn Marino 2) ease of maintenance, i.e. the maintainer needs not know all details 2795b7b453SJohn Marino of the ISO C 99 standard, 2895b7b453SJohn Marino 3) don't fail grossly if the input is not in the encoding set by the 2995b7b453SJohn Marino locale, because often different encodings are in use in the same 3095b7b453SJohn Marino countries (ISO-8859-1/UTF-8, EUC-JP/Shift_JIS, ...), 3195b7b453SJohn Marino 4) fast in the case of ASCII characters, 3295b7b453SJohn Marino 5) portability, i.e. don't make unportable assumptions about wchar_t. 3395b7b453SJohn Marino 3495b7b453SJohn Marino Multibyte characters are only accessed through the mb* macros. 3595b7b453SJohn Marino 3695b7b453SJohn Marino mb_ptr (mbc) 3795b7b453SJohn Marino return a pointer to the beginning of the multibyte sequence. 3895b7b453SJohn Marino 3995b7b453SJohn Marino mb_len (mbc) 4095b7b453SJohn Marino returns the number of bytes occupied by the multibyte sequence. 4195b7b453SJohn Marino Always > 0. 4295b7b453SJohn Marino 4395b7b453SJohn Marino mb_iseq (mbc, sc) 4495b7b453SJohn Marino returns true if mbc is the standard ASCII character sc. 4595b7b453SJohn Marino 4695b7b453SJohn Marino mb_isnul (mbc) 4795b7b453SJohn Marino returns true if mbc is the nul character. 4895b7b453SJohn Marino 4995b7b453SJohn Marino mb_cmp (mbc1, mbc2) 5095b7b453SJohn Marino returns a positive, zero, or negative value depending on whether mbc1 5195b7b453SJohn Marino sorts after, same or before mbc2. 5295b7b453SJohn Marino 5395b7b453SJohn Marino mb_casecmp (mbc1, mbc2) 5495b7b453SJohn Marino returns a positive, zero, or negative value depending on whether mbc1 5595b7b453SJohn Marino sorts after, same or before mbc2, modulo upper/lowercase conversion. 5695b7b453SJohn Marino 5795b7b453SJohn Marino mb_equal (mbc1, mbc2) 5895b7b453SJohn Marino returns true if mbc1 and mbc2 are equal. 5995b7b453SJohn Marino 6095b7b453SJohn Marino mb_caseequal (mbc1, mbc2) 6195b7b453SJohn Marino returns true if mbc1 and mbc2 are equal modulo upper/lowercase conversion. 6295b7b453SJohn Marino 6395b7b453SJohn Marino mb_isalnum (mbc) 6495b7b453SJohn Marino returns true if mbc is alphanumeric. 6595b7b453SJohn Marino 6695b7b453SJohn Marino mb_isalpha (mbc) 6795b7b453SJohn Marino returns true if mbc is alphabetic. 6895b7b453SJohn Marino 6995b7b453SJohn Marino mb_isascii(mbc) 7095b7b453SJohn Marino returns true if mbc is plain ASCII. 7195b7b453SJohn Marino 7295b7b453SJohn Marino mb_isblank (mbc) 7395b7b453SJohn Marino returns true if mbc is a blank. 7495b7b453SJohn Marino 7595b7b453SJohn Marino mb_iscntrl (mbc) 7695b7b453SJohn Marino returns true if mbc is a control character. 7795b7b453SJohn Marino 7895b7b453SJohn Marino mb_isdigit (mbc) 7995b7b453SJohn Marino returns true if mbc is a decimal digit. 8095b7b453SJohn Marino 8195b7b453SJohn Marino mb_isgraph (mbc) 8295b7b453SJohn Marino returns true if mbc is a graphic character. 8395b7b453SJohn Marino 8495b7b453SJohn Marino mb_islower (mbc) 8595b7b453SJohn Marino returns true if mbc is lowercase. 8695b7b453SJohn Marino 8795b7b453SJohn Marino mb_isprint (mbc) 8895b7b453SJohn Marino returns true if mbc is a printable character. 8995b7b453SJohn Marino 9095b7b453SJohn Marino mb_ispunct (mbc) 9195b7b453SJohn Marino returns true if mbc is a punctuation character. 9295b7b453SJohn Marino 9395b7b453SJohn Marino mb_isspace (mbc) 9495b7b453SJohn Marino returns true if mbc is a space character. 9595b7b453SJohn Marino 9695b7b453SJohn Marino mb_isupper (mbc) 9795b7b453SJohn Marino returns true if mbc is uppercase. 9895b7b453SJohn Marino 9995b7b453SJohn Marino mb_isxdigit (mbc) 10095b7b453SJohn Marino returns true if mbc is a hexadecimal digit. 10195b7b453SJohn Marino 10295b7b453SJohn Marino mb_width (mbc) 10395b7b453SJohn Marino returns the number of columns on the output device occupied by mbc. 10495b7b453SJohn Marino Always >= 0. 10595b7b453SJohn Marino 10695b7b453SJohn Marino mb_putc (mbc, stream) 10795b7b453SJohn Marino outputs mbc on stream, a byte oriented FILE stream opened for output. 10895b7b453SJohn Marino 10995b7b453SJohn Marino mb_setascii (&mbc, sc) 11095b7b453SJohn Marino assigns the standard ASCII character sc to mbc. 11195b7b453SJohn Marino 11295b7b453SJohn Marino mb_copy (&destmbc, &srcmbc) 11395b7b453SJohn Marino copies srcmbc to destmbc. 11495b7b453SJohn Marino 11595b7b453SJohn Marino Here are the function prototypes of the macros. 11695b7b453SJohn Marino 11795b7b453SJohn Marino extern const char * mb_ptr (const mbchar_t mbc); 11895b7b453SJohn Marino extern size_t mb_len (const mbchar_t mbc); 11995b7b453SJohn Marino extern bool mb_iseq (const mbchar_t mbc, char sc); 12095b7b453SJohn Marino extern bool mb_isnul (const mbchar_t mbc); 12195b7b453SJohn Marino extern int mb_cmp (const mbchar_t mbc1, const mbchar_t mbc2); 12295b7b453SJohn Marino extern int mb_casecmp (const mbchar_t mbc1, const mbchar_t mbc2); 12395b7b453SJohn Marino extern bool mb_equal (const mbchar_t mbc1, const mbchar_t mbc2); 12495b7b453SJohn Marino extern bool mb_caseequal (const mbchar_t mbc1, const mbchar_t mbc2); 12595b7b453SJohn Marino extern bool mb_isalnum (const mbchar_t mbc); 12695b7b453SJohn Marino extern bool mb_isalpha (const mbchar_t mbc); 12795b7b453SJohn Marino extern bool mb_isascii (const mbchar_t mbc); 12895b7b453SJohn Marino extern bool mb_isblank (const mbchar_t mbc); 12995b7b453SJohn Marino extern bool mb_iscntrl (const mbchar_t mbc); 13095b7b453SJohn Marino extern bool mb_isdigit (const mbchar_t mbc); 13195b7b453SJohn Marino extern bool mb_isgraph (const mbchar_t mbc); 13295b7b453SJohn Marino extern bool mb_islower (const mbchar_t mbc); 13395b7b453SJohn Marino extern bool mb_isprint (const mbchar_t mbc); 13495b7b453SJohn Marino extern bool mb_ispunct (const mbchar_t mbc); 13595b7b453SJohn Marino extern bool mb_isspace (const mbchar_t mbc); 13695b7b453SJohn Marino extern bool mb_isupper (const mbchar_t mbc); 13795b7b453SJohn Marino extern bool mb_isxdigit (const mbchar_t mbc); 13895b7b453SJohn Marino extern int mb_width (const mbchar_t mbc); 13995b7b453SJohn Marino extern void mb_putc (const mbchar_t mbc, FILE *stream); 14095b7b453SJohn Marino extern void mb_setascii (mbchar_t *new, char sc); 14195b7b453SJohn Marino extern void mb_copy (mbchar_t *new, const mbchar_t *old); 14295b7b453SJohn Marino */ 14395b7b453SJohn Marino 14495b7b453SJohn Marino #ifndef _MBCHAR_H 14595b7b453SJohn Marino #define _MBCHAR_H 1 14695b7b453SJohn Marino 14795b7b453SJohn Marino #include <stdbool.h> 14895b7b453SJohn Marino #include <string.h> 14995b7b453SJohn Marino 15095b7b453SJohn Marino /* Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be included before 15195b7b453SJohn Marino <wchar.h>. 15295b7b453SJohn Marino BSD/OS 4.1 has a bug: <stdio.h> and <time.h> must be included before 15395b7b453SJohn Marino <wchar.h>. */ 15495b7b453SJohn Marino #include <stdio.h> 15595b7b453SJohn Marino #include <time.h> 15695b7b453SJohn Marino #include <wchar.h> 15795b7b453SJohn Marino #include <wctype.h> 15895b7b453SJohn Marino 159680a9cb8SJohn Marino #ifndef _GL_INLINE_HEADER_BEGIN 160680a9cb8SJohn Marino #error "Please include config.h first." 161680a9cb8SJohn Marino #endif 162680a9cb8SJohn Marino _GL_INLINE_HEADER_BEGIN 163680a9cb8SJohn Marino #ifndef MBCHAR_INLINE 164680a9cb8SJohn Marino # define MBCHAR_INLINE _GL_INLINE 165680a9cb8SJohn Marino #endif 166680a9cb8SJohn Marino 16795b7b453SJohn Marino #define MBCHAR_BUF_SIZE 24 16895b7b453SJohn Marino 16995b7b453SJohn Marino struct mbchar 17095b7b453SJohn Marino { 17195b7b453SJohn Marino const char *ptr; /* pointer to current character */ 17295b7b453SJohn Marino size_t bytes; /* number of bytes of current character, > 0 */ 17395b7b453SJohn Marino bool wc_valid; /* true if wc is a valid wide character */ 17495b7b453SJohn Marino wchar_t wc; /* if wc_valid: the current character */ 17595b7b453SJohn Marino char buf[MBCHAR_BUF_SIZE]; /* room for the bytes, used for file input only */ 17695b7b453SJohn Marino }; 17795b7b453SJohn Marino 17895b7b453SJohn Marino /* EOF (not a real character) is represented with bytes = 0 and 17995b7b453SJohn Marino wc_valid = false. */ 18095b7b453SJohn Marino 18195b7b453SJohn Marino typedef struct mbchar mbchar_t; 18295b7b453SJohn Marino 18395b7b453SJohn Marino /* Access the current character. */ 18495b7b453SJohn Marino #define mb_ptr(mbc) ((mbc).ptr) 18595b7b453SJohn Marino #define mb_len(mbc) ((mbc).bytes) 18695b7b453SJohn Marino 18795b7b453SJohn Marino /* Comparison of characters. */ 18895b7b453SJohn Marino #define mb_iseq(mbc, sc) ((mbc).wc_valid && (mbc).wc == (sc)) 18995b7b453SJohn Marino #define mb_isnul(mbc) ((mbc).wc_valid && (mbc).wc == 0) 19095b7b453SJohn Marino #define mb_cmp(mbc1, mbc2) \ 19195b7b453SJohn Marino ((mbc1).wc_valid \ 19295b7b453SJohn Marino ? ((mbc2).wc_valid \ 19395b7b453SJohn Marino ? (int) (mbc1).wc - (int) (mbc2).wc \ 19495b7b453SJohn Marino : -1) \ 19595b7b453SJohn Marino : ((mbc2).wc_valid \ 19695b7b453SJohn Marino ? 1 \ 19795b7b453SJohn Marino : (mbc1).bytes == (mbc2).bytes \ 19895b7b453SJohn Marino ? memcmp ((mbc1).ptr, (mbc2).ptr, (mbc1).bytes) \ 19995b7b453SJohn Marino : (mbc1).bytes < (mbc2).bytes \ 20095b7b453SJohn Marino ? (memcmp ((mbc1).ptr, (mbc2).ptr, (mbc1).bytes) > 0 ? 1 : -1) \ 20195b7b453SJohn Marino : (memcmp ((mbc1).ptr, (mbc2).ptr, (mbc2).bytes) >= 0 ? 1 : -1))) 20295b7b453SJohn Marino #define mb_casecmp(mbc1, mbc2) \ 20395b7b453SJohn Marino ((mbc1).wc_valid \ 20495b7b453SJohn Marino ? ((mbc2).wc_valid \ 20595b7b453SJohn Marino ? (int) towlower ((mbc1).wc) - (int) towlower ((mbc2).wc) \ 20695b7b453SJohn Marino : -1) \ 20795b7b453SJohn Marino : ((mbc2).wc_valid \ 20895b7b453SJohn Marino ? 1 \ 20995b7b453SJohn Marino : (mbc1).bytes == (mbc2).bytes \ 21095b7b453SJohn Marino ? memcmp ((mbc1).ptr, (mbc2).ptr, (mbc1).bytes) \ 21195b7b453SJohn Marino : (mbc1).bytes < (mbc2).bytes \ 21295b7b453SJohn Marino ? (memcmp ((mbc1).ptr, (mbc2).ptr, (mbc1).bytes) > 0 ? 1 : -1) \ 21395b7b453SJohn Marino : (memcmp ((mbc1).ptr, (mbc2).ptr, (mbc2).bytes) >= 0 ? 1 : -1))) 21495b7b453SJohn Marino #define mb_equal(mbc1, mbc2) \ 21595b7b453SJohn Marino ((mbc1).wc_valid && (mbc2).wc_valid \ 21695b7b453SJohn Marino ? (mbc1).wc == (mbc2).wc \ 21795b7b453SJohn Marino : (mbc1).bytes == (mbc2).bytes \ 21895b7b453SJohn Marino && memcmp ((mbc1).ptr, (mbc2).ptr, (mbc1).bytes) == 0) 21995b7b453SJohn Marino #define mb_caseequal(mbc1, mbc2) \ 22095b7b453SJohn Marino ((mbc1).wc_valid && (mbc2).wc_valid \ 22195b7b453SJohn Marino ? towlower ((mbc1).wc) == towlower ((mbc2).wc) \ 22295b7b453SJohn Marino : (mbc1).bytes == (mbc2).bytes \ 22395b7b453SJohn Marino && memcmp ((mbc1).ptr, (mbc2).ptr, (mbc1).bytes) == 0) 22495b7b453SJohn Marino 22595b7b453SJohn Marino /* <ctype.h>, <wctype.h> classification. */ 22695b7b453SJohn Marino #define mb_isascii(mbc) \ 22795b7b453SJohn Marino ((mbc).wc_valid && (mbc).wc >= 0 && (mbc).wc <= 127) 22895b7b453SJohn Marino #define mb_isalnum(mbc) ((mbc).wc_valid && iswalnum ((mbc).wc)) 22995b7b453SJohn Marino #define mb_isalpha(mbc) ((mbc).wc_valid && iswalpha ((mbc).wc)) 23095b7b453SJohn Marino #define mb_isblank(mbc) ((mbc).wc_valid && iswblank ((mbc).wc)) 23195b7b453SJohn Marino #define mb_iscntrl(mbc) ((mbc).wc_valid && iswcntrl ((mbc).wc)) 23295b7b453SJohn Marino #define mb_isdigit(mbc) ((mbc).wc_valid && iswdigit ((mbc).wc)) 23395b7b453SJohn Marino #define mb_isgraph(mbc) ((mbc).wc_valid && iswgraph ((mbc).wc)) 23495b7b453SJohn Marino #define mb_islower(mbc) ((mbc).wc_valid && iswlower ((mbc).wc)) 23595b7b453SJohn Marino #define mb_isprint(mbc) ((mbc).wc_valid && iswprint ((mbc).wc)) 23695b7b453SJohn Marino #define mb_ispunct(mbc) ((mbc).wc_valid && iswpunct ((mbc).wc)) 23795b7b453SJohn Marino #define mb_isspace(mbc) ((mbc).wc_valid && iswspace ((mbc).wc)) 23895b7b453SJohn Marino #define mb_isupper(mbc) ((mbc).wc_valid && iswupper ((mbc).wc)) 23995b7b453SJohn Marino #define mb_isxdigit(mbc) ((mbc).wc_valid && iswxdigit ((mbc).wc)) 24095b7b453SJohn Marino 24195b7b453SJohn Marino /* Extra <wchar.h> function. */ 24295b7b453SJohn Marino 24395b7b453SJohn Marino /* Unprintable characters appear as a small box of width 1. */ 24495b7b453SJohn Marino #define MB_UNPRINTABLE_WIDTH 1 24595b7b453SJohn Marino 246680a9cb8SJohn Marino MBCHAR_INLINE int 24795b7b453SJohn Marino mb_width_aux (wint_t wc) 24895b7b453SJohn Marino { 24995b7b453SJohn Marino int w = wcwidth (wc); 25095b7b453SJohn Marino /* For unprintable characters, arbitrarily return 0 for control characters 25195b7b453SJohn Marino and MB_UNPRINTABLE_WIDTH otherwise. */ 25295b7b453SJohn Marino return (w >= 0 ? w : iswcntrl (wc) ? 0 : MB_UNPRINTABLE_WIDTH); 25395b7b453SJohn Marino } 25495b7b453SJohn Marino 25595b7b453SJohn Marino #define mb_width(mbc) \ 25695b7b453SJohn Marino ((mbc).wc_valid ? mb_width_aux ((mbc).wc) : MB_UNPRINTABLE_WIDTH) 25795b7b453SJohn Marino 25895b7b453SJohn Marino /* Output. */ 25995b7b453SJohn Marino #define mb_putc(mbc, stream) fwrite ((mbc).ptr, 1, (mbc).bytes, (stream)) 26095b7b453SJohn Marino 26195b7b453SJohn Marino /* Assignment. */ 26295b7b453SJohn Marino #define mb_setascii(mbc, sc) \ 26395b7b453SJohn Marino ((mbc)->ptr = (mbc)->buf, (mbc)->bytes = 1, (mbc)->wc_valid = 1, \ 26495b7b453SJohn Marino (mbc)->wc = (mbc)->buf[0] = (sc)) 26595b7b453SJohn Marino 26695b7b453SJohn Marino /* Copying a character. */ 267680a9cb8SJohn Marino MBCHAR_INLINE void 26895b7b453SJohn Marino mb_copy (mbchar_t *new_mbc, const mbchar_t *old_mbc) 26995b7b453SJohn Marino { 27095b7b453SJohn Marino if (old_mbc->ptr == &old_mbc->buf[0]) 27195b7b453SJohn Marino { 27295b7b453SJohn Marino memcpy (&new_mbc->buf[0], &old_mbc->buf[0], old_mbc->bytes); 27395b7b453SJohn Marino new_mbc->ptr = &new_mbc->buf[0]; 27495b7b453SJohn Marino } 27595b7b453SJohn Marino else 27695b7b453SJohn Marino new_mbc->ptr = old_mbc->ptr; 27795b7b453SJohn Marino new_mbc->bytes = old_mbc->bytes; 27895b7b453SJohn Marino if ((new_mbc->wc_valid = old_mbc->wc_valid)) 27995b7b453SJohn Marino new_mbc->wc = old_mbc->wc; 28095b7b453SJohn Marino } 28195b7b453SJohn Marino 28295b7b453SJohn Marino 28395b7b453SJohn Marino /* is_basic(c) tests whether the single-byte character c is in the 28495b7b453SJohn Marino ISO C "basic character set". 28595b7b453SJohn Marino This is a convenience function, and is in this file only to share code 28695b7b453SJohn Marino between mbiter_multi.h and mbfile_multi.h. */ 28795b7b453SJohn Marino #if (' ' == 32) && ('!' == 33) && ('"' == 34) && ('#' == 35) \ 28895b7b453SJohn Marino && ('%' == 37) && ('&' == 38) && ('\'' == 39) && ('(' == 40) \ 28995b7b453SJohn Marino && (')' == 41) && ('*' == 42) && ('+' == 43) && (',' == 44) \ 29095b7b453SJohn Marino && ('-' == 45) && ('.' == 46) && ('/' == 47) && ('0' == 48) \ 29195b7b453SJohn Marino && ('1' == 49) && ('2' == 50) && ('3' == 51) && ('4' == 52) \ 29295b7b453SJohn Marino && ('5' == 53) && ('6' == 54) && ('7' == 55) && ('8' == 56) \ 29395b7b453SJohn Marino && ('9' == 57) && (':' == 58) && (';' == 59) && ('<' == 60) \ 29495b7b453SJohn Marino && ('=' == 61) && ('>' == 62) && ('?' == 63) && ('A' == 65) \ 29595b7b453SJohn Marino && ('B' == 66) && ('C' == 67) && ('D' == 68) && ('E' == 69) \ 29695b7b453SJohn Marino && ('F' == 70) && ('G' == 71) && ('H' == 72) && ('I' == 73) \ 29795b7b453SJohn Marino && ('J' == 74) && ('K' == 75) && ('L' == 76) && ('M' == 77) \ 29895b7b453SJohn Marino && ('N' == 78) && ('O' == 79) && ('P' == 80) && ('Q' == 81) \ 29995b7b453SJohn Marino && ('R' == 82) && ('S' == 83) && ('T' == 84) && ('U' == 85) \ 30095b7b453SJohn Marino && ('V' == 86) && ('W' == 87) && ('X' == 88) && ('Y' == 89) \ 30195b7b453SJohn Marino && ('Z' == 90) && ('[' == 91) && ('\\' == 92) && (']' == 93) \ 30295b7b453SJohn Marino && ('^' == 94) && ('_' == 95) && ('a' == 97) && ('b' == 98) \ 30395b7b453SJohn Marino && ('c' == 99) && ('d' == 100) && ('e' == 101) && ('f' == 102) \ 30495b7b453SJohn Marino && ('g' == 103) && ('h' == 104) && ('i' == 105) && ('j' == 106) \ 30595b7b453SJohn Marino && ('k' == 107) && ('l' == 108) && ('m' == 109) && ('n' == 110) \ 30695b7b453SJohn Marino && ('o' == 111) && ('p' == 112) && ('q' == 113) && ('r' == 114) \ 30795b7b453SJohn Marino && ('s' == 115) && ('t' == 116) && ('u' == 117) && ('v' == 118) \ 30895b7b453SJohn Marino && ('w' == 119) && ('x' == 120) && ('y' == 121) && ('z' == 122) \ 30995b7b453SJohn Marino && ('{' == 123) && ('|' == 124) && ('}' == 125) && ('~' == 126) 31095b7b453SJohn Marino /* The character set is ISO-646, not EBCDIC. */ 31195b7b453SJohn Marino # define IS_BASIC_ASCII 1 31295b7b453SJohn Marino 31395b7b453SJohn Marino extern const unsigned int is_basic_table[]; 31495b7b453SJohn Marino 315680a9cb8SJohn Marino MBCHAR_INLINE bool 31695b7b453SJohn Marino is_basic (char c) 31795b7b453SJohn Marino { 31895b7b453SJohn Marino return (is_basic_table [(unsigned char) c >> 5] >> ((unsigned char) c & 31)) 31995b7b453SJohn Marino & 1; 32095b7b453SJohn Marino } 32195b7b453SJohn Marino 32295b7b453SJohn Marino #else 32395b7b453SJohn Marino 324680a9cb8SJohn Marino MBCHAR_INLINE bool 32595b7b453SJohn Marino is_basic (char c) 32695b7b453SJohn Marino { 32795b7b453SJohn Marino switch (c) 32895b7b453SJohn Marino { 32995b7b453SJohn Marino case '\t': case '\v': case '\f': 33095b7b453SJohn Marino case ' ': case '!': case '"': case '#': case '%': 33195b7b453SJohn Marino case '&': case '\'': case '(': case ')': case '*': 33295b7b453SJohn Marino case '+': case ',': case '-': case '.': case '/': 33395b7b453SJohn Marino case '0': case '1': case '2': case '3': case '4': 33495b7b453SJohn Marino case '5': case '6': case '7': case '8': case '9': 33595b7b453SJohn Marino case ':': case ';': case '<': case '=': case '>': 33695b7b453SJohn Marino case '?': 33795b7b453SJohn Marino case 'A': case 'B': case 'C': case 'D': case 'E': 33895b7b453SJohn Marino case 'F': case 'G': case 'H': case 'I': case 'J': 33995b7b453SJohn Marino case 'K': case 'L': case 'M': case 'N': case 'O': 34095b7b453SJohn Marino case 'P': case 'Q': case 'R': case 'S': case 'T': 34195b7b453SJohn Marino case 'U': case 'V': case 'W': case 'X': case 'Y': 34295b7b453SJohn Marino case 'Z': 34395b7b453SJohn Marino case '[': case '\\': case ']': case '^': case '_': 34495b7b453SJohn Marino case 'a': case 'b': case 'c': case 'd': case 'e': 34595b7b453SJohn Marino case 'f': case 'g': case 'h': case 'i': case 'j': 34695b7b453SJohn Marino case 'k': case 'l': case 'm': case 'n': case 'o': 34795b7b453SJohn Marino case 'p': case 'q': case 'r': case 's': case 't': 34895b7b453SJohn Marino case 'u': case 'v': case 'w': case 'x': case 'y': 34995b7b453SJohn Marino case 'z': case '{': case '|': case '}': case '~': 35095b7b453SJohn Marino return 1; 35195b7b453SJohn Marino default: 35295b7b453SJohn Marino return 0; 35395b7b453SJohn Marino } 35495b7b453SJohn Marino } 35595b7b453SJohn Marino 35695b7b453SJohn Marino #endif 35795b7b453SJohn Marino 358680a9cb8SJohn Marino _GL_INLINE_HEADER_END 359680a9cb8SJohn Marino 36095b7b453SJohn Marino #endif /* _MBCHAR_H */ 361