Changeset 17 for trunk/src


Ignore:
Timestamp:
Jan 13, 2008, 8:50:53 PM (11 years ago)
Author:
cameron
Message:

Initiating ASCII/EBCDIC selection using templates

Location:
trunk/src
Files:
1 added
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/charsets/ext_ascii_8.c

    r15 r17  
    2929
    3030int Ext_ASCII_8_Lexer::BOM_size(int rel_pos) {
    31   if (s3int32((unsigned char *) &parsing_engine_data->x8data) == c3int32(0xEF, 0xBB, 0xBF))
     31  if (s3int32((unsigned char *) &parsing_engine_data->x8data) == c3int32<Native,0xEF, 0xBB, 0xBF>::value)
    3232    return 3;
    3333  else return 0;
  • trunk/src/engine.c

    r16 r17  
    198198}
    199199
     200
    200201#include "multiliteral.h"
     202
    201203/* Now the XML recognizers. */
    202204
    203205inline bool ParsingEngine::at_EndTag_Start() const {
    204   return s2int16(x8dataPtr(0)) == c2int16('<', '/');
     206  return s2int16(x8dataPtr(0)) == c2int16<ASCII, '<', '/'>::value;
    205207}
    206208
    207209inline bool ParsingEngine::at_Comment_Start() const {
    208   return s4int32(x8dataPtr(0)) == c4int32('<', '!', '-', '-');
     210  return s4int32(x8dataPtr(0)) == c4int32<ASCII, '<', '!', '-', '-'>::value;
    209211}
    210212
    211213inline bool ParsingEngine::at_DoubleHyphen() const {
    212   return s2int16(x8dataPtr(0)) == c2int16('-', '-');
     214  return s2int16(x8dataPtr(0)) == c2int16<ASCII, '-', '-'>::value;
    213215}
    214216
    215217inline bool ParsingEngine::at_Comment_End() const {
    216   return s3int32(x8dataPtr(0)) == c3int32('-', '-', '>');
     218  return s3int32(x8dataPtr(0)) == c3int32<ASCII, '-', '-', '>'>::value;
    217219}
    218220
    219221inline bool ParsingEngine::at_CDATA_Start() const {
    220222  return s8int64(x8dataPtr(0)) ==
    221          c8int64('<', '!', '[', 'C', 'D', 'A', 'T', 'A');
     223         c8int64<ASCII, '<', '!', '[', 'C', 'D', 'A', 'T', 'A'>::value;
    222224}
    223225
    224226inline bool ParsingEngine::at_CDATA_End() const {
    225   return s3int32(x8dataPtr(0)) == c3int32(']', ']', '>');
     227  return s3int32(x8dataPtr(0)) == c3int32<ASCII, ']', ']', '>'>::value;
    226228}
    227229
    228230inline bool ParsingEngine::at_PI_Start() const {
    229   return s2int16(x8dataPtr(0)) == c2int16('<', '?');
     231  return s2int16(x8dataPtr(0)) == c2int16<ASCII, '<', '?'>::value;
    230232}
    231233
    232234inline bool ParsingEngine::at_PI_End() const {
    233   return s2int16(x8dataPtr(0)) == c2int16('?', '>');
     235  return s2int16(x8dataPtr(0)) == c2int16<ASCII, '?', '>'>::value;
    234236}
    235237
    236238inline bool ParsingEngine::at_EqualsDQuote() const {
    237   return s2int16(x8dataPtr(0)) == c2int16('=', '"');
     239  return s2int16(x8dataPtr(0)) == c2int16<ASCII, '=', '"'>::value;
    238240}
    239241
    240242inline bool ParsingEngine::at_EqualsSQuote() const {
    241   return s2int16(x8dataPtr(0)) == c2int16('=', '\'');
     243  return s2int16(x8dataPtr(0)) == c2int16<ASCII, '=', '\''>::value;
    242244}
    243245
    244246inline bool ParsingEngine::at_xmlns() const {
    245   return s5int64(x8dataPtr(0)) == c5int64('x', 'm', 'l', 'n', 's');
     247  return s5int64(x8dataPtr(0)) == c5int64<ASCII, 'x', 'm', 'l', 'n', 's'>::value;
    246248}
    247249
    248250inline bool ParsingEngine::at_EmptyElementDelim() const {
    249   return s2int16(x8dataPtr(0)) == c2int16('/', '>');
     251  return s2int16(x8dataPtr(0)) == c2int16<ASCII, '/', '>'>::value;
    250252}
    251253
    252254inline bool ParsingEngine::at_XmlDecl_start() const {
    253   return (s5int64(x8dataPtr(0)) == c5int64('<', '?', 'x', 'm', 'l')) &&
     255  return (s5int64(x8dataPtr(0)) == c5int64<ASCII, '<', '?', 'x', 'm', 'l'>::value) &&
    254256         ASCII_WS_at(5);
    255257}
    256258
    257259inline bool ParsingEngine::at_version() const {
    258   return s7int64(x8dataPtr(0)) == c7int64('v', 'e', 'r', 's', 'i', 'o', 'n');
     260  return s7int64(x8dataPtr(0)) == c7int64<ASCII, 'v', 'e', 'r', 's', 'i', 'o', 'n'>::value;
    259261}
    260262
    261263inline bool ParsingEngine::at_1_0() const {
    262   return (s5int64(x8dataPtr(0)) == c5int64('"', '1', '.', '0', '"')) ||
    263          (s5int64(x8dataPtr(0)) == c5int64('\'', '1', '.', '0', '\''));
     264  return (s5int64(x8dataPtr(0)) == c5int64<ASCII, '"', '1', '.', '0', '"'>::value) ||
     265         (s5int64(x8dataPtr(0)) == c5int64<ASCII, '\'', '1', '.', '0', '\''>::value);
    264266}
    265267
    266268inline bool ParsingEngine::at_1_1() const {
    267   return (s5int64(x8dataPtr(0)) == c5int64('"', '1', '.', '1', '"')) ||
    268          (s5int64(x8dataPtr(0)) == c5int64('\'', '1', '.', '1', '\''));
     269  return (s5int64(x8dataPtr(0)) == c5int64<ASCII, '"', '1', '.', '1', '"'>::value) ||
     270         (s5int64(x8dataPtr(0)) == c5int64<ASCII, '\'', '1', '.', '1', '\''>::value);
    269271}
    270272
    271273inline bool ParsingEngine::at_encoding() const {
    272   return s8int64(x8dataPtr(0)) == c8int64('e', 'n', 'c', 'o', 'd', 'i', 'n', 'g');
     274  return s8int64(x8dataPtr(0)) == c8int64<ASCII, 'e', 'n', 'c', 'o', 'd', 'i', 'n', 'g'>::value;
    273275}
    274276
    275277inline bool ParsingEngine::at_standalone() const {
    276   return (s8int64(x8dataPtr(0)) == c8int64('s', 't', 'a', 'n', 'd', 'a', 'l', 'o')) &
    277          (s2int16(x8dataPtr(8)) == c2int16('n', 'e'));
     278  return (s8int64(x8dataPtr(0)) == c8int64<ASCII, 's', 't', 'a', 'n', 'd', 'a', 'l', 'o'>::value) &
     279         (s2int16(x8dataPtr(8)) == c2int16<ASCII, 'n', 'e'>::value);
    278280}
    279281
    280282inline bool ParsingEngine::at_yes() const {
    281   return (s5int64(x8dataPtr(0)) == c5int64('"', 'y', 'e', 's', '"')) |
    282          (s5int64(x8dataPtr(0)) == c5int64('\'', 'y', 'e', 's', '\''));
     283  return (s5int64(x8dataPtr(0)) == c5int64<ASCII, '"', 'y', 'e', 's', '"'>::value) |
     284         (s5int64(x8dataPtr(0)) == c5int64<ASCII, '\'', 'y', 'e', 's', '\''>::value);
    283285}
    284286
    285287inline bool ParsingEngine::at_no() const {
    286   return (s4int32(x8dataPtr(0)) == c4int32('"', 'n', 'o', '"')) |
    287          (s4int32(x8dataPtr(0)) == c4int32('\'', 'n', 'o', '\''));
     288  return (s4int32(x8dataPtr(0)) == c4int32<ASCII, '"', 'n', 'o', '"'>::value) |
     289         (s4int32(x8dataPtr(0)) == c4int32<ASCII, '\'', 'n', 'o', '\''>::value);
    288290}
    289291
     
    403405        // Check for illegal [Xx][Mm][Ll] target.
    404406        if ((AbsPos() - markup_start == 5) &&
    405             ((s3int32(x8dataPtr(-3)) | c3int32(0x20, 0x20, 0x20)) == c3int32('x', 'm', 'l'))) {
     407            ((s3int32(x8dataPtr(-3)) | c3int32<ASCII, 0x20, 0x20, 0x20>::value)
     408                == c3int32<ASCII, 'x', 'm', 'l'>::value)) {
    406409                Error_action(markup_start, AbsPos());
    407410                return;
  • trunk/src/multiliteral.h

    r11 r17  
    1919#include <assert.h>
    2020#include <stdint.h>
     21#include "charsets/ASCII_EBCDIC.h"
    2122
    2223/*
     
    252616, 32 or 64 bit integer value.   These functions are intended to be called
    2627with constant arguments and hence to be applied at compile time.
     28This is achieved using template metaprogramming.
    2729*/
    2830
    29 static inline uint16_t c2int16(unsigned char c1, unsigned char c2) {
     31template <CharBase C, unsigned char c1, unsigned char c2>
     32struct c2int16 {
     33  static uint16_t const value =
    3034#if BYTE_ORDER == BIG_ENDIAN
    31   return (((uint16_t) c1) << 8) + (uint16_t) c2;
     35    (((uint16_t) Ord<C,c1>::value) << 8) + (uint16_t) Ord<C,c2>::value;
    3236#endif
    3337#if BYTE_ORDER == LITTLE_ENDIAN
    34   return (uint16_t) c1 + (((uint16_t) c2) << 8);
     38    (uint16_t) Ord<C,c1>::value + (((uint16_t) Ord<C,c2>::value) << 8);
    3539#endif
    36 }
     40};
    3741
    38 static inline uint32_t c4int32(unsigned char c1, unsigned char c2,
    39                         unsigned char c3, unsigned char c4) {
     42template <CharBase C, unsigned char c1, unsigned char c2,
     43                      unsigned char c3, unsigned char c4>
     44struct c4int32 {
     45  static uint32_t const value =
    4046#if BYTE_ORDER == BIG_ENDIAN
    41   return (((uint32_t) c2int16(c1, c2)) << 16) + (uint32_t) c2int16(c3, c4);
     47    (((uint16_t) c2int16<C,c1,c2>::value) << 16) + (uint16_t) c2int16<C,c3,c4>::value;
    4248#endif
    4349#if BYTE_ORDER == LITTLE_ENDIAN
    44   return ((uint32_t) c2int16(c1, c2)) + (((uint32_t) c2int16(c3, c4)) << 16);
     50    (uint16_t) c2int16<C,c1,c2>::value + (((uint16_t) c2int16<C,c3,c4>::value) << 16);
    4551#endif
    46 }
     52};
    4753
    48 static inline uint64_t c8int64(unsigned char c1, unsigned char c2,
    49                         unsigned char c3, unsigned char c4,
    50                         unsigned char c5, unsigned char c6,
    51                         unsigned char c7, unsigned char c8) {
     54template <CharBase C, unsigned char c1, unsigned char c2,
     55                      unsigned char c3, unsigned char c4,
     56                      unsigned char c5, unsigned char c6,
     57                      unsigned char c7, unsigned char c8>
     58struct c8int64 {
     59  static uint64_t const value =
    5260#if BYTE_ORDER == BIG_ENDIAN
    53   return ((uint64_t) c4int32(c1, c2, c3, c4)) << 32 +
    54           (uint64_t) c4int32(c5, c6, c7, c8);
     61    ((uint64_t) c4int32<C, c1, c2, c3, c4>::value) << 32 +
     62     (uint64_t) c4int32<C, c5, c6, c7, c8>::value;
    5563#endif
    5664#if BYTE_ORDER == LITTLE_ENDIAN
    57   return ((uint64_t) c4int32(c1, c2, c3, c4)) +
    58          (((uint64_t) c4int32(c5, c6, c7, c8)) << 32);
     65    ((uint64_t) c4int32<C, c1, c2, c3, c4>::value) +
     66    ((uint64_t) c4int32<C, c5, c6, c7, c8>::value) << 32;
    5967#endif
    60 }
     68};
     69
    6170
    6271/*  Specialized helpers for 3, 5, 6, and 7 character combinations. */
    6372
    64 static inline uint32_t c3int32(unsigned char c1, unsigned char c2,
    65                                unsigned char c3) {
    66   return c4int32(c1, c2, c3, 0);
    67 }
     73template <CharBase C, unsigned char c1, unsigned char c2,
     74                      unsigned char c3>
     75struct c3int32 {
     76  static uint32_t const value = c4int32<C, c1, c2, c3, 0>::value;
     77};
    6878
    69 static inline uint64_t c5int64(unsigned char c1, unsigned char c2,
    70                                unsigned char c3, unsigned char c4,
    71                                unsigned char c5) {
    72   return c8int64(c1, c2, c3, c4, c5, 0, 0, 0);
    73 }
     79template <CharBase C, unsigned char c1, unsigned char c2,
     80                      unsigned char c3, unsigned char c4,
     81                      unsigned char c5>
     82struct c5int64 {
     83  static uint64_t const value = c8int64<C, c1, c2, c3, c4, c5, 0, 0, 0>::value;
     84};
    7485
    75 static inline uint64_t c6int64(unsigned char c1, unsigned char c2,
    76                                unsigned char c3, unsigned char c4,
    77                                unsigned char c5, unsigned char c6) {
    78   return c8int64(c1, c2, c3, c4, c5, c6, 0, 0);
    79 }
     86template <CharBase C, unsigned char c1, unsigned char c2,
     87                      unsigned char c3, unsigned char c4,
     88                      unsigned char c5, unsigned char c6>
     89struct c6int64 {
     90  static uint64_t const value = c8int64<C, c1, c2, c3, c4, c5, c6, 0, 0>::value;
     91};
    8092
    81 static inline uint64_t c7int64(unsigned char c1, unsigned char c2,
    82                                unsigned char c3, unsigned char c4,
    83                                unsigned char c5, unsigned char c6,
    84                                unsigned char c7) {
    85   return c8int64(c1, c2, c3, c4, c5, c6, c7, 0);
    86 }
     93template <CharBase C, unsigned char c1, unsigned char c2,
     94                      unsigned char c3, unsigned char c4,
     95                      unsigned char c5, unsigned char c6,
     96                      unsigned char c7>
     97struct c7int64 {
     98  static uint64_t const value = c8int64<C, c1, c2, c3, c4, c5, c6, c7, 0>::value;
     99};
     100
    87101
    88102/*
     
    104118
    105119static inline uint32_t s3int32(unsigned char s[]) {
    106   return s4int32(s) & c3int32(0xFF, 0xFF, 0xFF);
     120  return s4int32(s) & c3int32<Native, 0xFF, 0xFF, 0xFF>::value;
    107121}
    108122
    109123static inline uint64_t s5int64(unsigned char s[]) {
    110   return s8int64(s) & c5int64(0xFF, 0xFF, 0xFF, 0xFF, 0xFF);
     124  return s8int64(s) & c5int64<Native, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF>::value;
    111125}
    112126
    113127static inline uint64_t s6int64(unsigned char s[]) {
    114   return s8int64(s) & c6int64(0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF);
     128  return s8int64(s) & c6int64<Native, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF>::value;
    115129}
    116130
    117131static inline uint64_t s7int64(unsigned char s[]) {
    118   return s8int64(s) & c7int64(0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF);
     132  return s8int64(s) & c7int64<Native, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF>::value;
    119133}
    120134
Note: See TracChangeset for help on using the changeset viewer.