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

#include <osisrtf.h>

+ Inheritance diagram for OSISRTF:
+ Collaboration diagram for OSISRTF:

Public Member Functions

virtual const char * getHeader () const
 
 OSISRTF ()
 

Protected Member Functions

void addAllowedEscapeString (const char *findString)
 
void addEscapeStringSubstitute (const char *findString, const char *replaceString)
 
void addTokenSubstitute (const char *findString, const char *replaceString)
 
void appendEscapeString (SWBuf &buf, const char *escString)
 
virtual BasicFilterUserDatacreateUserData (const SWModule *module, const SWKey *key)
 
virtual bool handleEscapeString (SWBuf &buf, const char *escString, BasicFilterUserData *userData)
 
virtual bool handleNumericEscapeString (SWBuf &buf, const char *escString)
 
virtual bool handleToken (SWBuf &buf, const char *token, BasicFilterUserData *userData)
 
bool passAllowedEscapeString (SWBuf &buf, const char *escString)
 
virtual bool processStage (char, SWBuf &, char *&, BasicFilterUserData *)
 
virtual char processText (SWBuf &text, const SWKey *key=0, const SWModule *module=0)
 
void removeAllowedEscapeString (const char *findString)
 
void removeEscapeStringSubstitute (const char *findString)
 
void removeTokenSubstitute (const char *findString)
 
void setEscapeEnd (const char *escEnd)
 
void setEscapeStart (const char *escStart)
 
void setEscapeStringCaseSensitive (bool val)
 
void setPassThruNumericEscapeString (bool val)
 
void setPassThruUnknownEscapeString (bool val)
 
void setPassThruUnknownToken (bool val)
 
virtual void setStageProcessing (char stages)
 
void setTokenCaseSensitive (bool val)
 
void setTokenEnd (const char *tokenEnd)
 
void setTokenStart (const char *tokenStart)
 
bool substituteEscapeString (SWBuf &buf, const char *escString)
 
bool substituteToken (SWBuf &buf, const char *token)
 

Static Protected Attributes

static const char FINALIZE = 8
 
static const char INITIALIZE = 1
 
static const char POSTCHAR = 4
 
static const char PRECHAR = 2
 

Detailed Description

this filter converts OSIS text to RTF text

Definition at line 33 of file osisrtf.h.

Constructor & Destructor Documentation

OSISRTF::OSISRTF ( )

Definition at line 78 of file osisrtf.cpp.

78  {
79  setTokenStart("<");
80  setTokenEnd(">");
81 
82  setEscapeStart("&");
83  setEscapeEnd(";");
84 
86 
87  addEscapeStringSubstitute("amp", "&");
88  addEscapeStringSubstitute("apos", "'");
89  addEscapeStringSubstitute("lt", "<");
90  addEscapeStringSubstitute("gt", ">");
91  addEscapeStringSubstitute("quot", "\"");
92  // addTokenSubstitute("lg", "{\\par}");
93  // addTokenSubstitute("/lg", "{\\par}");
94 
96 }
void setTokenEnd(const char *tokenEnd)
void setTokenCaseSensitive(bool val)
void setEscapeStart(const char *escStart)
void addEscapeStringSubstitute(const char *findString, const char *replaceString)
void setTokenStart(const char *tokenStart)
void setEscapeStringCaseSensitive(bool val)
void setEscapeEnd(const char *escEnd)

Member Function Documentation

void SWBasicFilter::addAllowedEscapeString ( const char *  findString)
protectedinherited

Registers an esc control sequence that can pass unchanged

Definition at line 156 of file swbasicfilter.cpp.

156  {
157  char *buf = 0;
158 
159  if (!escStringCaseSensitive) {
160  stdstr(&buf, findString);
161  toupperstr(buf);
162  p->escPassSet.insert(StringSet::value_type(buf));
163  delete [] buf;
164  }
165  else p->escPassSet.insert(StringSet::value_type(findString));
166 }
SWORD_NAMESPACE_START char * stdstr(char **ipstr, const char *istr, unsigned int memPadFactor=1)
Definition: utilstr.h:44
bool escStringCaseSensitive
Definition: swbasicfilter.h:74
char * toupperstr(char *t, unsigned int max=0)
Definition: stringmgr.h:107
Private * p
Definition: swbasicfilter.h:82
void SWBasicFilter::addEscapeStringSubstitute ( const char *  findString,
const char *  replaceString 
)
protectedinherited

Registers an esc control sequence

Definition at line 176 of file swbasicfilter.cpp.

