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

#include <osisosis.h>

+ Inheritance diagram for OSISOSIS:
+ Collaboration diagram for OSISOSIS:

Classes

class  MyUserData
 

Public Member Functions

virtual const char * getHeader () const
 
 OSISOSIS ()
 

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, const SWModule *module)
 
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 internal OSIS text to public OSIS text

Definition at line 34 of file osisosis.h.

Constructor & Destructor Documentation

OSISOSIS::OSISOSIS ( )

Definition at line 37 of file osisosis.cpp.

37  {
38  setTokenStart("<");
39  setTokenEnd(">");
40 
41  setEscapeStart("&");
42  setEscapeEnd(";");
43 
46 
47  addAllowedEscapeString("quot");
48  addAllowedEscapeString("apos");
52 
54 }
void setTokenEnd(const char *tokenEnd)
void addAllowedEscapeString(const char *findString)
void setTokenCaseSensitive(bool val)
void setEscapeStart(const char *escStart)
void setTokenStart(const char *tokenStart)
void setPassThruNumericEscapeString(bool val)
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 }
virtual BasicFilterUserData* OSISOSIS::createUserData ( const SWModule module,
const SWKey key 
)
inlineprotectedvirtual

Reimplemented from SWBasicFilter.

Definition at line 47 of file osisosis.h.

47  {
48  return new MyUserData(module, key);
49  }
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 OSISOSIS::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 95 of file osisosis.cpp.

95  {
96  // manually process if it wasn't a simple substitution
97  if (!substituteToken(buf, token)) {
98  MyUserData *u = (MyUserData *)userData;
99  XMLTag tag(token);
100 
101  if (!tag.isEmpty() && (!tag.isEndTag()))
102  u->startTag = tag;
103 
104  // <w> tag
105  if (!strcmp(tag.getName(), "w")) {
106 
107  // start <w> tag
108  if ((!tag.isEmpty()) && (!tag.isEndTag())) {
109  SWBuf attr = tag.getAttribute("lemma");
110  if (attr.length()) {
111  if (!strncmp(attr.c_str(), "x-Strongs:", 10)) {
112  memcpy(attr.getRawData()+3, "strong", 6);
113  attr << 3;
114  tag.setAttribute("lemma", attr);
115  }
116  }
117  attr = tag.getAttribute("morph");
118  if (attr.length()) {
119  if (!strncmp(attr.c_str(), "x-StrongsMorph:", 15)) {
120  memcpy(attr.getRawData()+3, "strong", 6);
121  attr << 3;
122  tag.setAttribute("lemma", attr);
123  }
124  if (!strncmp(attr.c_str(), "x-Robinson:", 11)) {
125  attr[2] = 'r';
126  attr << 2;
127  tag.setAttribute("lemma", attr);
128  }
129  }
130  tag.setAttribute("wn", 0);
131  tag.setAttribute("savlm", 0);
132  tag.setAttribute("splitID", 0);
133  }
134  buf += tag;
135  }
136 
137  // <note> tag
138  else if (!strcmp(tag.getName(), "note")) {
139  if (!tag.isEndTag()) {
140  SWBuf type = tag.getAttribute("type");
141 
142  bool strongsMarkup = (type == "x-strongsMarkup" || type == "strongsMarkup"); // the latter is deprecated
143  if (strongsMarkup) {
144  tag.setEmpty(false); // handle bug in KJV2003 module where some note open tags were <note ... />
145  }
146 
147  if (!tag.isEmpty()) {
148  tag.setAttribute("swordFootnote", 0);
149 
150  if (!strongsMarkup) {
151  buf += tag;
152  }
153  else u->suspendTextPassThru = true;
154  }
155 
156  if (u->module) {
157  XMLTag tag = token;
158  SWBuf swordFootnote = tag.getAttribute("swordFootnote");
159  SWBuf footnoteBody = u->module->getEntryAttributes()["Footnote"][swordFootnote]["body"];
160  buf.append(u->module->renderText(footnoteBody));
161  }
162  }
163  if (tag.isEndTag()) {
164  if (u->suspendTextPassThru == false)
165  buf+=tag;
166  else u->suspendTextPassThru = false;
167  }
168  }
169 
170  else {
171  return false; // we still didn't handle token
172  }
173  }
174  return true;
175 }
Definition: swbuf.h:47
unsigned long length() const
Definition: swbuf.h:197
Definition: utilxml.h:38
bool substituteToken(SWBuf &buf, const char *token)
char * getRawData()
Definition: swbuf.h:379
const char * c_str() const
Definition: swbuf.h:158
SWBuf & append(const char *str, long max=-1)
Definition: swbuf.h:274
const char * getAttribute(const char *attribName, int partNum=-1, char partSplit= '|') const
Definition: utilxml.cpp:230
bool isEndTag(const char *eID=0) const
Definition: utilxml.cpp:323
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 OSISOSIS::processText ( SWBuf text,
const SWKey key,
const SWModule module 
)
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 57 of file osisosis.cpp.

57  {
58  char status = SWBasicFilter::processText(text, key, module);
59  const VerseKey *vkey = SWDYNAMIC_CAST(const VerseKey, key);
60  if (vkey) {
61  if (vkey->getVerse()) {
62  VerseKey *tmp = (VerseKey *)vkey->clone();
63  *tmp = *vkey;
64  tmp->setAutoNormalize(false);
65  tmp->setIntros(true);
66 
67  *tmp = MAXVERSE;
68  if (*vkey == *tmp) {
69  tmp->setVerse(0);
70 // sprintf(ref, "\t</div>");
71 // pushString(&to, ref);
72  *tmp = MAXCHAPTER;
73  *tmp = MAXVERSE;
74  if (*vkey == *tmp) {
75  tmp->setChapter(0);
76  tmp->setVerse(0);
77 // sprintf(ref, "\t</div>");
78 // pushString(&to, ref);
79  }
80  }
81  delete tmp;
82  }
83 
84 //
85 // else if (vkey->Chapter()) {
86 // sprintf(ref, "\t<div type=\"chapter\" osisID=\"%s\">", vkey->getOSISRef());
87 // }
88 // else sprintf(ref, "\t<div type=\"book\" osisID=\"%s\">", vkey->getOSISRef());
89 //
90 
91  }
92  return status;
93 }
virtual SWKey * clone() const
Definition: versekey.cpp:278
virtual char processText(SWBuf &text, const SWKey *key=0, const SWModule *module=0)
#define MAXVERSE
Definition: versekey.h:43
virtual void setChapter(int ichapter)
Definition: versekey.cpp:1603
virtual void setIntros(bool val)
Definition: versekey.cpp:1663
virtual void setVerse(int iverse)
Definition: versekey.cpp:1622
virtual int getVerse() const
Definition: versekey.cpp:1534
#define SWDYNAMIC_CAST(className, object)
Definition: defs.h:47
#define MAXCHAPTER
Definition: versekey.h:44
virtual void setAutoNormalize(bool iautonorm)
Definition: versekey.cpp:1648
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: