ctype.cpp 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486
  1. /*
  2. * Copyright (c) 1999
  3. * Silicon Graphics Computer Systems, Inc.
  4. *
  5. * Copyright (c) 1999
  6. * Boris Fomitchev
  7. *
  8. * This material is provided "as is", with absolutely no warranty expressed
  9. * or implied. Any use is at your own risk.
  10. *
  11. * Permission to use or copy this software for any purpose is hereby granted
  12. * without fee, provided the above notices are retained on all copies.
  13. * Permission to modify the code and to distribute modified code is granted,
  14. * provided the above notices are retained, and a notice that the code was
  15. * modified is included with the above copyright notice.
  16. *
  17. */
  18. #include "stlport_prefix.h"
  19. #include <algorithm>
  20. #include <locale>
  21. #include <functional>
  22. #include "c_locale.h"
  23. _STLP_BEGIN_NAMESPACE
  24. //----------------------------------------------------------------------
  25. // ctype<char>
  26. // The classic table: static data members.
  27. #if !defined (_STLP_STATIC_CONST_INIT_BUG) && !defined (_STLP_NO_STATIC_CONST_DEFINITION)
  28. //*TY 02/25/2000 - added workaround for MPW compilers; they confuse on in-class static const
  29. const size_t ctype<char>::table_size;
  30. #endif
  31. // This macro is specifically for platforms where isprint() relies
  32. // on separate flag
  33. const ctype_base::mask*
  34. ctype<char>::classic_table() _STLP_NOTHROW {
  35. /* Ctype table for the ASCII character set. */
  36. static const ctype_base::mask _S_classic_table[table_size] = {
  37. cntrl /* null */,
  38. cntrl /* ^A */,
  39. cntrl /* ^B */,
  40. cntrl /* ^C */,
  41. cntrl /* ^D */,
  42. cntrl /* ^E */,
  43. cntrl /* ^F */,
  44. cntrl /* ^G */,
  45. cntrl /* ^H */,
  46. ctype_base::mask(space | cntrl) /* tab */,
  47. ctype_base::mask(space | cntrl) /* LF */,
  48. ctype_base::mask(space | cntrl) /* ^K */,
  49. ctype_base::mask(space | cntrl) /* FF */,
  50. ctype_base::mask(space | cntrl) /* ^M */,
  51. cntrl /* ^N */,
  52. cntrl /* ^O */,
  53. cntrl /* ^P */,
  54. cntrl /* ^Q */,
  55. cntrl /* ^R */,
  56. cntrl /* ^S */,
  57. cntrl /* ^T */,
  58. cntrl /* ^U */,
  59. cntrl /* ^V */,
  60. cntrl /* ^W */,
  61. cntrl /* ^X */,
  62. cntrl /* ^Y */,
  63. cntrl /* ^Z */,
  64. cntrl /* esc */,
  65. cntrl /* ^\ */,
  66. cntrl /* ^] */,
  67. cntrl /* ^^ */,
  68. cntrl /* ^_ */,
  69. ctype_base::mask(space | print) /* */,
  70. ctype_base::mask(punct | print) /* ! */,
  71. ctype_base::mask(punct | print) /* " */,
  72. ctype_base::mask(punct | print) /* # */,
  73. ctype_base::mask(punct | print) /* $ */,
  74. ctype_base::mask(punct | print) /* % */,
  75. ctype_base::mask(punct | print) /* & */,
  76. ctype_base::mask(punct | print) /* ' */,
  77. ctype_base::mask(punct | print) /* ( */,
  78. ctype_base::mask(punct | print) /* ) */,
  79. ctype_base::mask(punct | print) /* * */,
  80. ctype_base::mask(punct | print) /* + */,
  81. ctype_base::mask(punct | print) /* , */,
  82. ctype_base::mask(punct | print) /* - */,
  83. ctype_base::mask(punct | print) /* . */,
  84. ctype_base::mask(punct | print) /* / */,
  85. ctype_base::mask(digit | print | xdigit) /* 0 */,
  86. ctype_base::mask(digit | print | xdigit) /* 1 */,
  87. ctype_base::mask(digit | print | xdigit) /* 2 */,
  88. ctype_base::mask(digit | print | xdigit) /* 3 */,
  89. ctype_base::mask(digit | print | xdigit) /* 4 */,
  90. ctype_base::mask(digit | print | xdigit) /* 5 */,
  91. ctype_base::mask(digit | print | xdigit) /* 6 */,
  92. ctype_base::mask(digit | print | xdigit) /* 7 */,
  93. ctype_base::mask(digit | print | xdigit) /* 8 */,
  94. ctype_base::mask(digit | print | xdigit) /* 9 */,
  95. ctype_base::mask(punct | print) /* : */,
  96. ctype_base::mask(punct | print) /* ; */,
  97. ctype_base::mask(punct | print) /* < */,
  98. ctype_base::mask(punct | print) /* = */,
  99. ctype_base::mask(punct | print) /* > */,
  100. ctype_base::mask(punct | print) /* ? */,
  101. ctype_base::mask(punct | print) /* ! */,
  102. ctype_base::mask(alpha | print | upper | xdigit) /* A */,
  103. ctype_base::mask(alpha | print | upper | xdigit) /* B */,
  104. ctype_base::mask(alpha | print | upper | xdigit) /* C */,
  105. ctype_base::mask(alpha | print | upper | xdigit) /* D */,
  106. ctype_base::mask(alpha | print | upper | xdigit) /* E */,
  107. ctype_base::mask(alpha | print | upper | xdigit) /* F */,
  108. ctype_base::mask(alpha | print | upper) /* G */,
  109. ctype_base::mask(alpha | print | upper) /* H */,
  110. ctype_base::mask(alpha | print | upper) /* I */,
  111. ctype_base::mask(alpha | print | upper) /* J */,
  112. ctype_base::mask(alpha | print | upper) /* K */,
  113. ctype_base::mask(alpha | print | upper) /* L */,
  114. ctype_base::mask(alpha | print | upper) /* M */,
  115. ctype_base::mask(alpha | print | upper) /* N */,
  116. ctype_base::mask(alpha | print | upper) /* O */,
  117. ctype_base::mask(alpha | print | upper) /* P */,
  118. ctype_base::mask(alpha | print | upper) /* Q */,
  119. ctype_base::mask(alpha | print | upper) /* R */,
  120. ctype_base::mask(alpha | print | upper) /* S */,
  121. ctype_base::mask(alpha | print | upper) /* T */,
  122. ctype_base::mask(alpha | print | upper) /* U */,
  123. ctype_base::mask(alpha | print | upper) /* V */,
  124. ctype_base::mask(alpha | print | upper) /* W */,
  125. ctype_base::mask(alpha | print | upper) /* X */,
  126. ctype_base::mask(alpha | print | upper) /* Y */,
  127. ctype_base::mask(alpha | print | upper) /* Z */,
  128. ctype_base::mask(punct | print) /* [ */,
  129. ctype_base::mask(punct | print) /* \ */,
  130. ctype_base::mask(punct | print) /* ] */,
  131. ctype_base::mask(punct | print) /* ^ */,
  132. ctype_base::mask(punct | print) /* _ */,
  133. ctype_base::mask(punct | print) /* ` */,
  134. ctype_base::mask(alpha | print | lower | xdigit) /* a */,
  135. ctype_base::mask(alpha | print | lower | xdigit) /* b */,
  136. ctype_base::mask(alpha | print | lower | xdigit) /* c */,
  137. ctype_base::mask(alpha | print | lower | xdigit) /* d */,
  138. ctype_base::mask(alpha | print | lower | xdigit) /* e */,
  139. ctype_base::mask(alpha | print | lower | xdigit) /* f */,
  140. ctype_base::mask(alpha | print | lower) /* g */,
  141. ctype_base::mask(alpha | print | lower) /* h */,
  142. ctype_base::mask(alpha | print | lower) /* i */,
  143. ctype_base::mask(alpha | print | lower) /* j */,
  144. ctype_base::mask(alpha | print | lower) /* k */,
  145. ctype_base::mask(alpha | print | lower) /* l */,
  146. ctype_base::mask(alpha | print | lower) /* m */,
  147. ctype_base::mask(alpha | print | lower) /* n */,
  148. ctype_base::mask(alpha | print | lower) /* o */,
  149. ctype_base::mask(alpha | print | lower) /* p */,
  150. ctype_base::mask(alpha | print | lower) /* q */,
  151. ctype_base::mask(alpha | print | lower) /* r */,
  152. ctype_base::mask(alpha | print | lower) /* s */,
  153. ctype_base::mask(alpha | print | lower) /* t */,
  154. ctype_base::mask(alpha | print | lower) /* u */,
  155. ctype_base::mask(alpha | print | lower) /* v */,
  156. ctype_base::mask(alpha | print | lower) /* w */,
  157. ctype_base::mask(alpha | print | lower) /* x */,
  158. ctype_base::mask(alpha | print | lower) /* y */,
  159. ctype_base::mask(alpha | print | lower) /* z */,
  160. ctype_base::mask(punct | print) /* { */,
  161. ctype_base::mask(punct | print) /* | */,
  162. ctype_base::mask(punct | print) /* } */,
  163. ctype_base::mask(punct | print) /* ~ */,
  164. cntrl /* del (0x7f)*/,
  165. /* ASCII is a 7-bit code, so everything else is non-ASCII */
  166. ctype_base::mask(0), ctype_base::mask(0), ctype_base::mask(0), ctype_base::mask(0), ctype_base::mask(0), ctype_base::mask(0), ctype_base::mask(0), ctype_base::mask(0),
  167. ctype_base::mask(0), ctype_base::mask(0), ctype_base::mask(0), ctype_base::mask(0), ctype_base::mask(0), ctype_base::mask(0), ctype_base::mask(0), ctype_base::mask(0),
  168. ctype_base::mask(0), ctype_base::mask(0), ctype_base::mask(0), ctype_base::mask(0), ctype_base::mask(0), ctype_base::mask(0), ctype_base::mask(0), ctype_base::mask(0),
  169. ctype_base::mask(0), ctype_base::mask(0), ctype_base::mask(0), ctype_base::mask(0), ctype_base::mask(0), ctype_base::mask(0), ctype_base::mask(0), ctype_base::mask(0),
  170. ctype_base::mask(0), ctype_base::mask(0), ctype_base::mask(0), ctype_base::mask(0), ctype_base::mask(0), ctype_base::mask(0), ctype_base::mask(0), ctype_base::mask(0),
  171. ctype_base::mask(0), ctype_base::mask(0), ctype_base::mask(0), ctype_base::mask(0), ctype_base::mask(0), ctype_base::mask(0), ctype_base::mask(0), ctype_base::mask(0),
  172. ctype_base::mask(0), ctype_base::mask(0), ctype_base::mask(0), ctype_base::mask(0), ctype_base::mask(0), ctype_base::mask(0), ctype_base::mask(0), ctype_base::mask(0),
  173. ctype_base::mask(0), ctype_base::mask(0), ctype_base::mask(0), ctype_base::mask(0), ctype_base::mask(0), ctype_base::mask(0), ctype_base::mask(0), ctype_base::mask(0),
  174. ctype_base::mask(0), ctype_base::mask(0), ctype_base::mask(0), ctype_base::mask(0), ctype_base::mask(0), ctype_base::mask(0), ctype_base::mask(0), ctype_base::mask(0),
  175. ctype_base::mask(0), ctype_base::mask(0), ctype_base::mask(0), ctype_base::mask(0), ctype_base::mask(0), ctype_base::mask(0), ctype_base::mask(0), ctype_base::mask(0),
  176. ctype_base::mask(0), ctype_base::mask(0), ctype_base::mask(0), ctype_base::mask(0), ctype_base::mask(0), ctype_base::mask(0), ctype_base::mask(0), ctype_base::mask(0),
  177. ctype_base::mask(0), ctype_base::mask(0), ctype_base::mask(0), ctype_base::mask(0), ctype_base::mask(0), ctype_base::mask(0), ctype_base::mask(0), ctype_base::mask(0),
  178. ctype_base::mask(0), ctype_base::mask(0), ctype_base::mask(0), ctype_base::mask(0), ctype_base::mask(0), ctype_base::mask(0), ctype_base::mask(0), ctype_base::mask(0),
  179. ctype_base::mask(0), ctype_base::mask(0), ctype_base::mask(0), ctype_base::mask(0), ctype_base::mask(0), ctype_base::mask(0), ctype_base::mask(0), ctype_base::mask(0),
  180. ctype_base::mask(0), ctype_base::mask(0), ctype_base::mask(0), ctype_base::mask(0), ctype_base::mask(0), ctype_base::mask(0), ctype_base::mask(0), ctype_base::mask(0),
  181. ctype_base::mask(0), ctype_base::mask(0), ctype_base::mask(0), ctype_base::mask(0), ctype_base::mask(0), ctype_base::mask(0), ctype_base::mask(0), ctype_base::mask(0)
  182. };
  183. return _S_classic_table;
  184. }
  185. // For every c in the range 0 <= c < 256, _S_upper[c] is the
  186. // uppercased version of c and _S_lower[c] is the lowercased
  187. // version. As before, these two tables assume the ASCII character
  188. // set.
  189. const unsigned char _S_upper[ctype<char>::table_size] =
  190. {
  191. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  192. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
  193. 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
  194. 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
  195. 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
  196. 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,
  197. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  198. 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f,
  199. 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47,
  200. 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f,
  201. 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
  202. 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f,
  203. 0x60, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47,
  204. 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f,
  205. 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
  206. 0x58, 0x59, 0x5a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f,
  207. 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,
  208. 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f,
  209. 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97,
  210. 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f,
  211. 0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7,
  212. 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf,
  213. 0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7,
  214. 0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf,
  215. 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7,
  216. 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf,
  217. 0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7,
  218. 0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf,
  219. 0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7,
  220. 0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef,
  221. 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
  222. 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff
  223. };
  224. const unsigned char _S_lower[ctype<char>::table_size] =
  225. {
  226. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  227. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
  228. 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
  229. 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
  230. 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
  231. 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,
  232. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  233. 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f,
  234. 0x40, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67,
  235. 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f,
  236. 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77,
  237. 0x78, 0x79, 0x7a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f,
  238. 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67,
  239. 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f,
  240. 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77,
  241. 0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f,
  242. 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,
  243. 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f,
  244. 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97,
  245. 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f,
  246. 0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7,
  247. 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf,
  248. 0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7,
  249. 0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf,
  250. 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7,
  251. 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf,
  252. 0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7,
  253. 0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf,
  254. 0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7,
  255. 0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef,
  256. 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
  257. 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff
  258. };
  259. //An helper struct to check wchar_t index without generating warnings
  260. //under some compilers (gcc) because of a limited range of value
  261. //(when wchar_t is unsigned)
  262. template <bool _IsSigned>
  263. struct _WCharIndexT;
  264. #if !(defined (__BORLANDC__) && !defined(__linux__)) && \
  265. !(defined (__GNUC__) && (defined (__MINGW32__) || defined (__CYGWIN__))) && \
  266. !defined (__ICL)
  267. _STLP_TEMPLATE_NULL
  268. struct _WCharIndexT<true> {
  269. static bool in_range(wchar_t c, size_t upperBound) {
  270. return c >= 0 && size_t(c) < upperBound;
  271. }
  272. };
  273. #endif
  274. _STLP_TEMPLATE_NULL
  275. struct _WCharIndexT<false> {
  276. static bool in_range(wchar_t c, size_t upperBound) {
  277. return size_t(c) < upperBound;
  278. }
  279. };
  280. typedef _WCharIndexT<wchar_t(-1) < 0> _WCharIndex;
  281. // Some helper functions used in ctype<>::scan_is and scan_is_not.
  282. struct _Ctype_is_mask : public unary_function<char, bool> {
  283. ctype_base::mask _Mask;
  284. const ctype_base::mask* _M_table;
  285. _Ctype_is_mask(ctype_base::mask __m, const ctype_base::mask* __t) : _Mask(__m), _M_table(__t) {}
  286. bool operator()(char __c) const { return (_M_table[(unsigned char) __c] & _Mask) != 0; }
  287. };
  288. struct _Ctype_not_mask : public unary_function<char, bool> {
  289. ctype_base::mask _Mask;
  290. const ctype_base::mask* _M_table;
  291. _Ctype_not_mask(ctype_base::mask __m, const ctype_base::mask* __t) : _Mask(__m), _M_table(__t) {}
  292. bool operator()(char __c) const { return (_M_table[(unsigned char) __c] & _Mask) == 0; }
  293. };
  294. ctype<char>::ctype(const ctype_base::mask * __tab, bool __del, size_t __refs) :
  295. locale::facet(__refs),
  296. _M_ctype_table(__tab ? __tab : classic_table()),
  297. _M_delete(__tab && __del)
  298. {}
  299. ctype<char>::~ctype() {
  300. if (_M_delete)
  301. delete[] __CONST_CAST(ctype_base::mask *, _M_ctype_table);
  302. }
  303. const char*
  304. #if defined (__DMC__)
  305. _STLP_DECLSPEC
  306. #endif
  307. ctype<char>::scan_is(ctype_base::mask __m, const char* __low, const char* __high) const
  308. { return _STLP_STD::find_if(__low, __high, _Ctype_is_mask(__m, _M_ctype_table)); }
  309. const char*
  310. #if defined (__DMC__)
  311. _STLP_DECLSPEC
  312. #endif
  313. ctype<char>::scan_not(ctype_base::mask __m, const char* __low, const char* __high) const
  314. { return _STLP_STD::find_if(__low, __high, _Ctype_not_mask(__m, _M_ctype_table)); }
  315. char ctype<char>::do_toupper(char __c) const
  316. { return (char) _S_upper[(unsigned char) __c]; }
  317. char ctype<char>::do_tolower(char __c) const
  318. { return (char) _S_lower[(unsigned char) __c]; }
  319. const char* ctype<char>::do_toupper(char* __low, const char* __high) const {
  320. for ( ; __low < __high; ++__low)
  321. *__low = (char) _S_upper[(unsigned char) *__low];
  322. return __high;
  323. }
  324. const char* ctype<char>::do_tolower(char* __low, const char* __high) const {
  325. for ( ; __low < __high; ++__low)
  326. *__low = (char) _S_lower[(unsigned char) *__low];
  327. return __high;
  328. }
  329. char
  330. ctype<char>::do_widen(char __c) const { return __c; }
  331. const char*
  332. ctype<char>::do_widen(const char* __low, const char* __high,
  333. char* __to) const {
  334. _STLP_PRIV __copy_trivial(__low, __high, __to);
  335. return __high;
  336. }
  337. char
  338. ctype<char>::do_narrow(char __c, char /* dfault */ ) const { return __c; }
  339. const char*
  340. ctype<char>::do_narrow(const char* __low, const char* __high,
  341. char /* dfault */, char* __to) const {
  342. _STLP_PRIV __copy_trivial(__low, __high, __to);
  343. return __high;
  344. }
  345. #if !defined (_STLP_NO_WCHAR_T)
  346. struct _Ctype_w_is_mask : public unary_function<wchar_t, bool> {
  347. ctype_base::mask M;
  348. const ctype_base::mask* table;
  349. _Ctype_w_is_mask(ctype_base::mask m, const ctype_base::mask* t)
  350. : M(m), table(t) {}
  351. bool operator()(wchar_t c) const
  352. { return _WCharIndex::in_range(c, ctype<char>::table_size) && (table[c] & M); }
  353. };
  354. //----------------------------------------------------------------------
  355. // ctype<wchar_t>
  356. ctype<wchar_t>::~ctype() {}
  357. bool ctype<wchar_t>::do_is(ctype_base::mask m, wchar_t c) const {
  358. const ctype_base::mask * table = ctype<char>::classic_table();
  359. return _WCharIndex::in_range(c, ctype<char>::table_size) && (m & table[c]);
  360. }
  361. const wchar_t* ctype<wchar_t>::do_is(const wchar_t* low, const wchar_t* high,
  362. ctype_base::mask * vec) const {
  363. // boris : not clear if this is the right thing to do...
  364. const ctype_base::mask * table = ctype<char>::classic_table();
  365. wchar_t c;
  366. for ( ; low < high; ++low, ++vec) {
  367. c = *low;
  368. *vec = _WCharIndex::in_range(c, ctype<char>::table_size) ? table[c] : ctype_base::mask(0);
  369. }
  370. return high;
  371. }
  372. const wchar_t*
  373. ctype<wchar_t>::do_scan_is(ctype_base::mask m,
  374. const wchar_t* low, const wchar_t* high) const {
  375. return find_if(low, high, _Ctype_w_is_mask(m, ctype<char>::classic_table()));
  376. }
  377. const wchar_t*
  378. ctype<wchar_t>::do_scan_not(ctype_base::mask m,
  379. const wchar_t* low, const wchar_t* high) const {
  380. return find_if(low, high, not1(_Ctype_w_is_mask(m, ctype<char>::classic_table())));
  381. }
  382. wchar_t ctype<wchar_t>::do_toupper(wchar_t c) const {
  383. return _WCharIndex::in_range(c, ctype<char>::table_size) ? (wchar_t)_S_upper[c]
  384. : c;
  385. }
  386. const wchar_t*
  387. ctype<wchar_t>::do_toupper(wchar_t* low, const wchar_t* high) const {
  388. for ( ; low < high; ++low) {
  389. wchar_t c = *low;
  390. *low = _WCharIndex::in_range(c, ctype<char>::table_size) ? (wchar_t)_S_upper[c]
  391. : c;
  392. }
  393. return high;
  394. }
  395. wchar_t ctype<wchar_t>::do_tolower(wchar_t c) const {
  396. return _WCharIndex::in_range(c, ctype<char>::table_size) ? (wchar_t)_S_lower[c]
  397. : c;
  398. }
  399. const wchar_t*
  400. ctype<wchar_t>::do_tolower(wchar_t* low, const wchar_t* high) const {
  401. for ( ; low < high; ++low) {
  402. wchar_t c = *low;
  403. *low = _WCharIndex::in_range(c, ctype<char>::table_size) ? (wchar_t)_S_lower[c]
  404. : c;
  405. }
  406. return high;
  407. }
  408. wchar_t ctype<wchar_t>::do_widen(char c) const {
  409. return (wchar_t)(unsigned char)c;
  410. }
  411. const char*
  412. ctype<wchar_t>::do_widen(const char* low, const char* high,
  413. wchar_t* dest) const {
  414. while (low != high)
  415. *dest++ = (wchar_t)(unsigned char)*low++;
  416. return high;
  417. }
  418. char ctype<wchar_t>::do_narrow(wchar_t c, char dfault) const
  419. { return (unsigned char)c == c ? (char)c : dfault; }
  420. const wchar_t* ctype<wchar_t>::do_narrow(const wchar_t* low,
  421. const wchar_t* high,
  422. char dfault, char* dest) const {
  423. while (low != high) {
  424. wchar_t c = *low++;
  425. *dest++ = (unsigned char)c == c ? (char)c : dfault;
  426. }
  427. return high;
  428. }
  429. # endif
  430. _STLP_END_NAMESPACE
  431. // Local Variables:
  432. // mode:C++
  433. // End: