Home | History | Annotate | Download | only in android
      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 9 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 9 (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 #if !defined(_U)
     47 #  if !defined(_CTYPE_U)
     48 #   error Bionic header ctype.h does not define either _U nor _CTYPE_U
     49 #  endif
     50 #  define _U _CTYPE_U
     51 #  define _L _CTYPE_L
     52 #  define _N _CTYPE_N
     53 #  define _S _CTYPE_S
     54 #  define _P _CTYPE_P
     55 #  define _C _CTYPE_C
     56 #  define _X _CTYPE_X
     57 #  define _B _CTYPE_B
     58 #endif
     59 
     60 static const unsigned short ctype_android_tab[256+128] = {
     61        /* -128..-1 */
     62         _C,     _C,           _C,     _C,     _C,     _C,     _C,     _C, /* 80 */
     63         _C,     _C,           _C,     _C,     _C,     _C,     _C,     _C, /* 88 */
     64         _C,     _C,           _C,     _C,     _C,     _C,     _C,     _C, /* 90 */
     65         _C,     _C,           _C,     _C,     _C,     _C,     _C,     _C, /* 98 */
     66         _P,     _P,           _P,     _P,     _P,     _P,     _P,     _P, /* A0 */
     67         _P,     _P,           _P,     _P,     _P,     _P,     _P,     _P, /* A8 */
     68         _P,     _P,           _P,     _P,     _P,     _P,     _P,     _P, /* B0 */
     69         _P,     _P,           _P,     _P,     _P,     _P,     _P,     _P, /* B8 */
     70         _P,     _P,           _P,     _P,     _P,     _P,     _P,     _P, /* C0 */
     71         _P,     _P,           _P,     _P,     _P,     _P,     _P,     _P, /* C8 */
     72         _P,     _P,           _P,     _P,     _P,     _P,     _P,     _P, /* D0 */
     73         _P,     _P,           _P,     _P,     _P,     _P,     _P,     _P, /* D8 */
     74         _P,     _P,           _P,     _P,     _P,     _P,     _P,     _P, /* E0 */
     75         _P,     _P,           _P,     _P,     _P,     _P,     _P,     _P, /* E8 */
     76         _P,     _P,           _P,     _P,     _P,     _P,     _P,     _P, /* F0 */
     77         _P,     _P,           _P,     _P,     _P,     _P,     _P,     _P, /* F8 */
     78        /* 0..127 */
     79         _C,     _C,           _C,     _C,     _C,     _C,     _C,     _C,
     80         _C,     _C|_S|_BLANK, _C|_S,  _C|_S,  _C|_S,  _C|_S,  _C,     _C,
     81         _C,     _C,           _C,     _C,     _C,     _C,     _C,     _C,
     82         _C,     _C,           _C,     _C,     _C,     _C,     _C,     _C,
     83   _S|_B|_BLANK, _P,           _P,     _P,     _P,     _P,     _P,     _P,
     84         _P,     _P,           _P,     _P,     _P,     _P,     _P,     _P,
     85         _N,     _N,           _N,     _N,     _N,     _N,     _N,     _N,
     86         _N,     _N,           _P,     _P,     _P,     _P,     _P,     _P,
     87         _P,     _U|_X,        _U|_X,  _U|_X,  _U|_X,  _U|_X,  _U|_X,  _U,
     88         _U,     _U,           _U,     _U,     _U,     _U,     _U,     _U,
     89         _U,     _U,           _U,     _U,     _U,     _U,     _U,     _U,
     90         _U,     _U,           _U,     _P,     _P,     _P,     _P,     _P,
     91         _P,     _L|_X,        _L|_X,  _L|_X,  _L|_X,  _L|_X,  _L|_X,  _L,
     92         _L,     _L,           _L,     _L,     _L,     _L,     _L,     _L,
     93         _L,     _L,           _L,     _L,     _L,     _L,     _L,     _L,
     94         /* determine printability based on the IS0 8859 8-bit standard */
     95         _L,     _L,           _L,     _P,     _P,     _P,     _P,     _C,
     96         /* 128..255, same as -128..127 */
     97         _C,     _C,           _C,     _C,     _C,     _C,     _C,     _C, /* 80 */
     98         _C,     _C,           _C,     _C,     _C,     _C,     _C,     _C, /* 88 */
     99         _C,     _C,           _C,     _C,     _C,     _C,     _C,     _C, /* 90 */
    100         _C,     _C,           _C,     _C,     _C,     _C,     _C,     _C, /* 98 */
    101         _P,     _P,           _P,     _P,     _P,     _P,     _P,     _P, /* A0 */
    102         _P,     _P,           _P,     _P,     _P,     _P,     _P,     _P, /* A8 */
    103         _P,     _P,           _P,     _P,     _P,     _P,     _P,     _P, /* B0 */
    104         _P,     _P,           _P,     _P,     _P,     _P,     _P,     _P, /* B8 */
    105         _P,     _P,           _P,     _P,     _P,     _P,     _P,     _P, /* C0 */
    106         _P,     _P,           _P,     _P,     _P,     _P,     _P,     _P, /* C8 */
    107         _P,     _P,           _P,     _P,     _P,     _P,     _P,     _P, /* D0 */
    108         _P,     _P,           _P,     _P,     _P,     _P,     _P,     _P, /* D8 */
    109         _P,     _P,           _P,     _P,     _P,     _P,     _P,     _P, /* E0 */
    110         _P,     _P,           _P,     _P,     _P,     _P,     _P,     _P, /* E8 */
    111         _P,     _P,           _P,     _P,     _P,     _P,     _P,     _P, /* F0 */
    112         _P,     _P,           _P,     _P,     _P,     _P,     _P,     _P, /* F8 */
    113 };
    114 
    115 const unsigned short* const _ctype_android = ctype_android_tab + 128;
    116