The SWORD Project  1.9.0.svnversion
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
UTF16UTF8 Class Reference

#include <utf16utf8.h>

+ Inheritance diagram for UTF16UTF8:
+ Collaboration diagram for UTF16UTF8:

Public Member Functions

virtual const char * getHeader () const
 
virtual char processText (SWBuf &text, const SWKey *key=0, const SWModule *module=0)
 
 UTF16UTF8 ()
 

Detailed Description

This filter converts UTF-16 encoded text to UTF-8

Definition at line 33 of file utf16utf8.h.

Constructor & Destructor Documentation

SWORD_NAMESPACE_START UTF16UTF8::UTF16UTF8 ( )

Definition at line 31 of file utf16utf8.cpp.

31  {
32 }

Member Function Documentation

virtual const char* SWFilter::getHeader ( ) const
inlinevirtualinherited

This method can supply a header associated with the processing done with this filter. A typical example is a suggested CSS style block for classed containers.

Reimplemented in OSISLaTeX, OSISXHTML, ThMLLaTeX, ThMLXHTML, TEIXHTML, GBFLaTeX, and GBFXHTML.

Definition at line 62 of file swfilter.h.

62 { return ""; }
char UTF16UTF8::processText ( SWBuf text,
const SWKey key = 0,
const SWModule module = 0 
)
virtual

This method processes and appropriately modifies the text given it for a particular filter task

Parameters
textThe text to be filtered/converted
keyCurrent key That was used.
moduleCurrent module.
Returns
0

Implements SWFilter.

Definition at line 35 of file utf16utf8.cpp.

36 {
37  unsigned short *from;
38 
39  int len;
40  unsigned long uchar;
41  unsigned short schar;
42  len = 0;
43  from = (unsigned short*) text.c_str();
44  while (*from) {
45  len += 2;
46  from++;
47  }
48 
49  SWBuf orig = text;
50  from = (unsigned short*)orig.c_str();
51 
52 
53  // -------------------------------
54 
55  for (text = ""; *from; from++) {
56  uchar = 0;
57 
58  if (*from < 0xD800 || *from > 0xDFFF) {
59  uchar = *from;
60  }
61  else if (*from >= 0xD800 && *from <= 0xDBFF) {
62  uchar = *from;
63  schar = *(from+1);
64  if (uchar < 0xDC00 || uchar > 0xDFFF) {
65  //error, do nothing
66  continue;
67  }
68  uchar &= 0x03ff;
69  schar &= 0x03ff;
70  uchar <<= 10;
71  uchar |= schar;
72  uchar += 0x10000;
73  from++;
74  }
75  else {
76  //error, do nothing
77  continue;
78  }
79 
80  if (uchar < 0x80) {
81  text += uchar;
82  }
83  else if (uchar < 0x800) {
84  text += 0xc0 | (uchar >> 6);
85  text += 0x80 | (uchar & 0x3f);
86  }
87  else if (uchar < 0x10000) {
88  text += 0xe0 | (uchar >> 12);
89  text += 0x80 | ((uchar >> 6) & 0x3f);
90  text += 0x80 | (uchar & 0x3f);
91  }
92  else if (uchar < 0x200000) {
93  text += 0xF0 | (uchar >> 18);
94  text += 0x80 | ((uchar >> 12) & 0x3F);
95  text += 0x80 | ((uchar >> 6) & 0x3F);
96  text += 0x80 | (uchar & 0x3F);
97  }
98  }
99 
100  return 0;
101 }
Definition: swbuf.h:47
const char * c_str() const
Definition: swbuf.h:158

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