• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // -*- C++ -*-
2 //===-------------------- support/win32/locale_win32.cpp ------------------===//
3 //
4 //                     The LLVM Compiler Infrastructure
5 //
6 // This file is dual licensed under the MIT and the University of Illinois Open
7 // Source Licenses. See LICENSE.TXT for details.
8 //
9 //===----------------------------------------------------------------------===//
10 
11 #include <ctype.h>
12 
13 // Bionic exports the non-standard _ctype_ array in <ctype.h>,
14 // unfortunately, cannot be used directly for libc++ because it doesn't
15 // have a proper bit-flag for blank characters.
16 //
17 // Note that the header does define a _B flag (as 0x80), but it
18 // is only set on the space (32) character, and used to implement
19 // isprint() properly. The implementation of isblank() relies on
20 // direct comparisons with 7 and 32 instead.
21 //
22 // The following is a local copy of the Bionic _ctype_ array that has
23 // been modified in the following way:
24 //
25 //   - It stores 16-bit unsigned values, instead of 8-bit char ones.
26 //
27 //   - Bit flag _BLANK (0x100) is used to indicate blank characters.
28 //     It is only set for indices 7 (TAB) and 32 (SPACE).
29 //
30 //   - Support signed char properly for indexing.
31 
32 // Used to tag blank characters, this doesn't appear in <ctype.h> nor
33 // the original Bionic _ctype_ array.
34 #define _BLANK  0x100
35 
36 // NOTE: A standalone forward declaration is required to ensure that this
37 // variable is properly exported with a C name. In other words, this does
38 // _not_ work:
39 //
40 //  extern "C" {
41 //  const char* const _ctype_android = ...;
42 //  }
43 //
44 extern "C" const unsigned short* const _ctype_android;
45 
46 static const unsigned short ctype_android_tab[256+128] = {
47        /* -128..-1 */
48         _C,     _C,     _C,     _C,     _C,     _C,     _C,     _C, /* 80 */
49         _C,     _C,     _C,     _C,     _C,     _C,     _C,     _C, /* 88 */
50         _C,     _C,     _C,     _C,     _C,     _C,     _C,     _C, /* 90 */
51         _C,     _C,     _C,     _C,     _C,     _C,     _C,     _C, /* 98 */
52         _P,     _P,     _P,     _P,     _P,     _P,     _P,     _P, /* A0 */
53         _P,     _P,     _P,     _P,     _P,     _P,     _P,     _P, /* A8 */
54         _P,     _P,     _P,     _P,     _P,     _P,     _P,     _P, /* B0 */
55         _P,     _P,     _P,     _P,     _P,     _P,     _P,     _P, /* B8 */
56         _P,     _P,     _P,     _P,     _P,     _P,     _P,     _P, /* C0 */
57         _P,     _P,     _P,     _P,     _P,     _P,     _P,     _P, /* C8 */
58         _P,     _P,     _P,     _P,     _P,     _P,     _P,     _P, /* D0 */
59         _P,     _P,     _P,     _P,     _P,     _P,     _P,     _P, /* D8 */
60         _P,     _P,     _P,     _P,     _P,     _P,     _P,     _P, /* E0 */
61         _P,     _P,     _P,     _P,     _P,     _P,     _P,     _P, /* E8 */
62         _P,     _P,     _P,     _P,     _P,     _P,     _P,     _P, /* F0 */
63         _P,     _P,     _P,     _P,     _P,     _P,     _P,     _P, /* F8 */
64        /* 0..127 */
65         _C,     _C,     _C,     _C,     _C,     _C,     _C,     _C|_BLANK,
66         _C,     _C|_S,  _C|_S,  _C|_S,  _C|_S,  _C|_S,  _C,     _C,
67         _C,     _C,     _C,     _C,     _C,     _C,     _C,     _C,
68         _C,     _C,     _C,     _C,     _C,     _C,     _C,     _C,
69   _S|_B|_BLANK, _P,     _P,     _P,     _P,     _P,     _P,     _P,
70         _P,     _P,     _P,     _P,     _P,     _P,     _P,     _P,
71         _N,     _N,     _N,     _N,     _N,     _N,     _N,     _N,
72         _N,     _N,     _P,     _P,     _P,     _P,     _P,     _P,
73         _P,     _U|_X,  _U|_X,  _U|_X,  _U|_X,  _U|_X,  _U|_X,  _U,
74         _U,     _U,     _U,     _U,     _U,     _U,     _U,     _U,
75         _U,     _U,     _U,     _U,     _U,     _U,     _U,     _U,
76         _U,     _U,     _U,     _P,     _P,     _P,     _P,     _P,
77         _P,     _L|_X,  _L|_X,  _L|_X,  _L|_X,  _L|_X,  _L|_X,  _L,
78         _L,     _L,     _L,     _L,     _L,     _L,     _L,     _L,
79         _L,     _L,     _L,     _L,     _L,     _L,     _L,     _L,
80         /* determine printability based on the IS0 8859 8-bit standard */
81         _L,     _L,     _L,     _P,     _P,     _P,     _P,     _C,
82         /* 128..255, same as -128..127 */
83         _C,     _C,     _C,     _C,     _C,     _C,     _C,     _C, /* 80 */
84         _C,     _C,     _C,     _C,     _C,     _C,     _C,     _C, /* 88 */
85         _C,     _C,     _C,     _C,     _C,     _C,     _C,     _C, /* 90 */
86         _C,     _C,     _C,     _C,     _C,     _C,     _C,     _C, /* 98 */
87         _P,     _P,     _P,     _P,     _P,     _P,     _P,     _P, /* A0 */
88         _P,     _P,     _P,     _P,     _P,     _P,     _P,     _P, /* A8 */
89         _P,     _P,     _P,     _P,     _P,     _P,     _P,     _P, /* B0 */
90         _P,     _P,     _P,     _P,     _P,     _P,     _P,     _P, /* B8 */
91         _P,     _P,     _P,     _P,     _P,     _P,     _P,     _P, /* C0 */
92         _P,     _P,     _P,     _P,     _P,     _P,     _P,     _P, /* C8 */
93         _P,     _P,     _P,     _P,     _P,     _P,     _P,     _P, /* D0 */
94         _P,     _P,     _P,     _P,     _P,     _P,     _P,     _P, /* D8 */
95         _P,     _P,     _P,     _P,     _P,     _P,     _P,     _P, /* E0 */
96         _P,     _P,     _P,     _P,     _P,     _P,     _P,     _P, /* E8 */
97         _P,     _P,     _P,     _P,     _P,     _P,     _P,     _P, /* F0 */
98         _P,     _P,     _P,     _P,     _P,     _P,     _P,     _P, /* F8 */
99 };
100 
101 const unsigned short* const _ctype_android = ctype_android_tab + 128;
102