textwolf  0.2
char.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2014 Patrick P. Frey
3  *
4  * This Source Code Form is subject to the terms of the Mozilla Public
5  * License, v. 2.0. If a copy of the MPL was not distributed with this
6  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
7  */
10 #ifndef __TEXTWOLF_CHAR_HPP__
11 #define __TEXTWOLF_CHAR_HPP__
12 #include <cstddef>
13 
14 #ifdef BOOST_VERSION
15 #include <boost/cstdint.hpp>
16 namespace textwolf {
19  typedef boost::uint32_t UChar;
20  typedef boost::uint64_t EChar;
21 }//namespace
22 #else
23 #ifdef _MSC_VER
24 #pragma warning(disable:4290)
25 #include <BaseTsd.h>
26 namespace textwolf {
29  typedef DWORD32 UChar;
30  typedef DWORD64 EChar;
31 }//namespace
32 #else
33 #include <stdint.h>
34 namespace textwolf {
37  typedef uint32_t UChar;
38  typedef uint64_t EChar;
39 }//namespace
40 #endif
41 #endif
42 
43 namespace textwolf {
49 template <typename RESTYPE, RESTYPE nullvalue_, int RANGE=256>
50 class CharMap
51 {
52 public:
53  typedef RESTYPE valuetype;
54  enum Constant {nullvalue=nullvalue_};
55 
56 private:
57  RESTYPE ar[ RANGE]; //< the map elements
58 public:
60  CharMap() {for (unsigned int ii=0; ii<RANGE; ii++) ar[ii]=(valuetype)nullvalue;}
65  CharMap& operator()( unsigned char from, unsigned char to, valuetype value) {for (unsigned int ii=from; ii<=to; ii++) ar[ii]=value; return *this;}
69  CharMap& operator()( unsigned char at, valuetype value) {ar[at] = value; return *this;}
73  valuetype operator []( unsigned char ii) const {return ar[ii];}
74 };
75 
79 {
80  Undef=0, //< not defined (beyond ascii)
81  EndOfText, //< end of data (EOF,EOD,.)
82  EndOfLine, //< end of line
83  Cntrl, //< control character
84  Space, //< space, tab, etc..
85  Amp, //< ampersant ('&')
86  Lt, //< lesser than '<'
87  Equal, //< equal '='
88  Gt, //< greater than '>'
89  Slash, //< slash '/'
90  Dash, //< en dash (minus) '-'
91  Exclam, //< exclamation mark '!'
92  Questm, //< question mark '?'
93  Sq, //< single quote
94  Dq, //< double quote
95  Osb, //< open square bracket '['
96  Csb, //< close square bracket ']'
97  Any //< any ascii character with meaning
98 };
99 enum {NofControlCharacter=18}; //< total number of control characters
100 
104 {
107  static const char* name( ControlCharacter c)
108  {
109  static const char* name[ NofControlCharacter] = {"Undef", "EndOfText", "EndOfLine", "Cntrl", "Space", "Amp", "Lt", "Equal", "Gt", "Slash", "Dash", "Exclam", "Questm", "Sq", "Dq", "Osb", "Csb", "Any"};
110  return name[ (unsigned int)(unsigned char)c];
111  }
112 };
113 
114 }//namespace
115 #endif
116 
uint64_t EChar
Definition: char.hpp:38
Definition: char.hpp:94
Definition: char.hpp:80
Definition: char.hpp:91
Definition: char.hpp:86
Map of the enumeration of control characters to their names for debug messages.
Definition: char.hpp:103
RESTYPE valuetype
Definition: char.hpp:53
Definition: char.hpp:95
static const char * name(ControlCharacter c)
Get the name of a control character as string.
Definition: char.hpp:107
Definition: char.hpp:92
Definition: char.hpp:89
CharMap & operator()(unsigned char from, unsigned char to, valuetype value)
Define the values of the elements in the interval [from,to].
Definition: char.hpp:65
uint32_t UChar
Unicode character type.
Definition: char.hpp:37
Definition: char.hpp:82
Definition: char.hpp:93
Definition: char.hpp:84
Definition: char.hpp:85
Definition: char.hpp:96
Definition: char.hpp:97
Definition: char.hpp:88
Definition: char.hpp:81
Definition: char.hpp:54
ControlCharacter
Enumeration of control characters needed as events for XML scanner statemachine.
Definition: char.hpp:78
CharMap()
Constructor.
Definition: char.hpp:60
Definition: char.hpp:83
CharMap & operator()(unsigned char at, valuetype value)
Define the values of the single element at 'at'.
Definition: char.hpp:69
Definition: char.hpp:90
Character map for fast typing of a character byte.
Definition: char.hpp:50
Definition: char.hpp:87
valuetype operator[](unsigned char ii) const
Read the element assigned to 'ii'.
Definition: char.hpp:73
Definition: char.hpp:99