webkit  2cdf99a9e3038c7e01b3c37e8ad903ecbe5eecf1
https://github.com/WebKit/webkit
encodings.h
Go to the documentation of this file.
1 // Copyright (C) 2011 Milo Yip
2 //
3 // Permission is hereby granted, free of charge, to any person obtaining a copy
4 // of this software and associated documentation files (the "Software"), to deal
5 // in the Software without restriction, including without limitation the rights
6 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7 // copies of the Software, and to permit persons to whom the Software is
8 // furnished to do so, subject to the following conditions:
9 //
10 // The above copyright notice and this permission notice shall be included in
11 // all copies or substantial portions of the Software.
12 //
13 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19 // THE SOFTWARE.
20 
21 #ifndef RAPIDJSON_ENCODINGS_H_
22 #define RAPIDJSON_ENCODINGS_H_
23 
24 #include "rapidjson.h"
25 
26 #ifdef _MSC_VER
27 RAPIDJSON_DIAG_PUSH
28 RAPIDJSON_DIAG_OFF(4244) // conversion from 'type1' to 'type2', possible loss of data
29 RAPIDJSON_DIAG_OFF(4702) // unreachable code
30 #elif defined(__GNUC__)
31 RAPIDJSON_DIAG_PUSH
32 RAPIDJSON_DIAG_OFF(effc++)
33 #endif
34 
36 
38 // Encoding
39 
52 
59 
67 
73 
77 
81 
85 
91 // UTF8
93 
95 
100 template<typename CharType = char>
101 struct UTF8 {
102  typedef CharType Ch;
103 
104  enum { supportUnicode = 1 };
105 
106  template<typename OutputStream>
107  static void Encode(OutputStream& os, unsigned codepoint) {
108  if (codepoint <= 0x7F)
109  os.Put(static_cast<Ch>(codepoint & 0xFF));
110  else if (codepoint <= 0x7FF) {
111  os.Put(static_cast<Ch>(0xC0 | ((codepoint >> 6) & 0xFF)));
112  os.Put(static_cast<Ch>(0x80 | ((codepoint & 0x3F))));
113  }
114  else if (codepoint <= 0xFFFF) {
115  os.Put(static_cast<Ch>(0xE0 | ((codepoint >> 12) & 0xFF)));
116  os.Put(static_cast<Ch>(0x80 | ((codepoint >> 6) & 0x3F)));
117  os.Put(static_cast<Ch>(0x80 | (codepoint & 0x3F)));
118  }
119  else {
120  RAPIDJSON_ASSERT(codepoint <= 0x10FFFF);
121  os.Put(static_cast<Ch>(0xF0 | ((codepoint >> 18) & 0xFF)));
122  os.Put(static_cast<Ch>(0x80 | ((codepoint >> 12) & 0x3F)));
123  os.Put(static_cast<Ch>(0x80 | ((codepoint >> 6) & 0x3F)));
124  os.Put(static_cast<Ch>(0x80 | (codepoint & 0x3F)));
125  }
126  }
127 
128  template <typename InputStream>
129  static bool Decode(InputStream& is, unsigned* codepoint) {
130 #define COPY() c = is.Take(); *codepoint = (*codepoint << 6) | ((unsigned char)c & 0x3Fu)
131 #define TRANS(mask) result &= ((GetRange((unsigned char)c) & mask) != 0)
132 #define TAIL() COPY(); TRANS(0x70)
133  Ch c = is.Take();
134  if (!(c & 0x80)) {
135  *codepoint = (unsigned char)c;
136  return true;
137  }
138 
139  unsigned char type = GetRange((unsigned char)c);
140  *codepoint = (0xFF >> type) & (unsigned char)c;
141  bool result = true;
142  switch (type) {
143  case 2: TAIL(); return result;
144  case 3: TAIL(); TAIL(); return result;
145  case 4: COPY(); TRANS(0x50); TAIL(); return result;
146  case 5: COPY(); TRANS(0x10); TAIL(); TAIL(); return result;
147  case 6: TAIL(); TAIL(); TAIL(); return result;
148  case 10: COPY(); TRANS(0x20); TAIL(); return result;
149  case 11: COPY(); TRANS(0x60); TAIL(); TAIL(); return result;
150  default: return false;
151  }
152 #undef COPY
153 #undef TRANS
154 #undef TAIL
155  }
156 
157  template <typename InputStream, typename OutputStream>
158  static bool Validate(InputStream& is, OutputStream& os) {
159 #define COPY() os.Put(c = is.Take())
160 #define TRANS(mask) result &= ((GetRange((unsigned char)c) & mask) != 0)
161 #define TAIL() COPY(); TRANS(0x70)
162  Ch c;
163  COPY();
164  if (!(c & 0x80))
165  return true;
166 
167  bool result = true;
168  switch (GetRange((unsigned char)c)) {
169  case 2: TAIL(); return result;
170  case 3: TAIL(); TAIL(); return result;
171  case 4: COPY(); TRANS(0x50); TAIL(); return result;
172  case 5: COPY(); TRANS(0x10); TAIL(); TAIL(); return result;
173  case 6: TAIL(); TAIL(); TAIL(); return result;
174  case 10: COPY(); TRANS(0x20); TAIL(); return result;
175  case 11: COPY(); TRANS(0x60); TAIL(); TAIL(); return result;
176  default: return false;
177  }
178 #undef COPY
179 #undef TRANS
180 #undef TAIL
181  }
182 
183  static unsigned char GetRange(unsigned char c) {
184  // Referring to DFA of http://bjoern.hoehrmann.de/utf-8/decoder/dfa/
185  // With new mapping 1 -> 0x10, 7 -> 0x20, 9 -> 0x40, such that AND operation can test multiple types.
186  static const unsigned char type[] = {
187  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
188  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
189  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
190  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
191  0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,
192  0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,
193  0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
194  0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
195  8,8,2,2,2,2,2,2,2,2,2,2,2,2,2,2, 2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,
196  10,3,3,3,3,3,3,3,3,3,3,3,3,4,3,3, 11,6,6,6,5,8,8,8,8,8,8,8,8,8,8,8,
197  };
198  return type[c];
199  }
200 
201  template <typename InputByteStream>
202  static CharType TakeBOM(InputByteStream& is) {
203  RAPIDJSON_STATIC_ASSERT(sizeof(typename InputByteStream::Ch) == 1);
204  Ch c = Take(is);
205  if ((unsigned char)c != 0xEFu) return c;
206  c = is.Take();
207  if ((unsigned char)c != 0xBBu) return c;
208  c = is.Take();
209  if ((unsigned char)c != 0xBFu) return c;
210  c = is.Take();
211  return c;
212  }
213 
214  template <typename InputByteStream>
215  static Ch Take(InputByteStream& is) {
216  RAPIDJSON_STATIC_ASSERT(sizeof(typename InputByteStream::Ch) == 1);
217  return is.Take();
218  }
219 
220  template <typename OutputByteStream>
221  static void PutBOM(OutputByteStream& os) {
222  RAPIDJSON_STATIC_ASSERT(sizeof(typename OutputByteStream::Ch) == 1);
223  os.Put(0xEFu); os.Put(0xBBu); os.Put(0xBFu);
224  }
225 
226  template <typename OutputByteStream>
227  static void Put(OutputByteStream& os, Ch c) {
228  RAPIDJSON_STATIC_ASSERT(sizeof(typename OutputByteStream::Ch) == 1);
229  os.Put(static_cast<typename OutputByteStream::Ch>(c));
230  }
231 };
232 
234 // UTF16
235 
237 
245 template<typename CharType = wchar_t>
246 struct UTF16 {
247  typedef CharType Ch;
248  RAPIDJSON_STATIC_ASSERT(sizeof(Ch) >= 2);
249 
250  enum { supportUnicode = 1 };
251 
252  template<typename OutputStream>
253  static void Encode(OutputStream& os, unsigned codepoint) {
254  RAPIDJSON_STATIC_ASSERT(sizeof(typename OutputStream::Ch) >= 2);
255  if (codepoint <= 0xFFFF) {
256  RAPIDJSON_ASSERT(codepoint < 0xD800 || codepoint > 0xDFFF); // Code point itself cannot be surrogate pair
257  os.Put(static_cast<typename OutputStream::Ch>(codepoint));
258  }
259  else {
260  RAPIDJSON_ASSERT(codepoint <= 0x10FFFF);
261  unsigned v = codepoint - 0x10000;
262  os.Put(static_cast<typename OutputStream::Ch>((v >> 10) | 0xD800));
263  os.Put((v & 0x3FF) | 0xDC00);
264  }
265  }
266 
267  template <typename InputStream>
268  static bool Decode(InputStream& is, unsigned* codepoint) {
269  RAPIDJSON_STATIC_ASSERT(sizeof(typename InputStream::Ch) >= 2);
270  Ch c = is.Take();
271  if (c < 0xD800 || c > 0xDFFF) {
272  *codepoint = c;
273  return true;
274  }
275  else if (c <= 0xDBFF) {
276  *codepoint = (c & 0x3FF) << 10;
277  c = is.Take();
278  *codepoint |= (c & 0x3FF);
279  *codepoint += 0x10000;
280  return c >= 0xDC00 && c <= 0xDFFF;
281  }
282  return false;
283  }
284 
285  template <typename InputStream, typename OutputStream>
286  static bool Validate(InputStream& is, OutputStream& os) {
287  RAPIDJSON_STATIC_ASSERT(sizeof(typename InputStream::Ch) >= 2);
288  RAPIDJSON_STATIC_ASSERT(sizeof(typename OutputStream::Ch) >= 2);
289  Ch c;
290  os.Put(c = is.Take());
291  if (c < 0xD800 || c > 0xDFFF)
292  return true;
293  else if (c <= 0xDBFF) {
294  os.Put(c = is.Take());
295  return c >= 0xDC00 && c <= 0xDFFF;
296  }
297  return false;
298  }
299 };
300 
302 template<typename CharType = wchar_t>
303 struct UTF16LE : UTF16<CharType> {
304  template <typename InputByteStream>
305  static CharType TakeBOM(InputByteStream& is) {
306  RAPIDJSON_STATIC_ASSERT(sizeof(typename InputByteStream::Ch) == 1);
307  CharType c = Take(is);
308  return (unsigned short)c == 0xFEFFu ? Take(is) : c;
309  }
310 
311  template <typename InputByteStream>
312  static CharType Take(InputByteStream& is) {
313  RAPIDJSON_STATIC_ASSERT(sizeof(typename InputByteStream::Ch) == 1);
314  CharType c = (unsigned char)is.Take();
315  c |= (unsigned char)is.Take() << 8;
316  return c;
317  }
318 
319  template <typename OutputByteStream>
320  static void PutBOM(OutputByteStream& os) {
321  RAPIDJSON_STATIC_ASSERT(sizeof(typename OutputByteStream::Ch) == 1);
322  os.Put(0xFFu); os.Put(0xFEu);
323  }
324 
325  template <typename OutputByteStream>
326  static void Put(OutputByteStream& os, CharType c) {
327  RAPIDJSON_STATIC_ASSERT(sizeof(typename OutputByteStream::Ch) == 1);
328  os.Put(c & 0xFFu);
329  os.Put((c >> 8) & 0xFFu);
330  }
331 };
332 
334 template<typename CharType = wchar_t>
335 struct UTF16BE : UTF16<CharType> {
336  template <typename InputByteStream>
337  static CharType TakeBOM(InputByteStream& is) {
338  RAPIDJSON_STATIC_ASSERT(sizeof(typename InputByteStream::Ch) == 1);
339  CharType c = Take(is);
340  return (unsigned short)c == 0xFEFFu ? Take(is) : c;
341  }
342 
343  template <typename InputByteStream>
344  static CharType Take(InputByteStream& is) {
345  RAPIDJSON_STATIC_ASSERT(sizeof(typename InputByteStream::Ch) == 1);
346  CharType c = (unsigned char)is.Take() << 8;
347  c |= (unsigned char)is.Take();
348  return c;
349  }
350 
351  template <typename OutputByteStream>
352  static void PutBOM(OutputByteStream& os) {
353  RAPIDJSON_STATIC_ASSERT(sizeof(typename OutputByteStream::Ch) == 1);
354  os.Put(0xFEu); os.Put(0xFFu);
355  }
356 
357  template <typename OutputByteStream>
358  static void Put(OutputByteStream& os, CharType c) {
359  RAPIDJSON_STATIC_ASSERT(sizeof(typename OutputByteStream::Ch) == 1);
360  os.Put((c >> 8) & 0xFFu);
361  os.Put(c & 0xFFu);
362  }
363 };
364 
366 // UTF32
367 
369 
376 template<typename CharType = unsigned>
377 struct UTF32 {
378  typedef CharType Ch;
379  RAPIDJSON_STATIC_ASSERT(sizeof(Ch) >= 4);
380 
381  enum { supportUnicode = 1 };
382 
383  template<typename OutputStream>
384  static void Encode(OutputStream& os, unsigned codepoint) {
385  RAPIDJSON_STATIC_ASSERT(sizeof(typename OutputStream::Ch) >= 4);
386  RAPIDJSON_ASSERT(codepoint <= 0x10FFFF);
387  os.Put(codepoint);
388  }
389 
390  template <typename InputStream>
391  static bool Decode(InputStream& is, unsigned* codepoint) {
392  RAPIDJSON_STATIC_ASSERT(sizeof(typename InputStream::Ch) >= 4);
393  Ch c = is.Take();
394  *codepoint = c;
395  return c <= 0x10FFFF;
396  }
397 
398  template <typename InputStream, typename OutputStream>
399  static bool Validate(InputStream& is, OutputStream& os) {
400  RAPIDJSON_STATIC_ASSERT(sizeof(typename InputStream::Ch) >= 4);
401  Ch c;
402  os.Put(c = is.Take());
403  return c <= 0x10FFFF;
404  }
405 };
406 
408 template<typename CharType = unsigned>
409 struct UTF32LE : UTF32<CharType> {
410  template <typename InputByteStream>
411  static CharType TakeBOM(InputByteStream& is) {
412  RAPIDJSON_STATIC_ASSERT(sizeof(typename InputByteStream::Ch) == 1);
413  CharType c = Take(is);
414  return (unsigned)c == 0x0000FEFFu ? Take(is) : c;
415  }
416 
417  template <typename InputByteStream>
418  static CharType Take(InputByteStream& is) {
419  RAPIDJSON_STATIC_ASSERT(sizeof(typename InputByteStream::Ch) == 1);
420  CharType c = (unsigned char)is.Take();
421  c |= (unsigned char)is.Take() << 8;
422  c |= (unsigned char)is.Take() << 16;
423  c |= (unsigned char)is.Take() << 24;
424  return c;
425  }
426 
427  template <typename OutputByteStream>
428  static void PutBOM(OutputByteStream& os) {
429  RAPIDJSON_STATIC_ASSERT(sizeof(typename OutputByteStream::Ch) == 1);
430  os.Put(0xFFu); os.Put(0xFEu); os.Put(0x00u); os.Put(0x00u);
431  }
432 
433  template <typename OutputByteStream>
434  static void Put(OutputByteStream& os, CharType c) {
435  RAPIDJSON_STATIC_ASSERT(sizeof(typename OutputByteStream::Ch) == 1);
436  os.Put(c & 0xFFu);
437  os.Put((c >> 8) & 0xFFu);
438  os.Put((c >> 16) & 0xFFu);
439  os.Put((c >> 24) & 0xFFu);
440  }
441 };
442 
444 template<typename CharType = unsigned>
445 struct UTF32BE : UTF32<CharType> {
446  template <typename InputByteStream>
447  static CharType TakeBOM(InputByteStream& is) {
448  RAPIDJSON_STATIC_ASSERT(sizeof(typename InputByteStream::Ch) == 1);
449  CharType c = Take(is);
450  return (unsigned)c == 0x0000FEFFu ? Take(is) : c;
451  }
452 
453  template <typename InputByteStream>
454  static CharType Take(InputByteStream& is) {
455  RAPIDJSON_STATIC_ASSERT(sizeof(typename InputByteStream::Ch) == 1);
456  CharType c = (unsigned char)is.Take() << 24;
457  c |= (unsigned char)is.Take() << 16;
458  c |= (unsigned char)is.Take() << 8;
459  c |= (unsigned char)is.Take();
460  return c;
461  }
462 
463  template <typename OutputByteStream>
464  static void PutBOM(OutputByteStream& os) {
465  RAPIDJSON_STATIC_ASSERT(sizeof(typename OutputByteStream::Ch) == 1);
466  os.Put(0x00u); os.Put(0x00u); os.Put(0xFEu); os.Put(0xFFu);
467  }
468 
469  template <typename OutputByteStream>
470  static void Put(OutputByteStream& os, CharType c) {
471  RAPIDJSON_STATIC_ASSERT(sizeof(typename OutputByteStream::Ch) == 1);
472  os.Put((c >> 24) & 0xFFu);
473  os.Put((c >> 16) & 0xFFu);
474  os.Put((c >> 8) & 0xFFu);
475  os.Put(c & 0xFFu);
476  }
477 };
478 
480 // ASCII
481 
483 
487 template<typename CharType = char>
488 struct ASCII {
489  typedef CharType Ch;
490 
491  enum { supportUnicode = 0 };
492 
493  template<typename OutputStream>
494  static void Encode(OutputStream& os, unsigned codepoint) {
495  RAPIDJSON_ASSERT(codepoint <= 0x7F);
496  os.Put(static_cast<Ch>(codepoint & 0xFF));
497  }
498 
499  template <typename InputStream>
500  static bool Decode(InputStream& is, unsigned* codepoint) {
501  unsigned char c = static_cast<unsigned char>(is.Take());
502  *codepoint = c;
503  return c <= 0X7F;
504  }
505 
506  template <typename InputStream, typename OutputStream>
507  static bool Validate(InputStream& is, OutputStream& os) {
508  unsigned char c = is.Take();
509  os.Put(c);
510  return c <= 0x7F;
511  }
512 
513  template <typename InputByteStream>
514  static CharType TakeBOM(InputByteStream& is) {
515  RAPIDJSON_STATIC_ASSERT(sizeof(typename InputByteStream::Ch) == 1);
516  Ch c = Take(is);
517  return c;
518  }
519 
520  template <typename InputByteStream>
521  static Ch Take(InputByteStream& is) {
522  RAPIDJSON_STATIC_ASSERT(sizeof(typename InputByteStream::Ch) == 1);
523  return is.Take();
524  }
525 
526  template <typename OutputByteStream>
527  static void PutBOM(OutputByteStream& os) {
528  RAPIDJSON_STATIC_ASSERT(sizeof(typename OutputByteStream::Ch) == 1);
529  (void)os;
530  }
531 
532  template <typename OutputByteStream>
533  static void Put(OutputByteStream& os, Ch c) {
534  RAPIDJSON_STATIC_ASSERT(sizeof(typename OutputByteStream::Ch) == 1);
535  os.Put(static_cast<typename OutputByteStream::Ch>(c));
536  }
537 };
538 
540 // AutoUTF
541 
543 enum UTFType {
544  kUTF8 = 0,
545  kUTF16LE = 1,
546  kUTF16BE = 2,
547  kUTF32LE = 3,
548  kUTF32BE = 4
549 };
550 
552 
554 template<typename CharType>
555 struct AutoUTF {
556  typedef CharType Ch;
557 
558  enum { supportUnicode = 1 };
559 
560 #define RAPIDJSON_ENCODINGS_FUNC(x) UTF8<Ch>::x, UTF16LE<Ch>::x, UTF16BE<Ch>::x, UTF32LE<Ch>::x, UTF32BE<Ch>::x
561 
562  template<typename OutputStream>
563  RAPIDJSON_FORCEINLINE static void Encode(OutputStream& os, unsigned codepoint) {
564  typedef void (*EncodeFunc)(OutputStream&, unsigned);
565  static const EncodeFunc f[] = { RAPIDJSON_ENCODINGS_FUNC(Encode) };
566  (*f[os.GetType()])(os, codepoint);
567  }
568 
569  template <typename InputStream>
570  RAPIDJSON_FORCEINLINE static bool Decode(InputStream& is, unsigned* codepoint) {
571  typedef bool (*DecodeFunc)(InputStream&, unsigned*);
572  static const DecodeFunc f[] = { RAPIDJSON_ENCODINGS_FUNC(Decode) };
573  return (*f[is.GetType()])(is, codepoint);
574  }
575 
576  template <typename InputStream, typename OutputStream>
577  RAPIDJSON_FORCEINLINE static bool Validate(InputStream& is, OutputStream& os) {
578  typedef bool (*ValidateFunc)(InputStream&, OutputStream&);
579  static const ValidateFunc f[] = { RAPIDJSON_ENCODINGS_FUNC(Validate) };
580  return (*f[is.GetType()])(is, os);
581  }
582 
583 #undef RAPIDJSON_ENCODINGS_FUNC
584 };
585 
587 // Transcoder
588 
590 template<typename SourceEncoding, typename TargetEncoding>
591 struct Transcoder {
593  template<typename InputStream, typename OutputStream>
594  RAPIDJSON_FORCEINLINE static bool Transcode(InputStream& is, OutputStream& os) {
595  unsigned codepoint;
596  if (!SourceEncoding::Decode(is, &codepoint))
597  return false;
598  TargetEncoding::Encode(os, codepoint);
599  return true;
600  }
601 
603  template<typename InputStream, typename OutputStream>
604  RAPIDJSON_FORCEINLINE static bool Validate(InputStream& is, OutputStream& os) {
605  return Transcode(is, os); // Since source/target encoding is different, must transcode.
606  }
607 };
608 
610 template<typename Encoding>
611 struct Transcoder<Encoding, Encoding> {
612  template<typename InputStream, typename OutputStream>
613  RAPIDJSON_FORCEINLINE static bool Transcode(InputStream& is, OutputStream& os) {
614  os.Put(is.Take()); // Just copy one code unit. This semantic is different from primary template class.
615  return true;
616  }
617 
618  template<typename InputStream, typename OutputStream>
619  RAPIDJSON_FORCEINLINE static bool Validate(InputStream& is, OutputStream& os) {
620  return Encoding::Validate(is, os); // source/target encoding are the same
621  }
622 };
623 
625 
626 #if defined(__GNUC__) || defined(_MSV_VER)
627 RAPIDJSON_DIAG_POP
628 #endif
629 
630 #endif // RAPIDJSON_ENCODINGS_H_
CharType Ch
Definition: encodings.h:102
static void Put(OutputByteStream &os, Ch c)
Definition: encodings.h:533
#define COPY()
#define TAIL()
static void Encode(OutputStream &os, unsigned codepoint)
Definition: encodings.h:253
static void Encode(OutputStream &os, unsigned codepoint)
Definition: encodings.h:494
static bool Decode(InputStream &is, unsigned *codepoint)
Definition: encodings.h:129
UTFType
Runtime-specified UTF encoding type of a stream.
Definition: encodings.h:543
static Ch Take(InputByteStream &is)
Definition: encodings.h:215
static bool Validate(InputStream &is, OutputStream &os)
Definition: encodings.h:286
int c
Definition: cpp_unittests.cpp:275
static unsigned char GetRange(unsigned char c)
Definition: encodings.h:183
static void PutBOM(OutputByteStream &os)
Definition: encodings.h:527
static bool Validate(InputStream &is, OutputStream &os)
Definition: encodings.h:399
static void PutBOM(OutputByteStream &os)
Definition: encodings.h:221
OPENSSL_EXPORT pem_password_cb void * u
Definition: pem.h:398
#define Ch(x, y, z)
Definition: sha256.c:217
UTF-32 big endian.
Definition: encodings.h:548
UTF-16 little endian.
Definition: encodings.h:545
static CharType TakeBOM(InputByteStream &is)
Definition: encodings.h:411
UTF-8.
Definition: encodings.h:544
static CharType Take(InputByteStream &is)
Definition: encodings.h:454
#define RAPIDJSON_STATIC_ASSERT(x)
(Internal) macro to check for conditions at compile-time
Definition: rapidjson.h:346
static void Put(OutputByteStream &os, CharType c)
Definition: encodings.h:434
static Ch Take(InputByteStream &is)
Definition: encodings.h:521
static CharType TakeBOM(InputByteStream &is)
Definition: encodings.h:305
#define RAPIDJSON_NAMESPACE_BEGIN
provide custom rapidjson namespace (opening expression)
Definition: rapidjson.h:91
static bool Validate(InputStream &is, OutputStream &os)
Definition: encodings.h:158
UTF-16 big endian.
Definition: encodings.h:546
static CharType TakeBOM(InputByteStream &is)
Definition: encodings.h:447
static void PutBOM(OutputByteStream &os)
Definition: encodings.h:352
static CharType Take(InputByteStream &is)
Definition: encodings.h:418
Encoding conversion.
Definition: encodings.h:591
#define RAPIDJSON_ENCODINGS_FUNC(x)
Definition: encodings.h:560
static CharType TakeBOM(InputByteStream &is)
Definition: encodings.h:514
Definition: encodings.h:104
CharType Ch
Definition: encodings.h:556
static void Encode(OutputStream &os, unsigned codepoint)
Definition: encodings.h:107
void
Definition: AVFoundationCFSoftLinking.h:81
#define TRANS(mask)
Dynamically select encoding according to stream&#39;s runtime-specified UTF encoding type.
Definition: encodings.h:555
static void Encode(OutputStream &os, unsigned codepoint)
Definition: encodings.h:384
static RAPIDJSON_FORCEINLINE void Encode(OutputStream &os, unsigned codepoint)
Definition: encodings.h:563
static CharType Take(InputByteStream &is)
Definition: encodings.h:344
ASCII encoding.
Definition: encodings.h:488
static RAPIDJSON_FORCEINLINE bool Validate(InputStream &is, OutputStream &os)
Definition: encodings.h:619
static void PutBOM(OutputByteStream &os)
Definition: encodings.h:428
static void Put(OutputByteStream &os, CharType c)
Definition: encodings.h:358
static CharType TakeBOM(InputByteStream &is)
Definition: encodings.h:337
static void Put(OutputByteStream &os, CharType c)
Definition: encodings.h:326
#define RAPIDJSON_NAMESPACE_END
provide custom rapidjson namespace (closing expression)
Definition: rapidjson.h:94
static CharType Take(InputByteStream &is)
Definition: encodings.h:312
CharType Ch
Definition: encodings.h:489
UTF-32 big endian encoding.
Definition: encodings.h:445
GLfloat f
Definition: gl2.h:417
UTF-32 little endian enocoding.
Definition: encodings.h:409
const GLfloat * v
Definition: gl2.h:514
EGLenum type
Definition: eglext.h:63
static void Put(OutputByteStream &os, Ch c)
Definition: encodings.h:227
result
Definition: target-blank-opener-post-window.php:5
static void PutBOM(OutputByteStream &os)
Definition: encodings.h:464
bool is(Ref< ArgType > &source)
Definition: Ref.h:220
UTF-32 encoding.
Definition: encodings.h:377
CharType Ch
Definition: encodings.h:247
static CharType TakeBOM(InputByteStream &is)
Definition: encodings.h:202
common definitions and configuration
static bool Validate(InputStream &is, OutputStream &os)
Definition: encodings.h:507
static RAPIDJSON_FORCEINLINE bool Transcode(InputStream &is, OutputStream &os)
Definition: encodings.h:613
static bool Decode(InputStream &is, unsigned *codepoint)
Definition: encodings.h:500
static void PutBOM(OutputByteStream &os)
Definition: encodings.h:320
static RAPIDJSON_FORCEINLINE bool Decode(InputStream &is, unsigned *codepoint)
Definition: encodings.h:570
UTF-16 encoding.
Definition: encodings.h:246
CharType Ch
Definition: encodings.h:378
UTF-32 little endian.
Definition: encodings.h:547
static RAPIDJSON_FORCEINLINE bool Transcode(InputStream &is, OutputStream &os)
Take one Unicode codepoint from source encoding, convert it to target encoding and put it to the outp...
Definition: encodings.h:594
static bool Decode(InputStream &is, unsigned *codepoint)
Definition: encodings.h:268
static void Put(OutputByteStream &os, CharType c)
Definition: encodings.h:470
UTF-16 big endian encoding.
Definition: encodings.h:335
UTF-16 little endian encoding.
Definition: encodings.h:303
static bool Decode(InputStream &is, unsigned *codepoint)
Definition: encodings.h:391
#define RAPIDJSON_ASSERT(x)
Assertion.
Definition: rapidjson.h:315
static RAPIDJSON_FORCEINLINE bool Validate(InputStream &is, OutputStream &os)
Definition: encodings.h:577
UTF-8 encoding.
Definition: encodings.h:101
static RAPIDJSON_FORCEINLINE bool Validate(InputStream &is, OutputStream &os)
Validate one Unicode codepoint from an encoded stream.
Definition: encodings.h:604