cset.cc 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. // -*- C++ -*-
  2. /* Copyright (C) 1989, 1990, 1991, 1992 Free Software Foundation, Inc.
  3. Written by James Clark (jjc@jclark.com) */
  4. #include <ctype.h>
  5. #include "cset.h"
  6. cset csalpha(CSET_BUILTIN);
  7. cset csupper(CSET_BUILTIN);
  8. cset cslower(CSET_BUILTIN);
  9. cset csdigit(CSET_BUILTIN);
  10. cset csxdigit(CSET_BUILTIN);
  11. cset csspace(CSET_BUILTIN);
  12. cset cspunct(CSET_BUILTIN);
  13. cset csalnum(CSET_BUILTIN);
  14. cset csprint(CSET_BUILTIN);
  15. cset csgraph(CSET_BUILTIN);
  16. cset cscntrl(CSET_BUILTIN);
  17. #ifdef isascii
  18. #define ISASCII(c) isascii(c)
  19. #else
  20. #define ISASCII(c) (1)
  21. #endif
  22. void
  23. cset::clear()
  24. {
  25. char *p = v;
  26. for (int i = 0; i <= UCHAR_MAX; i++)
  27. p[i] = 0;
  28. }
  29. cset::cset()
  30. {
  31. clear();
  32. }
  33. cset::cset(const char *s)
  34. {
  35. clear();
  36. while (*s)
  37. v[(unsigned char)*s++] = 1;
  38. }
  39. cset::cset(const unsigned char *s)
  40. {
  41. clear();
  42. while (*s)
  43. v[*s++] = 1;
  44. }
  45. cset::cset(cset_builtin)
  46. {
  47. // these are initialised by cset_init::cset_init()
  48. }
  49. cset &
  50. cset::operator|=(const cset &cs)
  51. {
  52. for (int i = 0; i <= UCHAR_MAX; i++)
  53. if (cs.v[i])
  54. v[i] = 1;
  55. return *this;
  56. }
  57. int
  58. cset_init::initialised = 0;
  59. cset_init::cset_init()
  60. {
  61. if (initialised)
  62. return;
  63. initialised = 1;
  64. for (int i = 0; i <= UCHAR_MAX; i++) {
  65. csalpha.v[i] = ISASCII(i) && isalpha(i);
  66. csupper.v[i] = ISASCII(i) && isupper(i);
  67. cslower.v[i] = ISASCII(i) && islower(i);
  68. csdigit.v[i] = ISASCII(i) && isdigit(i);
  69. csxdigit.v[i] = ISASCII(i) && isxdigit(i);
  70. csspace.v[i] = ISASCII(i) && isspace(i);
  71. cspunct.v[i] = ISASCII(i) && ispunct(i);
  72. csalnum.v[i] = ISASCII(i) && isalnum(i);
  73. csprint.v[i] = ISASCII(i) && isprint(i);
  74. csgraph.v[i] = ISASCII(i) && isgraph(i);
  75. cscntrl.v[i] = ISASCII(i) && iscntrl(i);
  76. }
  77. }