176  {
177  char *buf = 0;
178 
179  if (!escStringCaseSensitive) {
180  stdstr(&buf, findString);
181  toupperstr(buf);
182  p->escSubMap.insert(DualStringMap::value_type(buf, replaceString));
183  delete [] buf;
184  }
185  else p->escSubMap.insert(DualStringMap::value_type(findString, replaceString));
186 }
SWORD_NAMESPACE_START char * stdstr(char **ipstr, const char *istr, unsigned int memPadFactor=1)
Definition: utilstr.h:44
bool escStringCaseSensitive
Definition: swbasicfilter.h:74
char * toupperstr(char *t, unsigned int max=0)
Definition: stringmgr.h:107
Private * p
Definition: swbasicfilter.h:82
void SWBasicFilter::addTokenSubstitute ( const char *  findString,
const char *  replaceString 
)
protectedinherited

Registers a simple token substitutions. Usually called from the c-tor of a subclass

Definition at line 136 of file swbasicfilter.cpp.

136  {
137  char *buf = 0;
138 
139  if (!tokenCaseSensitive) {
140  stdstr(&buf, findString);
141  toupperstr(buf);
142  p->tokenSubMap[buf] = replaceString;
143  delete [] buf;
144  }
145  else p->tokenSubMap[findString] = replaceString;
146 }
SWORD_NAMESPACE_START char * stdstr(char **ipstr, const char *istr, unsigned int memPadFactor=1)
Definition: utilstr.h:44
bool tokenCaseSensitive
Definition: swbasicfilter.h:75
DualStringMap tokenSubMap
char * toupperstr(char *t, unsigned int max=0)
Definition: stringmgr.h:107
Private * p
Definition: swbasicfilter.h:82
void SWBasicFilter::appendEscapeString ( SWBuf buf,
const char *  escString 
)
protectedinherited

This appends escString to buf as an entity

Definition at line 216 of file swbasicfilter.cpp.

216  {
217  buf += escStart;
218  buf += escString;
219  buf += escEnd;
220 }
BasicFilterUserData * OSISRTF::createUserData ( const SWModule module,
const SWKey key 
)
protectedvirtual

Reimplemented from SWBasicFilter.

Definition at line 99 of file osisrtf.cpp.

99  {
100  return new MyUserData(module, key);
101 }
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 ""; }
bool SWBasicFilter::handleEscapeString ( SWBuf buf,
const char *  escString,
BasicFilterUserData userData 
)
protectedvirtualinherited

This function is called for every escape sequence encountered in the input text.

Parameters
bufthe output buffer
escStringthe escape sequence (e.g. "amp" for &amp;)
userDatauser storage space for data transient to 1 full buffer parse
Returns
false if was not handled and should be handled in
subclasses should return true if they handled the esc seq, or false if they did not.

Definition at line 286 of file swbasicfilter.cpp.

286  {
287  return substituteEscapeString(buf, escString);
288 }
bool substituteEscapeString(SWBuf &buf, const char *escString)
bool SWBasicFilter::handleNumericEscapeString ( SWBuf buf,
const char *  escString 
)
protectedvirtualinherited

This function is called for all numeric escape sequences. If passThrough

Parameters
bufthe output buffer
escStringthe escape sequence (e.g. "#235" for &235;)
Returns
subclasses should return true if they handled the esc seq, or false if they did not.

Definition at line 244 of file swbasicfilter.cpp.

244  {
245  if (passThruNumericEsc) {
246  appendEscapeString(buf, escString);
247  return true;
248  }
249  return false;
250 }
bool passThruNumericEsc
Definition: swbasicfilter.h:78
void appendEscapeString(SWBuf &buf, const char *escString)
bool OSISRTF::handleToken ( SWBuf buf,
const char *  token,
BasicFilterUserData userData 
)
protectedvirtual

This function is called for every token encountered in the input text.

