c-ctype.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. /*
  2. * libdpkg - Debian packaging suite library routines
  3. * c-ctype.c - ASCII C locale-only functions
  4. *
  5. * Copyright © 2009-2014 Guillem Jover <guillem@debian.org>
  6. *
  7. * This is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. */
  20. #include <config.h>
  21. #include <compat.h>
  22. #include <dpkg/c-ctype.h>
  23. #undef S
  24. #define S C_CTYPE_SPACE
  25. #undef W
  26. #define W C_CTYPE_WHITE
  27. #undef B
  28. #define B C_CTYPE_BLANK
  29. #undef U
  30. #define U C_CTYPE_UPPER
  31. #undef L
  32. #define L C_CTYPE_LOWER
  33. #undef D
  34. #define D C_CTYPE_DIGIT
  35. static unsigned short int c_ctype[256] = {
  36. /** 0 **/
  37. /* \0 */ 0,
  38. 0,
  39. 0,
  40. 0,
  41. 0,
  42. 0,
  43. 0,
  44. /* \a */ 0,
  45. /* \b */ 0,
  46. /* \t */ S | W | B,
  47. /* \n */ S | W,
  48. /* \v */ S,
  49. /* \f */ S,
  50. /* \r */ S,
  51. 0,
  52. 0,
  53. /** 16 **/
  54. 0,
  55. 0,
  56. 0,
  57. 0,
  58. 0,
  59. 0,
  60. 0,
  61. 0,
  62. 0,
  63. 0,
  64. 0,
  65. 0,
  66. 0,
  67. 0,
  68. 0,
  69. 0,
  70. /** 32 **/
  71. /* */ S | W | B,
  72. /* ! */ 0,
  73. /* " */ 0,
  74. /* # */ 0,
  75. /* $ */ 0,
  76. /* % */ 0,
  77. /* & */ 0,
  78. /* ' */ 0,
  79. /* ( */ 0,
  80. /* ) */ 0,
  81. /* * */ 0,
  82. /* + */ 0,
  83. /* , */ 0,
  84. /* - */ 0,
  85. /* . */ 0,
  86. /* / */ 0,
  87. /** 48 **/
  88. /* 0 */ D,
  89. /* 1 */ D,
  90. /* 2 */ D,
  91. /* 3 */ D,
  92. /* 4 */ D,
  93. /* 5 */ D,
  94. /* 6 */ D,
  95. /* 7 */ D,
  96. /* 8 */ D,
  97. /* 9 */ D,
  98. /* : */ 0,
  99. /* ; */ 0,
  100. /* < */ 0,
  101. /* = */ 0,
  102. /* > */ 0,
  103. /* ? */ 0,
  104. /* 64 */
  105. /* @ */ 0,
  106. /* A */ U,
  107. /* B */ U,
  108. /* C */ U,
  109. /* D */ U,
  110. /* E */ U,
  111. /* F */ U,
  112. /* G */ U,
  113. /* H */ U,
  114. /* I */ U,
  115. /* J */ U,
  116. /* K */ U,
  117. /* L */ U,
  118. /* M */ U,
  119. /* N */ U,
  120. /* O */ U,
  121. /* 80 */
  122. /* P */ U,
  123. /* Q */ U,
  124. /* R */ U,
  125. /* S */ U,
  126. /* T */ U,
  127. /* U */ U,
  128. /* V */ U,
  129. /* W */ U,
  130. /* X */ U,
  131. /* Y */ U,
  132. /* Z */ U,
  133. /* [ */ 0,
  134. /* \ */ 0,
  135. /* ] */ 0,
  136. /* ^ */ 0,
  137. /* _ */ 0,
  138. /* 96 */
  139. /* ` */ 0,
  140. /* a */ L,
  141. /* b */ L,
  142. /* c */ L,
  143. /* d */ L,
  144. /* e */ L,
  145. /* f */ L,
  146. /* g */ L,
  147. /* h */ L,
  148. /* i */ L,
  149. /* j */ L,
  150. /* k */ L,
  151. /* l */ L,
  152. /* m */ L,
  153. /* n */ L,
  154. /* o */ L,
  155. /* 112 */
  156. /* p */ L,
  157. /* q */ L,
  158. /* r */ L,
  159. /* s */ L,
  160. /* t */ L,
  161. /* u */ L,
  162. /* v */ L,
  163. /* w */ L,
  164. /* x */ L,
  165. /* y */ L,
  166. /* z */ L,
  167. /* { */ 0,
  168. /* | */ 0,
  169. /* } */ 0,
  170. /* ~ */ 0,
  171. 0,
  172. /* 128 */
  173. };
  174. /**
  175. * Check if the character is bits ctype.
  176. */
  177. bool
  178. c_isbits(int c, enum c_ctype_bit bits)
  179. {
  180. return ((c_ctype[(unsigned char)c] & bits) != 0);
  181. }