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

#include <utf8utf16.h>

+ Inheritance diagram for UTF8UTF16:
+ Collaboration diagram for UTF8UTF16:

Public Member Functions

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

Detailed Description

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

Definition at line 33 of file utf8utf16.h.

Constructor & Destructor Documentation

SWORD_NAMESPACE_START UTF8UTF16::UTF8UTF16 ( )

Definition at line 32 of file utf8utf16.cpp.

32  {
33 }

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 UTF8UTF16::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 36 of file utf8utf16.cpp.

36  {
37  const unsigned char *from;
38  SWBuf orig = text;
39 
40  from = (const unsigned char *)orig.c_str();
41 
42  // -------------------------------
43  text = "";
44  while (*from) {
45 
46  SW_u32 ch = getUniCharFromUTF8(&from);
47 
48  if (!ch) continue; // invalid char
49 
50  if (ch < 0x10000) {
51  text.setSize(text.size()+2);
52  *((SW_u16 *)(text.getRawData() + (text.size() - 2))) = (SW_u16)ch;
53  }
54  else {
55  SW_u16 utf16;
56  utf16 = (SW_s16)((ch - 0x10000) / 0x400 + 0xD800);
57  text.setSize(text.size()+4);
58  *((SW_u16 *)(text.getRawData() + (text.size() - 4))) = utf16;
59  utf16 = (SW_s16)((ch - 0x10000) % 0x400 + 0xDC00);
60  *((SW_u16 *)(text.getRawData() + (text.size() - 2))) = utf16;
61  }
62  }
63  text.setSize(text.size()+2);
64  *((SW_u16 *)(text.getRawData() + (text.size() - 2))) = (SW_u16)0;
65  text.setSize(text.size()-2);
66 
67  return 0;
68 }
Definition: swbuf.h:47
char * getRawData()
Definition: swbuf.h:379
const char * c_str() const
Definition: swbuf.h:158
unsigned short SW_u16
Definition: sysdata.h:38
unsigned long size() const
Definition: swbuf.h:185
unsigned int SW_u32
Definition: sysdata.h:41
SW_u32 getUniCharFromUTF8(const unsigned char **buf, bool skipValidation=false)
Definition: utilstr.h:88
void setSize(unsigned long len)
Definition: swbuf.h:255
signed short SW_s16
Definition: sysdata.h:37

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