src
Public Types | Public Member Functions | Static Public Member Functions | List of all members
re2c::Enc Class Reference

#include <enc.h>

Public Types

enum  type_t {
  ASCII, EBCDIC, UCS2, UTF16,
  UTF32, UTF8
}
 
enum  policy_t { POLICY_FAIL, POLICY_SUBSTITUTE, POLICY_IGNORE }
 

Public Member Functions

 Enc ()
 
bool operator!= (const Enc &e) const
 
uint32_t nCodePoints () const
 
uint32_t nCodeUnits () const
 
uint32_t szCodePoint () const
 
uint32_t szCodeUnit () const
 
bool set (type_t t)
 
void unset (type_t)
 
type_t type () const
 
void setPolicy (policy_t t)
 
bool encode (uint32_t &c) const
 
uint32_t decodeUnsafe (uint32_t c) const
 
RangeencodeRange (uint32_t l, uint32_t h) const
 
RangefullRange () const
 

Static Public Member Functions

static const char * name (type_t t)
 

Detailed Description

Definition at line 38 of file enc.h.

Member Enumeration Documentation

Enumerator
POLICY_FAIL 
POLICY_SUBSTITUTE 
POLICY_IGNORE 

Definition at line 52 of file enc.h.

Enumerator
ASCII 
EBCDIC 
UCS2 
UTF16 
UTF32 
UTF8 

Definition at line 42 of file enc.h.

43  { ASCII
44  , EBCDIC
45  , UCS2
46  , UTF16
47  , UTF32
48  , UTF8
49  };

Constructor & Destructor Documentation

re2c::Enc::Enc ( )
inline

Definition at line 69 of file enc.h.

70  : type_ (ASCII)
71  , policy_ (POLICY_IGNORE)
72  { }

Member Function Documentation

uint32_t re2c::Enc::decodeUnsafe ( uint32_t  c) const

Definition at line 103 of file enc.cc.

104 {
105  switch (type_)
106  {
107  case EBCDIC:
108  c = ebc2asc[c & 0xFF];
109  break;
110  case ASCII:
111  case UCS2:
112  case UTF16:
113  case UTF32:
114  case UTF8:
115  break;
116  }
117  return c;
118 }

Here is the caller graph for this function:

bool re2c::Enc::encode ( uint32_t &  c) const

Definition at line 62 of file enc.cc.

63 {
64  if (c >= nCodePoints ())
65  {
66  return false;
67  }
68 
69  switch (type_)
70  {
71  case ASCII:
72  return true;
73  case EBCDIC:
74  c = asc2ebc[c];
75  return true;
76  case UCS2:
77  case UTF16:
78  case UTF32:
79  case UTF8:
80  if (c < SURR_MIN || c > SURR_MAX)
81  return true;
82  else
83  {
84  switch (policy_)
85  {
86  case POLICY_FAIL:
87  return false;
88  case POLICY_SUBSTITUTE:
89  c = UNICODE_ERROR;
90  return true;
91  case POLICY_IGNORE:
92  return true;
93  }
94  }
95  }
96  return false; // to silence gcc warning
97 }
uint32_t nCodePoints() const
Definition: enc.h:109

Here is the call graph for this function:

Here is the caller graph for this function:

Range * re2c::Enc::encodeRange ( uint32_t  l,
uint32_t  h 
) const

Definition at line 132 of file enc.cc.

133 {
134  if (l >= nCodePoints () || h >= nCodePoints ())
135  {
136  return NULL;
137  }
138 
139  Range * r = NULL;
140  switch (type_)
141  {
142  case ASCII:
143  r = Range::ran (l, h + 1);
144  break;
145  case EBCDIC:
146  {
147  const uint32_t el = asc2ebc[l];
148  r = Range::sym (el);
149  for (uint32_t c = l + 1; c <= h; ++c)
150  {
151  const uint32_t ec = asc2ebc[c];
152  r = Range::add (r, Range::sym (ec));
153  }
154  break;
155  }
156  case UCS2:
157  case UTF16:
158  case UTF32:
159  case UTF8:
160  r = Range::ran (l, h + 1);
161  if (l <= SURR_MAX && h >= SURR_MIN)
162  {
163  switch (policy_)
164  {
165  case POLICY_FAIL:
166  r = NULL;
167  break;
168  case POLICY_SUBSTITUTE:
169  {
170  Range * surrs = Range::ran (SURR_MIN, SURR_MAX + 1);
171  Range * error = Range::sym (UNICODE_ERROR);
172  r = Range::sub (r, surrs);
173  r = Range::add (r, error);
174  break;
175  }
176  case POLICY_IGNORE:
177  break;
178  }
179  }
180  break;
181  }
182  return r;
183 }
static Range * sub(const Range *r1, const Range *r2)
Definition: range.cc:61
static Range * ran(uint32_t l, uint32_t u)
Definition: range.h:31
void error(const char *fmt,...)
Definition: msg.cc:10
static Range * sym(uint32_t c)
Definition: range.h:27
uint32_t nCodePoints() const
Definition: enc.h:109
static Range * add(const Range *r1, const Range *r2)
Definition: range.cc:26

