[sword-cvs] sword/src/modules/filters thmlvariants.cpp,1.4,1.5
sword@www.crosswire.org
sword@www.crosswire.org
Sun, 23 Feb 2003 04:54:22 -0700
Update of /usr/local/cvsroot/sword/src/modules/filters
In directory www:/tmp/cvs-serv26371
Modified Files:
thmlvariants.cpp
Log Message:
converted to use SWBuf stuff
Index: thmlvariants.cpp
===================================================================
RCS file: /usr/local/cvsroot/sword/src/modules/filters/thmlvariants.cpp,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** thmlvariants.cpp 1 Oct 2002 19:52:40 -0000 1.4
--- thmlvariants.cpp 23 Feb 2003 11:54:20 -0000 1.5
***************
*** 55,152 ****
}
! char ThMLVariants::ProcessText(char *text, int maxlen, const SWKey *key, const SWModule *module)
{
! if (option == 0) { //we want primary only
! char *to, *from, token[2048]; // cheese. Fix.
! int tokpos = 0;
bool intoken = false;
- int len;
bool hide = false;
-
- len = strlen(text) + 1; // shift string to right of buffer
- if (len < maxlen) {
- memmove(&text[maxlen - len], text, len);
- from = &text[maxlen - len];
- }
- else from = text;
! // -------------------------------
! for (to = text; *from; from++) {
if (*from == '<') {
intoken = true;
! tokpos = 0;
! token[0] = 0;
! token[1] = 0;
! token[2] = 0;
continue;
}
! if (*from == '>') { // process tokens
intoken = false;
! if (!strncmp(token, "div type=\"variant\" class=\"2\"", 28)) {
! hide = true;
! continue;
}
! else if (!strncmp(token, "/div", 4)) {
! hide = false;
! continue;
}
// if not a footnote token, keep token in text
if (!hide) {
! *to++ = '<';
! for (char *tok = token; *tok; tok++)
! *to++ = *tok;
! *to++ = '>';
}
continue;
}
if (intoken) {
! if (tokpos < 2045)
! token[tokpos++] = *from;
! token[tokpos+2] = 0;
}
! else {
! if (!hide) {
! *to++ = *from;
! }
}
}
- *to++ = 0;
- *to = 0;
}
! else if (option == 1) { //we want variant only
! char *to, *from, token[2048]; // cheese. Fix.
! int tokpos = 0;
bool intoken = false;
- int len;
bool hide = false;
! len = strlen(text) + 1; // shift string to right of buffer
! if (len < maxlen) {
! memmove(&text[maxlen - len], text, len);
! from = &text[maxlen - len];
! }
! else from = text;
!
! // -------------------------------
! for (to = text; *from; from++) {
if (*from == '<') {
intoken = true;
! tokpos = 0;
! token[0] = 0;
! token[1] = 0;
! token[2] = 0;
continue;
}
! if (*from == '>') { // process tokens
intoken = false;
! if (!strncmp(token, "div type=\"variant\" class=\"1\"", 28)) {
hide = true;
continue;
}
! else if (!strncmp(token, "/div", 4)) {
hide = false;
continue;
--- 55,127 ----
}
! char ThMLVariants::processText(SWBuf &text, const SWKey *key, const SWModule *module)
{
! if ( option == 0 || option == 1) { //we want primary or variant only
bool intoken = false;
bool hide = false;
! SWBuf token;
! SWBuf orig = text;
! const char *from = orig.c_str();
! //we use a fixed comparision string to make sure the loop is as fast as the original two blocks with almost the same code
! const char* variantCompareString = (option == 0) ? "div type=\"variant\" class=\"1\"" : "div type=\"variant\" class=\"2\"";
!
! for (text = ""; *from; from++) {
if (*from == '<') {
intoken = true;
! token = "";
continue;
}
! else if (*from == '>') { // process tokens
intoken = false;
!
! if ( !strncmp(token.c_str(), variantCompareString, 28)) { //only one of the variants, length of the two strings is 28 in both cases
! hide = true;
! continue;
}
! else if (!strncmp(token.c_str(), "/div", 4)) {
! hide = false;
! continue;
}
// if not a footnote token, keep token in text
if (!hide) {
! text += '<';
! text.append(token);
! text += '>';
}
continue;
}
if (intoken) {
! token += *from;
}
! else if (!hide) {
! text += *from;
}
}
}
! /* else if (option == 1) { //we want variant only
bool intoken = false;
bool hide = false;
! SWBuf token;
! SWBuf orig = text;
! const char *from = orig.c_str();
! for (text = ""; *from; from++) {
if (*from == '<') {
intoken = true;
! token = "";
continue;
}
! else if (*from == '>') { // process tokens
intoken = false;
! if (!strncmp(token.c_str(), "div type=\"variant\" class=\"1\"", 28)) {
hide = true;
continue;
}
! else if (!strncmp(token.c_str(), "/div", 4)) {
hide = false;
continue;
***************
*** 155,180 ****
// if not a footnote token, keep token in text
if (!hide) {
! *to++ = '<';
! for (char *tok = token; *tok; tok++)
! *to++ = *tok;
! *to++ = '>';
}
continue;
}
if (intoken) {
! if (tokpos < 2045)
! token[tokpos++] = *from;
! token[tokpos+2] = 0;
}
! else {
! if (!hide) {
! *to++ = *from;
! }
}
}
- *to++ = 0;
- *to = 0;
-
}
return 0;
}
--- 130,149 ----
// if not a footnote token, keep token in text
if (!hide) {
! text += '<';
! text.append( token );
! text += '>';
}
continue;
}
if (intoken) {
! token += *from;
}
! else if (!hide) {
! text += *from;
}
}
}
+ */
+
return 0;
}