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

#include <unicodertf.h>

+ Inheritance diagram for UnicodeRTF:
+ Collaboration diagram for UnicodeRTF:

Public Member Functions

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

Detailed Description

This filter converts UTF-8 text into RTF Unicode tags

Definition at line 33 of file unicodertf.h.

Constructor & Destructor Documentation

SWORD_NAMESPACE_START UnicodeRTF::UnicodeRTF ( )

Definition at line 29 of file unicodertf.cpp.

29  {
30 }

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 UnicodeRTF::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 33 of file unicodertf.cpp.

34 {
35  const unsigned char *from;
36  char digit[10];
37  unsigned long ch;
38  signed short utf16;
39  unsigned char from2[7];
40 
41  SWBuf orig = text;
42 
43  from = (const unsigned char *)orig.c_str();
44 
45  // -------------------------------
46  for (text = ""; *from; from++) {
47  ch = 0;
48  //case: ANSI
49  if ((*from & 128) != 128) {
50  text += *from;
51  continue;
52  }
53  //case: Invalid UTF-8 (illegal continuing byte in initial position)
54  if ((*from & 128) && ((*from & 64) != 64)) {
55  continue;
56  }
57  //case: 2+ byte codepoint
58  from2[0] = *from;
59  from2[0] <<= 1;
60  int subsequent;
61  for (subsequent = 1; (from2[0] & 128) && (subsequent < 7); subsequent++) {
62  from2[0] <<= 1;
63  from2[subsequent] = from[subsequent];
64  from2[subsequent] &= 63;
65  ch <<= 6;
66  ch |= from2[subsequent];
67  }
68  subsequent--;
69  from2[0] <<= 1;
70  char significantFirstBits = 8 - (2+subsequent);
71 
72  ch |= (((short)from2[0]) << (((6*subsequent)+significantFirstBits)-8));
73  from += subsequent;
74  if (ch < 0x10000) {
75  utf16 = (signed short)ch;
76  text += '\\';
77  text += 'u';
78  sprintf(digit, "%d", utf16);
79  text += digit;
80  text += '?';
81  }
82  else {
83  utf16 = (signed short)((ch - 0x10000) / 0x400 + 0xD800);
84  text += '\\';
85  text += 'u';
86  sprintf(digit, "%d", utf16);
87  text += digit;
88  text += '?';
89  utf16 = (signed short)((ch - 0x10000) % 0x400 + 0xDC00);
90  text += '\\';
91  text += 'u';
92  sprintf(digit, "%d", utf16);
93  text += digit;
94  text += '?';
95  }
96  }
97 
98  return 0;
99 }
Definition: swbuf.h:47
const char * c_str() const
Definition: swbuf.h:158

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