home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 5 Edit / 05-Edit.zip / me34src.zip / me3 / util / char.h < prev    next >
C/C++ Source or Header  |  1995-01-14  |  3KB  |  88 lines

  1. /*
  2.  * char.h:  a replacement ctype.h
  3.  * C Durland    Public Domain
  4.  */
  5.  
  6. /*
  7.  * isalnum(c)    non-zero if c is alpha or digit
  8.  * isalpha(c)    non-zero if c is alpha
  9.  * isascii(c)    non-zero if c is ASCII
  10.  * iscntrl(c)    non-zero if c is control character
  11.  * isdigit(c)    non-zero if c is a digit (0 to 9)
  12.  * islower(c)    non-zero if c is lower case
  13.  * ispunct(c)    non-zero if c is punctuation
  14.  * isspace(c)    non-zero if c is white space
  15.  * isupper(c)    non-zero if c is upper case
  16.  
  17.  * isprint(c)    non-zero if c is printable (including blank)
  18.  * isgraph(c)    non-zero if c is graphic (excluding blank)
  19.   
  20.  * _toupper(c)    jam c to uppercase no matter what
  21.  * TOUPPER(c)    convert c to uppercase if it is lowercase
  22.  * _tolower(c)    jam c to lowercase no matter what
  23.  * TOLOWER(c)    convert c to lowercase if it is uppercase
  24.  */
  25.  
  26. #ifndef __CHAR_H_INCLUDED
  27. #define __CHAR_H_INCLUDED
  28.  
  29. #define    _W    0x01    /* Word */
  30. #define    _U    0x02    /* Upper case letter */
  31. #define    _L    0x04    /* Lower case letter */
  32. #define    _C    0x08    /* Control */
  33. #define _N    0x10    /* number */
  34. #define _S    0x20    /* space */
  35. #define _P    0x40    /* punctuation */
  36.  
  37. extern unsigned char _cinfo[];    /* in char.c */
  38.  
  39. #define isalnum(c)    (_cinfo[(unsigned char)(c)] & (_U|_L|_N))
  40. #define isalpha(c)    (_cinfo[(unsigned char)(c)] & (_U|_L))
  41. #define    iscntrl(c)    (_cinfo[(unsigned char)(c)] & _C)
  42. #define isdigit(c)    (_cinfo[(unsigned char)(c)] & _N)
  43. #define    islower(c)    (_cinfo[(unsigned char)(c)] & _L)
  44. #define ispunct(c)    (_cinfo[(unsigned char)(c)] & _P)
  45. #define isspace(c)    (_cinfo[(unsigned char)(c)] & _S)
  46. #define    isupper(c)    (_cinfo[(unsigned char)(c)] & _U)
  47. #define    isword(c)    (_cinfo[(unsigned char)(c)] & _W)
  48.  
  49. #define isgraph(c)    (_cinfo[(unsigned char)(c)] & (_U|_L|_N|_P))
  50. #define isprint(c)    (_cinfo[(unsigned char)(c)] & (_U|_L|_N|_P|_S))
  51.  
  52. #define toascii(c)    ((unsigned char)(c) & 0x7F)
  53.  
  54. #define add_cinfo(c,x)    _cinfo[(unsigned char)(c)] |= x
  55. #define remove_cinfo(c,x) _cinfo[(unsigned char)(c)] &= ~(x)
  56.  
  57. #ifndef CHAR_MAPS
  58.  
  59.     /* Note:  these only really work with ASCII ie < 0x7F */
  60. #define    _toupper(c)    ((unsigned char)(c) & 0xDF)
  61. #define    TOUPPER(c)    (islower(c) ? _toupper(c) : (c))
  62. #define    _tolower(c)    ((unsigned char)(c) | ' ')
  63. #define    TOLOWER(c)    (isupper(c) ? _tolower(c) : (c))
  64.  
  65. #else
  66.  
  67. extern unsigned char _lcmap[], _ucmap[];
  68.  
  69. #define    _toupper(c)    _ucmap[(unsigned char)(c)]
  70. #define    TOUPPER(c)    _ucmap[(unsigned char)(c)]
  71. #define    _tolower(c)    _lcmap[(unsigned char)(c)]
  72. #define    TOLOWER(c)    _lcmap[(unsigned char)(c)]
  73.  
  74. #define set_toupper(a,A) _ucmap[(unsigned char)(a)] = (A)
  75. #define set_tolower(A,a) _lcmap[(unsigned char)(A)] = (a)
  76.  
  77. #endif
  78.  
  79.     /* Case insensitive table stuff.
  80.      * Define _cmap[256] in your code and munge it.
  81.      */
  82. extern unsigned char _cmap[];
  83.  
  84.         /* character compare */
  85. #define ceq(c1,c2) (_cmap[(unsigned char)(c1)] == _cmap[(unsigned char)(c2)])
  86.  
  87. #endif    /* __CHAR_H_INCLUDED */
  88.