Parameters
bufthe output buffer
tokenthe token (e.g. "p align='left'"
userDatauser storage space for data transient to 1 full buffer parse
Returns
subclasses should return true if they handled the token, or false if they did not.

Reimplemented from SWBasicFilter.

Definition at line 144 of file osisrtf.cpp.

144  {
145  // manually process if it wasn't a simple substitution
146  MyUserData *u = (MyUserData *)userData;
147  SWBuf scratch;
148  bool sub = (u->suspendTextPassThru) ? substituteToken(scratch, token) : substituteToken(buf, token);
149  if (!sub) {
150  XMLTag tag(token);
151 
152  // <w> tag
153  if (!strcmp(tag.getName(), "w")) {
154 
155  // start <w> tag
156  if ((!tag.isEmpty()) && (!tag.isEndTag())) {
157  outText('{', buf, u);
158  u->w = token;
159  }
160 
161  // end or empty <w> tag
162  else {
163  bool endTag = tag.isEndTag();
164  SWBuf lastText;
165  bool show = true; // to handle unplaced article in kjv2003-- temporary till combined
166 
167  if (endTag) {
168  tag = u->w.c_str();
169  lastText = u->lastTextNode.c_str();
170  }
171  else lastText = "stuff";
172 
173  const char *attrib;
174  const char *val;
175  if ((attrib = tag.getAttribute("xlit"))) {
176  val = strchr(attrib, ':');
177  val = (val) ? (val + 1) : attrib;
178  scratch.setFormatted(" {\\fs15 <%s>}", val);
179  outText(scratch.c_str(), buf, u);
180  }
181  if ((attrib = tag.getAttribute("gloss"))) {
182  val = strchr(attrib, ':');
183  val = (val) ? (val + 1) : attrib;
184  scratch.setFormatted(" {\\fs15 <%s>}", val);
185  outText(scratch.c_str(), buf, u);
186  }
187  if ((attrib = tag.getAttribute("lemma"))) {
188  int count = tag.getAttributePartCount("lemma", ' ');
189  int i = (count > 1) ? 0 : -1; // -1 for whole value cuz it's faster, but does the same thing as 0
190  do {
191  attrib = tag.getAttribute("lemma", i, ' ');
192  if (i < 0) i = 0; // to handle our -1 condition
193  val = strchr(attrib, ':');
194  val = (val) ? (val + 1) : attrib;
195  const char *val2 = val;
196  if ((strchr("GH", *val)) && (isdigit(val[1])))
197  val2++;
198  if ((!strcmp(val2, "3588")) && (lastText.length() < 1))
199  show = false;
200  else {
201  scratch.setFormatted(" {\\cf3 \\sub <%s>}", val2);
202  outText(scratch.c_str(), buf, u);
203  }
204  } while (++i < count);
205  }
206  if ((attrib = tag.getAttribute("morph")) && (show)) {
207  SWBuf savelemma = tag.getAttribute("savlm");
208  if ((strstr(savelemma.c_str(), "3588")) && (lastText.length() < 1))
209  show = false;
210  if (show) {
211  int count = tag.getAttributePartCount("morph", ' ');
212  int i = (count > 1) ? 0 : -1; // -1 for whole value cuz it's faster, but does the same thing as 0
213  do {
214  attrib = tag.getAttribute("morph", i, ' ');
215  if (i < 0) i = 0; // to handle our -1 condition
216  val = strchr(attrib, ':');
217  val = (val) ? (val + 1) : attrib;
218  const char *val2 = val;
219  if ((*val == 'T') && (strchr("GH", val[1])) && (isdigit(val[2])))
220  val2+=2;
221  scratch.setFormatted(" {\\cf4 \\sub (%s)}", val2);
222  outText(scratch.c_str(), buf, u);
223  } while (++i < count);
224  }
225  }
226  if ((attrib = tag.getAttribute("POS"))) {
227  val = strchr(attrib, ':');
228  val = (val) ? (val + 1) : attrib;
229  scratch.setFormatted(" {\\fs15 <%s>}", val);
230  outText(scratch.c_str(), buf, u);
231  }
232 
233  if (endTag)
234  outText('}', buf, u);
235  }
236  }
237 
238  // <note> tag
239  else if (!strcmp(tag.getName(), "note")) {
240  if (!tag.isEndTag()) {
241  if (!tag.isEmpty()) {
242  SWBuf type = tag.getAttribute("type");
243 
244  if ((type != "x-strongsMarkup") // leave strong's markup notes out, in the future we'll probably have different option filters to turn different note types on or off
245  && (type != "strongsMarkup") // deprecated
246  ) {
247  SWBuf footnoteNumber = tag.getAttribute("swordFootnote");
248  if (u->vkey) {
249  char ch = ((!strcmp(type.c_str(), "crossReference")) || (!strcmp(type.c_str(), "x-cross-ref"))) ? 'x':'n';
250  scratch.setFormatted("{\\super <a href=\"\">*%c%i.%s</a>} ", ch, u->vkey->getVerse(), footnoteNumber.c_str());
251  outText(scratch.c_str(), buf, u);
252  u->inXRefNote = (ch == 'x');
253  }
254  }
255  u->suspendTextPassThru = (++u->suspendLevel);
256  }
257  }
258  if (tag.isEndTag()) {
259  u->suspendTextPassThru = (--u->suspendLevel);
260  u->inXRefNote = false;
261  }
262  }
263 
264  // <p> paragraph and <lg> linegroup tags
265  else if (!strcmp(tag.getName(), "p") || !strcmp(tag.getName(), "lg")) {
266  if ((!tag.isEndTag()) && (!tag.isEmpty())) { // non-empty start tag
267  outText("{\\fi200\\par}", buf, u);
268  }
269  else if (tag.isEndTag()) { // end tag
270  outText("{\\par}", buf, u);
271  userData->supressAdjacentWhitespace = true;
272  }
273  else { // empty paragraph break marker
274  outText("{\\pard\\par}", buf, u);
275  userData->supressAdjacentWhitespace = true;
276  }
277  }
278 
279  // Milestoned paragraphs, created by osis2mod
280  // <div type="paragraph" sID.../>
281  // <div type="paragraph" eID.../>
282  else if (tag.isEmpty() && !strcmp(tag.getName(), "div") && tag.getAttribute("type") && (!strcmp(tag.getAttribute("type"), "x-p") || !strcmp(tag.getAttribute("type"), "paragraph"))) {
283  // <div type="paragraph" sID... />
284  if (tag.getAttribute("sID")) { // non-empty start tag
285  outText("{\\fi200\\par}", buf, u);
286  }
287  // <div type="paragraph" eID... />
288  else if (tag.getAttribute("eID")) {
289  outText("{\\par}", buf, u);
290  userData->supressAdjacentWhitespace = true;
291  }
292  }
293 
294  // <reference> tag
295  else if (!strcmp(tag.getName(), "reference")) {
296  if (!u->inXRefNote) { // only show these if we're not in an xref note
297  if ((!tag.isEndTag()) && (!tag.isEmpty())) {
298  outText("{<a href=\"\">", buf, u);
299  }
300  else if (tag.isEndTag()) {
301  outText("</a>}", buf, u);
302  }
303  }
304  }
305 
306  // <l> poetry
307  else if (!strcmp(tag.getName(), "l")) {
308  // end line marker
309  if (tag.getAttribute("eID")) {
310  outText("{\\par}", buf, u);
311  }
312  // <l/> without eID or sID
313  // Note: this is improper osis. This should be <lb/>
314  else if (tag.isEmpty() && !tag.getAttribute("sID")) {
315  outText("{\\par}", buf, u);
316  }
317  // end of the line
318  else if (tag.isEndTag()) {
319  outText("{\\par}", buf, u);
320  }
321  }
322 
323  // <milestone type="line"/> or <lb.../>
324  else if ((!strcmp(tag.getName(), "lb") && (!tag.getAttribute("type") || strcmp(tag.getAttribute("type"), "x-optional"))) || ((!strcmp(tag.getName(), "milestone")) && (tag.getAttribute("type")) && (!strcmp(tag.getAttribute("type"), "line")))) {
325  outText("{\\par}", buf, u);
326  userData->supressAdjacentWhitespace = true;
327  }
328 
329  // <title>
330  else if (!strcmp(tag.getName(), "title")) {
331  if ((!tag.isEndTag()) && (!tag.isEmpty())) {
332  outText("{\\par\\i1\\b1 ", buf, u);
333  }
334  else if (tag.isEndTag()) {
335  outText("\\par}", buf, u);
336  }
337  }
338  // <list> - how do we support these better in RTF?
339  else if (!strcmp(tag.getName(), "list")) {
340  if((!tag.isEndTag()) && (!tag.isEmpty())) {
341  outText("\\par\\pard", buf, u);
342  }
343  else if (tag.isEndTag()) {
344  outText("\\par\\pard", buf, u);
345  }
346  }
347 
348  // <item> - support better
349  else if (!strcmp(tag.getName(), "item")) {
350  if((!tag.isEndTag()) && (!tag.isEmpty())) {
351  outText("* ", buf, u);
352  }
353  else if (tag.isEndTag()) {
354  outText("\\par", buf, u);
355  }
356  }
357 
358  // <catchWord> & <rdg> tags (italicize)
359  else if (!strcmp(tag.getName(), "rdg") || !strcmp(tag.getName(), "catchWord")) {
360  if ((!tag.isEndTag()) && (!tag.isEmpty())) {
361  outText("{\\i1 ", buf, u);
362  }
363  else if (tag.isEndTag()) {
364  outText('}', buf, u);
365  }
366  }
367 
368  // <hi>
369  else if (!strcmp(tag.getName(), "hi")) {
370  SWBuf type = tag.getAttribute("type");
371  if ((!tag.isEndTag()) && (!tag.isEmpty())) {
372  if (type == "bold" || type == "b" || type == "x-b")
373  outText("{\\b1 ", buf, u);
374  else // all other types
375  outText("{\\i1 ", buf, u);
376  }
377  else if (tag.isEndTag()) {
378  outText('}', buf, u);
379  }
380  }
381 
382  // <q> quote
383  // Rules for a quote element:
384  // If the tag is empty with an sID or an eID then use whatever it specifies for quoting.
385  // Note: empty elements without sID or eID are ignored.
386  // If the tag is <q> then use it's specifications and push it onto a stack for </q>
387  // If the tag is </q> then use the pushed <q> for specification
388  // If there is a marker attribute, possibly empty, this overrides osisQToTick.
389  // If osisQToTick, then output the marker, using level to determine the type of mark.
390  else if (!strcmp(tag.getName(), "q")) {
391  SWBuf type = tag.getAttribute("type");
392  SWBuf who = tag.getAttribute("who");
393  const char *tmp = tag.getAttribute("level");
394  int level = (tmp) ? atoi(tmp) : 1;
395  tmp = tag.getAttribute("marker");
396  bool hasMark = tmp;
397  SWBuf mark = tmp;
398 
399  // open <q> or <q sID... />
400  if ((!tag.isEmpty() && !tag.isEndTag()) || (tag.isEmpty() && tag.getAttribute("sID"))) {
401  // if <q> then remember it for the </q>
402  if (!tag.isEmpty()) {
403  char *tagData = 0;
404  stdstr(&tagData, tag.toString());
405  u->quoteStack.push(tagData);
406  }
407 
408  // Do this first so quote marks are included as WoC
409  if (who == "Jesus")
410  outText("\\cf6 ", buf, u);
411 
412  // first check to see if we've been given an explicit mark
413  if (hasMark)
414  outText(mark, buf, u);
415  //alternate " and '
416  else if (u->osisQToTick)
417  outText((level % 2) ? '\"' : '\'', buf, u);
418  }
419  // close </q> or <q eID... />
420  else if ((tag.isEndTag()) || (tag.getAttribute("eID"))) {
421  // if it is </q> then pop the stack for the attributes
422  if (tag.isEndTag() && !u->quoteStack.empty()) {
423  char *tagData = u->quoteStack.top();
424  u->quoteStack.pop();
425  XMLTag qTag(tagData);
426  delete [] tagData;
427 
428  type = qTag.getAttribute("type");
429  who = qTag.getAttribute("who");
430  tmp = qTag.getAttribute("level");
431  level = (tmp) ? atoi(tmp) : 1;
432  tmp = qTag.getAttribute("marker");
433  hasMark = tmp;
434  mark = tmp;
435  }
436 
437  // first check to see if we've been given an explicit mark
438  if (hasMark)
439  outText(mark, buf, u);
440  // finally, alternate " and ', if config says we should supply a mark
441  else if (u->osisQToTick)
442  outText((level % 2) ? '\"' : '\'', buf, u);
443 
444  // Do this last so quote marks are included as WoC
445  if (who == "Jesus")
446  outText("\\cf0 ", buf, u);
447  }
448  }
449 
450 
451  // <milestone type="cQuote" marker="x"/>
452  else if (!strcmp(tag.getName(), "milestone") && tag.getAttribute("type") && !strcmp(tag.getAttribute("type"), "cQuote")) {
453  const char *tmp = tag.getAttribute("marker");
454  bool hasMark = tmp;
455  SWBuf mark = tmp;
456  tmp = tag.getAttribute("level");
457  int level = (tmp) ? atoi(tmp) : 1;
458 
459  // first check to see if we've been given an explicit mark
460  if (hasMark)
461  outText(mark, buf, u);
462  // finally, alternate " and ', if config says we should supply a mark
463  else if (u->osisQToTick)
464  outText((level % 2) ? '\"' : '\'', buf, u);
465  }
466 
467  // <transChange>
468  else if (!strcmp(tag.getName(), "transChange")) {
469  SWBuf type = tag.getAttribute("type");
470 
471  if ((!tag.isEndTag()) && (!tag.isEmpty())) {
472 
473 // just do all transChange tags this way for now
474 // if (type == "supplied")
475  outText("{\\i1 ", buf, u);
476  }
477  else if (tag.isEndTag()) {
478  outText('}', buf, u);
479  }
480  }
481 
482  // <divineName>
483  else if (!strcmp(tag.getName(), "divineName")) {
484 
485  if ((!tag.isEndTag()) && (!tag.isEmpty())) {
486  outText("{\\scaps ", buf, u);
487  }
488  else if (tag.isEndTag()) {
489  outText("}", buf, u);
490  }
491  }
492 
493  // <div>
494  else if (!strcmp(tag.getName(), "div")) {
495 
496  if ((!tag.isEndTag()) && (!tag.isEmpty())) {
497  outText("\\pard ", buf, u);
498  }
499  else if (tag.isEndTag()) {
500  outText("\\par ", buf, u);
501  }
502  }
503 
504  // image
505  else if (!strcmp(tag.getName(), "figure")) {
506  const char *src = tag.getAttribute("src");
507  if (!src) // assert we have a src attribute
508  return false;
509 
510  char* filepath = new char[strlen(u->module->getConfigEntry("AbsoluteDataPath")) + strlen(token)];
511  *filepath = 0;
512  strcpy(filepath, userData->module->getConfigEntry("AbsoluteDataPath"));
513  strcat(filepath, src);
514 
515 // we do this because BibleCS looks for this EXACT format for an image tag
516  outText("<img src=\"", buf, u);
517  outText(filepath, buf, u);
518  outText("\" />", buf, u);
519 /*
520  char imgc;
521  for (c = filepath + strlen(filepath); c > filepath && *c != '.'; c--);
522  c++;
523  FILE* imgfile;
524  if (stricmp(c, "jpg") || stricmp(c, "jpeg")) {
525  imgfile = fopen(filepath, "r");
526  if (imgfile != NULL) {
527  outText("{\\nonshppict {\\pict\\jpegblip ", buf, u);
528  while (feof(imgfile) != EOF) {
529  scratch.setFormatted("%2x", fgetc(imgfile));
530  outText(scratch.c_str(), buf, u);
531 
532  }
533  fclose(imgfile);
534  outText("}}", buf, u);
535  }
536  }
537  else if (stricmp(c, "png")) {
538  outText("{\\*\\shppict {\\pict\\pngblip ", buf, u);
539 
540  outText("}}", buf, u);
541  }
542 */
543  delete [] filepath;
544  }
545  else {
546  return false; // we still didn't handle token
547  }
548  }
549  return true;
550 }
Definition: swbuf.h:47
unsigned long length() const
Definition: swbuf.h:197
virtual const char * getConfigEntry(const char *key) const
Definition: swmodule.cpp:1159
const SWModule * module
Definition: swbasicfilter.h:42
Definition: utilxml.h:38
bool substituteToken(SWBuf &buf, const char *token)
SWORD_NAMESPACE_START char * stdstr(char **ipstr, const char *istr, unsigned int memPadFactor=1)
Definition: utilstr.h:44
const char * c_str() const
Definition: swbuf.h:158
static void outText(const char *t, SWBuf &o, BasicFilterUserData *u)
SWBuf & setFormatted(const char *format,...)
Definition: swbuf.cpp:50
bool SWBasicFilter::passAllowedEscapeString ( SWBuf buf,
const char *  escString 
)
protectedinherited

This passes allowed escapeStrings

Definition at line 223 of file swbasicfilter.cpp.

223  {
224  StringSet::iterator it;
225 
226  if (!escStringCaseSensitive) {
227  char *tmp = 0;
228  stdstr(&tmp, escString);
229  toupperstr(tmp);
230  it = p->escPassSet.find(tmp);
231  delete [] tmp;
232  } else
233  it = p->escPassSet.find(escString);
234 
235  if (it != p->escPassSet.end()) {
236  appendEscapeString(buf, escString);
237  return true;
238  }
239 
240  return false;
241 }
SWORD_NAMESPACE_START char * stdstr(char **ipstr, const char *istr, unsigned int memPadFactor=1)
Definition: utilstr.h:44
bool escStringCaseSensitive
Definition: swbasicfilter.h:74
char * toupperstr(char *t, unsigned int max=0)
Definition: stringmgr.h:107
Private * p
Definition: swbasicfilter.h:82
void appendEscapeString(SWBuf &buf, const char *escString)
virtual bool SWBasicFilter::processStage ( char  ,
SWBuf ,
char *&  ,
BasicFilterUserData  
)
inlineprotectedvirtualinherited

Reimplemented in OSISPlain.

Definition at line 185 of file swbasicfilter.h.

185 { return false; }
char OSISRTF::processText ( SWBuf text,
const SWKey key = 0,
const SWModule module = 0 
)
protectedvirtual

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

Reimplemented from SWBasicFilter.

Definition at line 104 of file osisrtf.cpp.

104  {
105 
106  // preprocess text buffer to escape RTF control codes
107  const char *from;
108  SWBuf orig = text;
109  from = orig.c_str();
110  for (text = ""; *from; from++) { //loop to remove extra spaces
111  switch (*from) {
112  case '{':
113  case '}':
114  case '\\':
115  text += "\\";
116  text += *from;
117  break;
118  default:
119  text += *from;
120  }
121  }
122  text += (char)0;
123 
124  SWBasicFilter::processText(text, key, module); //handle tokens as usual
125 
126  orig = text;
127  from = orig.c_str();
128  for (text = ""; *from; from++) { //loop to remove extra spaces
129  if ((strchr(" \t\n\r", *from))) {
130  while (*(from+1) && (strchr(" \t\n\r", *(from+1)))) {
131  from++;
132  }
133  text += " ";
134  }
135  else {
136  text += *from;
137  }
138  }
139  text += (char)0; // probably not needed, but don't want to remove without investigating (same as above)
140  return 0;
141 }
Definition: swbuf.h:47
virtual char processText(SWBuf &text, const SWKey *key=0, const SWModule *module=0)
const char * c_str() const
Definition: swbuf.h:158
void SWBasicFilter::removeAllowedEscapeString ( const char *  findString)
protectedinherited

Unregisters an esc control sequence that can pass unchanged

Definition at line 169 of file swbasicfilter.cpp.

169  {
170  if (p->escPassSet.find(findString) != p->escPassSet.end()) {
171  p->escPassSet.erase( p->escPassSet.find(findString) );
172  }
173 }
Private * p
Definition: swbasicfilter.h:82
void SWBasicFilter::removeEscapeStringSubstitute ( const char *  findString)
protectedinherited

Unregisters an esc control sequence

Definition at line 189 of file swbasicfilter.cpp.

189  {
190  if (p->escSubMap.find(findString) != p->escSubMap.end()) {
191  p->escSubMap.erase( p->escSubMap.find(findString) );
192  }
193 }
Private * p
Definition: swbasicfilter.h:82
void SWBasicFilter::removeTokenSubstitute ( const char *  findString)
protectedinherited

Unregisters a simple token substitute

Definition at line 149 of file swbasicfilter.cpp.

149  {
150  if (p->tokenSubMap.find(findString) != p->tokenSubMap.end()) {
151  p->tokenSubMap.erase( p->tokenSubMap.find(findString) );
152  }
153 }
DualStringMap tokenSubMap
Private * p
Definition: swbasicfilter.h:82
void SWBasicFilter::setEscapeEnd ( const char *  escEnd)
protectedinherited

Sets the end of escape sequence (by default ";").

Definition at line 297 of file swbasicfilter.cpp.

297  {
298  stdstr(&(this->escEnd), escEnd);
299  escEndLen = strlen(escEnd);
300 }
SWORD_NAMESPACE_START char * stdstr(char **ipstr, const char *istr, unsigned int memPadFactor=1)
Definition: utilstr.h:44
void SWBasicFilter::setEscapeStart ( const char *  escStart)
protectedinherited

Sets the beginning of escape sequence (by default "&").

Definition at line 291 of file swbasicfilter.cpp.

291  {
292  stdstr(&(this->escStart), escStart);
293  escStartLen = strlen(escStart);
294 }
SWORD_NAMESPACE_START char * stdstr(char **ipstr, const char *istr, unsigned int memPadFactor=1)
Definition: utilstr.h:44
void SWBasicFilter::setEscapeStringCaseSensitive ( bool  val)
protectedinherited

Are escapeStrings case sensitive or not? Call this function before addEscapeStingSubstitute()

Definition at line 131 of file swbasicfilter.cpp.

131  {
133 }
bool escStringCaseSensitive
Definition: swbasicfilter.h:74
void SWBasicFilter::setPassThruNumericEscapeString ( bool  val)
protectedinherited

Sets whether to pass thru a numeric escape sequence unchanged or allow it to be handled otherwise. Default is false.

Definition at line 121 of file swbasicfilter.cpp.

121  {
122  passThruUnknownEsc = val;
123 }
bool passThruUnknownEsc
Definition: swbasicfilter.h:77
void SWBasicFilter::setPassThruUnknownEscapeString ( bool  val)
protectedinherited

Sets whether to pass thru an unknown escape sequence unchanged or just remove it. Default is false.

Definition at line 116 of file swbasicfilter.cpp.

116  {
117  passThruUnknownEsc = val;
118 }
bool passThruUnknownEsc
Definition: swbasicfilter.h:77
void SWBasicFilter::setPassThruUnknownToken ( bool  val)
protectedinherited

Sets whether to pass thru an unknown token unchanged or just remove it. Default is false.

Definition at line 111 of file swbasicfilter.cpp.

111  {
112  passThruUnknownToken = val;
113 }
bool passThruUnknownToken
Definition: swbasicfilter.h:76
virtual void SWBasicFilter::setStageProcessing ( char  stages)
inlineprotectedvirtualinherited

Definition at line 186 of file swbasicfilter.h.

186 { processStages = stages; } // see STATICs up above
void SWBasicFilter::setTokenCaseSensitive ( bool  val)
protectedinherited

Are tokens case sensitive (like in GBF) or not? Call this function before addTokenSubstitute()

Definition at line 126 of file swbasicfilter.cpp.

126  {
127  tokenCaseSensitive = val;
128 }
bool tokenCaseSensitive
Definition: swbasicfilter.h:75
void SWBasicFilter::setTokenEnd ( const char *  tokenEnd)
protectedinherited

Sets the end of token start sequence (by default ">").

Definition at line 309 of file swbasicfilter.cpp.

309  {
310  stdstr(&(this->tokenEnd), tokenEnd);
311  tokenEndLen = strlen(tokenEnd);
312 }
SWORD_NAMESPACE_START char * stdstr(char **ipstr, const char *istr, unsigned int memPadFactor=1)
Definition: utilstr.h:44
void SWBasicFilter::setTokenStart ( const char *  tokenStart)
protectedinherited

Sets the beginning of token start sequence (by default "<").

Definition at line 303 of file swbasicfilter.cpp.

303  {
304  stdstr(&(this->tokenStart), tokenStart);
305  tokenStartLen = strlen(tokenStart);
306 }
char * tokenStart
Definition: swbasicfilter.h:64
SWORD_NAMESPACE_START char * stdstr(char **ipstr, const char *istr, unsigned int memPadFactor=1)
Definition: utilstr.h:44
bool SWBasicFilter::substituteEscapeString ( SWBuf buf,
const char *  escString 
)
protectedinherited

This function performs the substitution of escapeStrings

Definition at line 253 of file swbasicfilter.cpp.

253  {
254  DualStringMap::iterator it;
255 
256  if (*escString == '#') {
257  return handleNumericEscapeString(buf, escString);
258  }
259 
260  if (passAllowedEscapeString(buf, escString)) {
261  return true;
262  }
263 
264  if (!escStringCaseSensitive) {
265  char *tmp = 0;
266  stdstr(&tmp, escString);
267  toupperstr(tmp);
268  it = p->escSubMap.find(tmp);
269  delete [] tmp;
270  } else
271  it = p->escSubMap.find(escString);
272 
273  if (it != p->escSubMap.end()) {
274  buf += it->second.c_str();
275  return true;
276  }
277  return false;
278 }
virtual bool handleNumericEscapeString(SWBuf &buf, const char *escString)
SWORD_NAMESPACE_START char * stdstr(char **ipstr, const char *istr, unsigned int memPadFactor=1)
Definition: utilstr.h:44
const char * c_str() const
Definition: swbuf.h:158
bool escStringCaseSensitive
Definition: swbasicfilter.h:74
bool passAllowedEscapeString(SWBuf &buf, const char *escString)
char * toupperstr(char *t, unsigned int max=0)
Definition: stringmgr.h:107
Private * p
Definition: swbasicfilter.h:82
bool SWBasicFilter::substituteToken ( SWBuf buf,
const char *  token 
)
protectedinherited

This function performs the substitution of tokens

Definition at line 196 of file swbasicfilter.cpp.

196  {
197  DualStringMap::iterator it;
198 
199  if (!tokenCaseSensitive) {
200  char *tmp = 0;
201  stdstr(&tmp, token);
202  toupperstr(tmp);
203  it = p->tokenSubMap.find(tmp);
204  delete [] tmp;
205  } else
206  it = p->tokenSubMap.find(token);
207 
208  if (it != p->tokenSubMap.end()) {
209  buf += it->second.c_str();
210  return true;
211  }
212  return false;
213 }
SWORD_NAMESPACE_START char * stdstr(char **ipstr, const char *istr, unsigned int memPadFactor=1)
Definition: utilstr.h:44
const char * c_str() const
Definition: swbuf.h:158
bool tokenCaseSensitive
Definition: swbasicfilter.h:75
DualStringMap tokenSubMap
char * toupperstr(char *t, unsigned int max=0)
Definition: stringmgr.h:107
Private * p
Definition: swbasicfilter.h:82

Member Data Documentation

const char SWBasicFilter::FINALIZE = 8
staticprotectedinherited

Definition at line 99 of file swbasicfilter.h.

const char SWBasicFilter::INITIALIZE = 1
staticprotectedinherited

Definition at line 96 of file swbasicfilter.h.

const char SWBasicFilter::POSTCHAR = 4
staticprotectedinherited

Definition at line 98 of file swbasicfilter.h.

const char SWBasicFilter::PRECHAR = 2
staticprotectedinherited

Definition at line 97 of file swbasicfilter.h.


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