char OSISXHTMLXS::processText(SWBuf &text, const SWKey *key, const SWModule *module) { char *from; char token[4096]; int tokpos = 0; bool intoken = false; bool inEsc = false; SWBuf lastTextNode; MyUserDataXS *userData = (MyUserDataXS *)createUserData(module, key); SWBuf orig = text; from = orig.getRawData(); text = ""; for (;*from; from++) { if (*from == '<') { intoken = true; tokpos = 0; token[0] = 0; token[1] = 0; token[2] = 0; inEsc = false; continue; } if (*from == '&') { intoken = true; tokpos = 0; token[0] = 0; token[1] = 0; token[2] = 0; inEsc = true; continue; } if (inEsc) { if (*from == ';') { intoken = inEsc = false; userData->lastTextNode = lastTextNode; if (!userData->suspendTextPassThru) { //if text through is disabled no tokens should pass, too handleEscapeString(text, token, userData); } lastTextNode = ""; continue; } } if (!inEsc) { if (*from == '>') { intoken = false; userData->lastTextNode = lastTextNode; handleToken(text, token, userData); lastTextNode = ""; continue; } } if (intoken) { if (tokpos < 4090) { token[tokpos++] = *from; token[tokpos+2] = 0; } } else { if ((!userData->supressAdjacentWhitespace) || (*from != ' ')) { if (!userData->suspendTextPassThru) { text.append(*from); userData->lastSuspendSegment.size(0); } else userData->lastSuspendSegment.append(*from); lastTextNode.append(*from); } userData->supressAdjacentWhitespace = false; } } // THE MAIN PURPOSE OF THIS OVERRIDE FUNCTION: is to insure all opened HTML tags are closed while (!userData->htmlTagStack->empty()) { text.append((SWBuf)"</" + userData->htmlTagStack->top().c_str() + ">"); userData->htmlTagStack->pop(); } delete userData; return 0; }
char SWBasicFilter::processText(std::string &text, const SWKey *key, const SWModule *module) { char *from; char token[4096]; int tokpos = 0; bool intoken = false; bool inEsc = false; int escStartPos = 0, escEndPos = 0; int tokenStartPos = 0, tokenEndPos = 0; std::string lastTextNode; BasicFilterUserData *userData = createUserData(module, key); std::string orig = text; from = &orig[0u]; text = ""; if (processStages & INITIALIZE) { if (processStage(INITIALIZE, text, from, userData)) { // processStage handled it all delete userData; return 0; } } for (;*from; from++) { if (processStages & PRECHAR) { if (processStage(PRECHAR, text, from, userData)) // processStage handled this char continue; } if (*from == tokenStart[tokenStartPos]) { if (tokenStartPos == (tokenStartLen - 1)) { intoken = true; tokpos = 0; token[0] = 0; token[1] = 0; token[2] = 0; inEsc = false; } else tokenStartPos++; continue; } if (*from == escStart[escStartPos]) { if (escStartPos == (escStartLen - 1)) { intoken = true; tokpos = 0; token[0] = 0; token[1] = 0; token[2] = 0; inEsc = true; } else escStartPos++; continue; } if (inEsc) { if (*from == escEnd[escEndPos]) { if (escEndPos == (escEndLen - 1)) { intoken = inEsc = false; userData->lastTextNode = lastTextNode; if (!userData->suspendTextPassThru) { //if text through is disabled no tokens should pass, too if ((!handleEscapeString(text, token, userData)) && (passThruUnknownEsc)) { appendEscapeString(text, token); } } escEndPos = escStartPos = tokenEndPos = tokenStartPos = 0; lastTextNode = ""; continue; } } } if (!inEsc) { if (*from == tokenEnd[tokenEndPos]) { if (tokenEndPos == (tokenEndLen - 1)) { intoken = false; userData->lastTextNode = lastTextNode; if ((!handleToken(text, token, userData)) && (passThruUnknownToken)) { text += tokenStart; text += token; text += tokenEnd; } escEndPos = escStartPos = tokenEndPos = tokenStartPos = 0; lastTextNode = ""; continue; } } } if (intoken) { if (tokpos < 4090) { token[tokpos++] = *from; token[tokpos+2] = 0; } } else { if ((!userData->supressAdjacentWhitespace) || (*from != ' ')) { if (!userData->suspendTextPassThru) { text.push_back(*from); userData->lastSuspendSegment.clear(); } else userData->lastSuspendSegment.push_back(*from); lastTextNode.push_back(*from); } userData->supressAdjacentWhitespace = false; } if (processStages & POSTCHAR) processStage(POSTCHAR, text, from, userData); } if (processStages & FINALIZE) processStage(FINALIZE, text, from, userData); delete userData; return 0; }