Here is the call graph for this function:

Range * re2c::Enc::fullRange ( ) const

Definition at line 195 of file enc.cc.

196 {
197  Range * r = Range::ran (0, nCodePoints());
198  if (policy_ != POLICY_IGNORE)
199  {
200  Range * surrs = Range::ran (SURR_MIN, SURR_MAX + 1);
201  r = Range::sub (r, surrs);
202  }
203  return r;
204 }
static Range * sub(const Range *r1, const Range *r2)
Definition: range.cc:61
static Range * ran(uint32_t l, uint32_t u)
Definition: range.h:31
uint32_t nCodePoints() const
Definition: enc.h:109

Here is the call graph for this function:

Here is the caller graph for this function:

const char * re2c::Enc::name ( type_t  t)
inlinestatic

Definition at line 95 of file enc.h.

96 {
97  switch (t)
98  {
99  case ASCII: return "ASCII";
100  case EBCDIC: return "EBCDIC";
101  case UTF8: return "UTF8";
102  case UCS2: return "USC2";
103  case UTF16: return "UTF16";
104  case UTF32: return "UTF32";
105  default: return "<bad encoding>";
106  }
107 }
uint32_t re2c::Enc::nCodePoints ( ) const
inline

Definition at line 109 of file enc.h.

110 {
111  switch (type_)
112  {
113  case ASCII:
114  case EBCDIC: return 0x100;
115  case UCS2: return 0x10000;
116  case UTF16:
117  case UTF32:
118  case UTF8:
119  default: return 0x110000;
120  }
121 }

Here is the caller graph for this function:

uint32_t re2c::Enc::nCodeUnits ( ) const
inline

Definition at line 123 of file enc.h.

124 {
125  switch (type_)
126  {
127  case ASCII:
128  case EBCDIC:
129  case UTF8: return 0x100;
130  case UCS2:
131  case UTF16: return 0x10000;
132  case UTF32:
133  default: return 0x110000;
134  }
135 }

Here is the caller graph for this function:

bool re2c::Enc::operator!= ( const Enc e) const
inline

Definition at line 76 of file enc.h.

76 { return type_ != e.type_; }
bool re2c::Enc::set ( type_t  t)
inline

Definition at line 166 of file enc.h.

167 {
168  if (type_ == t)
169  return true;
170  else if (type_ != ASCII)
171  return false;
172  else
173  {
174  type_ = t;
175  return true;
176  }
177 }

Here is the caller graph for this function:

void re2c::Enc::setPolicy ( policy_t  t)
inline

Definition at line 190 of file enc.h.

191 {
192  policy_ = t;
193 }

Here is the caller graph for this function:

uint32_t re2c::Enc::szCodePoint ( ) const
inline

Definition at line 138 of file enc.h.

139 {
140  switch (type_)
141  {
142  case ASCII:
143  case EBCDIC: return 1;
144  case UCS2: return 2;
145  case UTF16:
146  case UTF32:
147  case UTF8:
148  default: return 4;
149  }
150 }
uint32_t re2c::Enc::szCodeUnit ( ) const
inline

Definition at line 152 of file enc.h.

153 {
154  switch (type_)
155  {
156  case ASCII:
157  case EBCDIC:
158  case UTF8: return 1;
159  case UCS2:
160  case UTF16: return 2;
161  case UTF32:
162  default: return 4;
163  }
164 }

Here is the caller graph for this function:

Enc::type_t re2c::Enc::type ( ) const
inline

Definition at line 185 of file enc.h.

186 {
187  return type_;
188 }

Here is the caller graph for this function:

void re2c::Enc::unset ( type_t  t)
inline

Definition at line 179 of file enc.h.

180 {
181  if (type_ == t)
182  type_ = ASCII;
183 }

Here is the caller graph for this function:


The documentation for this class was generated from the following files: