Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-19 09:47:48

0001 /*=============================================================================
0002     Copyright (c) 2001-2011 Hartmut Kaiser
0003     Copyright (c) 2001-2011 Joel de Guzman
0004 
0005     Distributed under the Boost Software License, Version 1.0. (See accompanying
0006     file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0007 =============================================================================*/
0008 #if !defined(BOOST_SPIRIT_ASCII_APRIL_26_2006_1106PM)
0009 #define BOOST_SPIRIT_ASCII_APRIL_26_2006_1106PM
0010 
0011 #if defined(_MSC_VER)
0012 #pragma once
0013 #endif
0014 
0015 #include <climits>
0016 #include <boost/assert.hpp>
0017 #include <boost/cstdint.hpp>
0018 
0019 ///////////////////////////////////////////////////////////////////////////////
0020 // constants used to classify the single characters
0021 ///////////////////////////////////////////////////////////////////////////////
0022 #define BOOST_CC_DIGIT    0x0001
0023 #define BOOST_CC_XDIGIT   0x0002
0024 #define BOOST_CC_ALPHA    0x0004
0025 #define BOOST_CC_CTRL     0x0008
0026 #define BOOST_CC_LOWER    0x0010
0027 #define BOOST_CC_UPPER    0x0020
0028 #define BOOST_CC_SPACE    0x0040
0029 #define BOOST_CC_PUNCT    0x0080
0030 
0031 namespace boost { namespace spirit { namespace char_encoding
0032 {
0033     // The detection of isgraph(), isprint() and isblank() is done programmatically
0034     // to keep the character type table small. Additionally, these functions are
0035     // rather seldom used and the programmatic detection is very simple.
0036 
0037     ///////////////////////////////////////////////////////////////////////////
0038     // ASCII character classification table
0039     ///////////////////////////////////////////////////////////////////////////
0040     const unsigned char ascii_char_types[] =
0041     {
0042         /* NUL   0   0 */   BOOST_CC_CTRL,
0043         /* SOH   1   1 */   BOOST_CC_CTRL,
0044         /* STX   2   2 */   BOOST_CC_CTRL,
0045         /* ETX   3   3 */   BOOST_CC_CTRL,
0046         /* EOT   4   4 */   BOOST_CC_CTRL,
0047         /* ENQ   5   5 */   BOOST_CC_CTRL,
0048         /* ACK   6   6 */   BOOST_CC_CTRL,
0049         /* BEL   7   7 */   BOOST_CC_CTRL,
0050         /* BS    8   8 */   BOOST_CC_CTRL,
0051         /* HT    9   9 */   BOOST_CC_CTRL|BOOST_CC_SPACE,
0052         /* NL   10   a */   BOOST_CC_CTRL|BOOST_CC_SPACE,
0053         /* VT   11   b */   BOOST_CC_CTRL|BOOST_CC_SPACE,
0054         /* NP   12   c */   BOOST_CC_CTRL|BOOST_CC_SPACE,
0055         /* CR   13   d */   BOOST_CC_CTRL|BOOST_CC_SPACE,
0056         /* SO   14   e */   BOOST_CC_CTRL,
0057         /* SI   15   f */   BOOST_CC_CTRL,
0058         /* DLE  16  10 */   BOOST_CC_CTRL,
0059         /* DC1  17  11 */   BOOST_CC_CTRL,
0060         /* DC2  18  12 */   BOOST_CC_CTRL,
0061         /* DC3  19  13 */   BOOST_CC_CTRL,
0062         /* DC4  20  14 */   BOOST_CC_CTRL,
0063         /* NAK  21  15 */   BOOST_CC_CTRL,
0064         /* SYN  22  16 */   BOOST_CC_CTRL,
0065         /* ETB  23  17 */   BOOST_CC_CTRL,
0066         /* CAN  24  18 */   BOOST_CC_CTRL,
0067         /* EM   25  19 */   BOOST_CC_CTRL,
0068         /* SUB  26  1a */   BOOST_CC_CTRL,
0069         /* ESC  27  1b */   BOOST_CC_CTRL,
0070         /* FS   28  1c */   BOOST_CC_CTRL,
0071         /* GS   29  1d */   BOOST_CC_CTRL,
0072         /* RS   30  1e */   BOOST_CC_CTRL,
0073         /* US   31  1f */   BOOST_CC_CTRL,
0074         /* SP   32  20 */   BOOST_CC_SPACE,
0075         /*  !   33  21 */   BOOST_CC_PUNCT,
0076         /*  "   34  22 */   BOOST_CC_PUNCT,
0077         /*  #   35  23 */   BOOST_CC_PUNCT,
0078         /*  $   36  24 */   BOOST_CC_PUNCT,
0079         /*  %   37  25 */   BOOST_CC_PUNCT,
0080         /*  &   38  26 */   BOOST_CC_PUNCT,
0081         /*  '   39  27 */   BOOST_CC_PUNCT,
0082         /*  (   40  28 */   BOOST_CC_PUNCT,
0083         /*  )   41  29 */   BOOST_CC_PUNCT,
0084         /*  *   42  2a */   BOOST_CC_PUNCT,
0085         /*  +   43  2b */   BOOST_CC_PUNCT,
0086         /*  ,   44  2c */   BOOST_CC_PUNCT,
0087         /*  -   45  2d */   BOOST_CC_PUNCT,
0088         /*  .   46  2e */   BOOST_CC_PUNCT,
0089         /*  /   47  2f */   BOOST_CC_PUNCT,
0090         /*  0   48  30 */   BOOST_CC_DIGIT|BOOST_CC_XDIGIT,
0091         /*  1   49  31 */   BOOST_CC_DIGIT|BOOST_CC_XDIGIT,
0092         /*  2   50  32 */   BOOST_CC_DIGIT|BOOST_CC_XDIGIT,
0093         /*  3   51  33 */   BOOST_CC_DIGIT|BOOST_CC_XDIGIT,
0094         /*  4   52  34 */   BOOST_CC_DIGIT|BOOST_CC_XDIGIT,
0095         /*  5   53  35 */   BOOST_CC_DIGIT|BOOST_CC_XDIGIT,
0096         /*  6   54  36 */   BOOST_CC_DIGIT|BOOST_CC_XDIGIT,
0097         /*  7   55  37 */   BOOST_CC_DIGIT|BOOST_CC_XDIGIT,
0098         /*  8   56  38 */   BOOST_CC_DIGIT|BOOST_CC_XDIGIT,
0099         /*  9   57  39 */   BOOST_CC_DIGIT|BOOST_CC_XDIGIT,
0100         /*  :   58  3a */   BOOST_CC_PUNCT,
0101         /*  ;   59  3b */   BOOST_CC_PUNCT,
0102         /*  <   60  3c */   BOOST_CC_PUNCT,
0103         /*  =   61  3d */   BOOST_CC_PUNCT,
0104         /*  >   62  3e */   BOOST_CC_PUNCT,
0105         /*  ?   63  3f */   BOOST_CC_PUNCT,
0106         /*  @   64  40 */   BOOST_CC_PUNCT,
0107         /*  A   65  41 */   BOOST_CC_ALPHA|BOOST_CC_XDIGIT|BOOST_CC_UPPER,
0108         /*  B   66  42 */   BOOST_CC_ALPHA|BOOST_CC_XDIGIT|BOOST_CC_UPPER,
0109         /*  C   67  43 */   BOOST_CC_ALPHA|BOOST_CC_XDIGIT|BOOST_CC_UPPER,
0110         /*  D   68  44 */   BOOST_CC_ALPHA|BOOST_CC_XDIGIT|BOOST_CC_UPPER,
0111         /*  E   69  45 */   BOOST_CC_ALPHA|BOOST_CC_XDIGIT|BOOST_CC_UPPER,
0112         /*  F   70  46 */   BOOST_CC_ALPHA|BOOST_CC_XDIGIT|BOOST_CC_UPPER,
0113         /*  G   71  47 */   BOOST_CC_ALPHA|BOOST_CC_UPPER,
0114         /*  H   72  48 */   BOOST_CC_ALPHA|BOOST_CC_UPPER,
0115         /*  I   73  49 */   BOOST_CC_ALPHA|BOOST_CC_UPPER,
0116         /*  J   74  4a */   BOOST_CC_ALPHA|BOOST_CC_UPPER,
0117         /*  K   75  4b */   BOOST_CC_ALPHA|BOOST_CC_UPPER,
0118         /*  L   76  4c */   BOOST_CC_ALPHA|BOOST_CC_UPPER,
0119         /*  M   77  4d */   BOOST_CC_ALPHA|BOOST_CC_UPPER,
0120         /*  N   78  4e */   BOOST_CC_ALPHA|BOOST_CC_UPPER,
0121         /*  O   79  4f */   BOOST_CC_ALPHA|BOOST_CC_UPPER,
0122         /*  P   80  50 */   BOOST_CC_ALPHA|BOOST_CC_UPPER,
0123         /*  Q   81  51 */   BOOST_CC_ALPHA|BOOST_CC_UPPER,
0124         /*  R   82  52 */   BOOST_CC_ALPHA|BOOST_CC_UPPER,
0125         /*  S   83  53 */   BOOST_CC_ALPHA|BOOST_CC_UPPER,
0126         /*  T   84  54 */   BOOST_CC_ALPHA|BOOST_CC_UPPER,
0127         /*  U   85  55 */   BOOST_CC_ALPHA|BOOST_CC_UPPER,
0128         /*  V   86  56 */   BOOST_CC_ALPHA|BOOST_CC_UPPER,
0129         /*  W   87  57 */   BOOST_CC_ALPHA|BOOST_CC_UPPER,
0130         /*  X   88  58 */   BOOST_CC_ALPHA|BOOST_CC_UPPER,
0131         /*  Y   89  59 */   BOOST_CC_ALPHA|BOOST_CC_UPPER,
0132         /*  Z   90  5a */   BOOST_CC_ALPHA|BOOST_CC_UPPER,
0133         /*  [   91  5b */   BOOST_CC_PUNCT,
0134         /*  \   92  5c */   BOOST_CC_PUNCT,
0135         /*  ]   93  5d */   BOOST_CC_PUNCT,
0136         /*  ^   94  5e */   BOOST_CC_PUNCT,
0137         /*  _   95  5f */   BOOST_CC_PUNCT,
0138         /*  `   96  60 */   BOOST_CC_PUNCT,
0139         /*  a   97  61 */   BOOST_CC_ALPHA|BOOST_CC_XDIGIT|BOOST_CC_LOWER,
0140         /*  b   98  62 */   BOOST_CC_ALPHA|BOOST_CC_XDIGIT|BOOST_CC_LOWER,
0141         /*  c   99  63 */   BOOST_CC_ALPHA|BOOST_CC_XDIGIT|BOOST_CC_LOWER,
0142         /*  d  100  64 */   BOOST_CC_ALPHA|BOOST_CC_XDIGIT|BOOST_CC_LOWER,
0143         /*  e  101  65 */   BOOST_CC_ALPHA|BOOST_CC_XDIGIT|BOOST_CC_LOWER,
0144         /*  f  102  66 */   BOOST_CC_ALPHA|BOOST_CC_XDIGIT|BOOST_CC_LOWER,
0145         /*  g  103  67 */   BOOST_CC_ALPHA|BOOST_CC_LOWER,
0146         /*  h  104  68 */   BOOST_CC_ALPHA|BOOST_CC_LOWER,
0147         /*  i  105  69 */   BOOST_CC_ALPHA|BOOST_CC_LOWER,
0148         /*  j  106  6a */   BOOST_CC_ALPHA|BOOST_CC_LOWER,
0149         /*  k  107  6b */   BOOST_CC_ALPHA|BOOST_CC_LOWER,
0150         /*  l  108  6c */   BOOST_CC_ALPHA|BOOST_CC_LOWER,
0151         /*  m  109  6d */   BOOST_CC_ALPHA|BOOST_CC_LOWER,
0152         /*  n  110  6e */   BOOST_CC_ALPHA|BOOST_CC_LOWER,
0153         /*  o  111  6f */   BOOST_CC_ALPHA|BOOST_CC_LOWER,
0154         /*  p  112  70 */   BOOST_CC_ALPHA|BOOST_CC_LOWER,
0155         /*  q  113  71 */   BOOST_CC_ALPHA|BOOST_CC_LOWER,
0156         /*  r  114  72 */   BOOST_CC_ALPHA|BOOST_CC_LOWER,
0157         /*  s  115  73 */   BOOST_CC_ALPHA|BOOST_CC_LOWER,
0158         /*  t  116  74 */   BOOST_CC_ALPHA|BOOST_CC_LOWER,
0159         /*  u  117  75 */   BOOST_CC_ALPHA|BOOST_CC_LOWER,
0160         /*  v  118  76 */   BOOST_CC_ALPHA|BOOST_CC_LOWER,
0161         /*  w  119  77 */   BOOST_CC_ALPHA|BOOST_CC_LOWER,
0162         /*  x  120  78 */   BOOST_CC_ALPHA|BOOST_CC_LOWER,
0163         /*  y  121  79 */   BOOST_CC_ALPHA|BOOST_CC_LOWER,
0164         /*  z  122  7a */   BOOST_CC_ALPHA|BOOST_CC_LOWER,
0165         /*  {  123  7b */   BOOST_CC_PUNCT,
0166         /*  |  124  7c */   BOOST_CC_PUNCT,
0167         /*  }  125  7d */   BOOST_CC_PUNCT,
0168         /*  ~  126  7e */   BOOST_CC_PUNCT,
0169         /* DEL 127  7f */   BOOST_CC_CTRL,
0170         0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0171         0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0172         0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0173         0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0174         0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0175         0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0176         0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0177         0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0178     };
0179 
0180     ///////////////////////////////////////////////////////////////////////////
0181     //  Test characters for specified conditions (using ASCII)
0182     ///////////////////////////////////////////////////////////////////////////
0183     struct ascii
0184     {
0185         typedef char char_type;
0186         typedef unsigned char classify_type;
0187 
0188         static bool
0189         isascii_(int ch)
0190         {
0191             return 0 == (ch & ~0x7f);
0192         }
0193 
0194         static bool
0195         ischar(int ch)
0196         {
0197             return isascii_(ch);
0198         }
0199 
0200         // *** Note on assertions: The precondition is that the calls to
0201         // these functions do not violate the required range of ch (type int)
0202         // which is that strict_ischar(ch) should be true. It is the
0203         // responsibility of the caller to make sure this precondition is not
0204         // violated.
0205 
0206         static bool
0207         strict_ischar(int ch)
0208         {
0209             return ch >= 0 && ch <= 127;
0210         }
0211 
0212         static bool
0213         isalnum(int ch)
0214         {
0215             BOOST_ASSERT(strict_ischar(ch));
0216             return (ascii_char_types[ch] & BOOST_CC_ALPHA)
0217                 || (ascii_char_types[ch] & BOOST_CC_DIGIT);
0218         }
0219 
0220         static bool
0221         isalpha(int ch)
0222         {
0223             BOOST_ASSERT(strict_ischar(ch));
0224             return (ascii_char_types[ch] & BOOST_CC_ALPHA) ? true : false;
0225         }
0226 
0227         static bool
0228         isdigit(int ch)
0229         {
0230             BOOST_ASSERT(strict_ischar(ch));
0231             return (ascii_char_types[ch] & BOOST_CC_DIGIT) ? true : false;
0232         }
0233 
0234         static bool
0235         isxdigit(int ch)
0236         {
0237             BOOST_ASSERT(strict_ischar(ch));
0238             return (ascii_char_types[ch] & BOOST_CC_XDIGIT) ? true : false;
0239         }
0240 
0241         static bool
0242         iscntrl(int ch)
0243         {
0244             BOOST_ASSERT(strict_ischar(ch));
0245             return (ascii_char_types[ch] & BOOST_CC_CTRL) ? true : false;
0246         }
0247 
0248         static bool
0249         isgraph(int ch)
0250         {
0251             BOOST_ASSERT(strict_ischar(ch));
0252             return ('\x21' <= ch && ch <= '\x7e');
0253         }
0254 
0255         static bool
0256         islower(int ch)
0257         {
0258             BOOST_ASSERT(strict_ischar(ch));
0259             return (ascii_char_types[ch] & BOOST_CC_LOWER) ? true : false;
0260         }
0261 
0262         static bool
0263         isprint(int ch)
0264         {
0265             BOOST_ASSERT(strict_ischar(ch));
0266             return ('\x20' <= ch && ch <= '\x7e');
0267         }
0268 
0269         static bool
0270         ispunct(int ch)
0271         {
0272             BOOST_ASSERT(strict_ischar(ch));
0273             return (ascii_char_types[ch] & BOOST_CC_PUNCT) ? true : false;
0274         }
0275 
0276         static bool
0277         isspace(int ch)
0278         {
0279             BOOST_ASSERT(strict_ischar(ch));
0280             return (ascii_char_types[ch] & BOOST_CC_SPACE) ? true : false;
0281         }
0282 
0283         static bool
0284         isblank BOOST_PREVENT_MACRO_SUBSTITUTION (int ch)
0285         {
0286             BOOST_ASSERT(strict_ischar(ch));
0287             return ('\x09' == ch || '\x20' == ch);
0288         }
0289 
0290         static bool
0291         isupper(int ch)
0292         {
0293             BOOST_ASSERT(strict_ischar(ch));
0294             return (ascii_char_types[ch] & BOOST_CC_UPPER) ? true : false;
0295         }
0296 
0297         ///////////////////////////////////////////////////////////////////////
0298         //  Simple character conversions
0299         ///////////////////////////////////////////////////////////////////////
0300 
0301         static int
0302         tolower(int ch)
0303         {
0304             BOOST_ASSERT(strict_ischar(ch));
0305             return isupper(ch) ? (ch - 'A' + 'a') : ch;
0306         }
0307 
0308         static int
0309         toupper(int ch)
0310         {
0311             BOOST_ASSERT(strict_ischar(ch));
0312             return islower(ch) ? (ch - 'a' + 'A') : ch;
0313         }
0314 
0315         static ::boost::uint32_t
0316         toucs4(int ch)
0317         {
0318             BOOST_ASSERT(strict_ischar(ch));
0319             return ch;
0320         }
0321     };
0322 
0323 }}}
0324 
0325 ///////////////////////////////////////////////////////////////////////////////
0326 // undefine macros
0327 ///////////////////////////////////////////////////////////////////////////////
0328 #undef BOOST_CC_DIGIT
0329 #undef BOOST_CC_XDIGIT
0330 #undef BOOST_CC_ALPHA
0331 #undef BOOST_CC_CTRL
0332 #undef BOOST_CC_LOWER
0333 #undef BOOST_CC_UPPER
0334 #undef BOOST_CC_PUNCT
0335 #undef BOOST_CC_SPACE
0336 
0337 #endif