1
/******************************************************************************
3
* thmlvariants - SWFilter descendant to hide or show textual variants
7
* Copyright 2009 CrossWire Bible Society (http://www.crosswire.org)
8
* CrossWire Bible Society
10
* Tempe, AZ 85280-2528
12
* This program is free software; you can redistribute it and/or modify it
13
* under the terms of the GNU General Public License as published by the
14
* Free Software Foundation version 2.
16
* This program is distributed in the hope that it will be useful, but
17
* WITHOUT ANY WARRANTY; without even the implied warranty of
18
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19
* General Public License for more details.
24
#include <thmlvariants.h>
29
const char ThMLVariants::primary[] = "Primary Reading";
30
const char ThMLVariants::secondary[] = "Secondary Reading";
31
const char ThMLVariants::all[] = "All Readings";
33
const char ThMLVariants::optName[] = "Textual Variants";
34
const char ThMLVariants::optTip[] = "Switch between Textual Variants modes";
37
ThMLVariants::ThMLVariants() {
39
options.push_back(primary);
40
options.push_back(secondary);
41
options.push_back(all);
45
ThMLVariants::~ThMLVariants() {
48
void ThMLVariants::setOptionValue(const char *ival)
50
if (!stricmp(ival, primary)) option = 0;
51
else if (!stricmp(ival, secondary)) option = 1;
55
const char *ThMLVariants::getOptionValue()
60
else if (option == 1) {
68
char ThMLVariants::processText(SWBuf &text, const SWKey *key, const SWModule *module)
70
if ( option == 0 || option == 1) { //we want primary or variant only
77
const char *from = orig.c_str();
79
//we use a fixed comparision string to make sure the loop is as fast as the original two blocks with almost the same code
80
const char* variantCompareString = (option == 0) ? "div type=\"variant\" class=\"1\"" : "div type=\"variant\" class=\"2\"";
82
for (text = ""; *from; from++) {
88
else if (*from == '>') { // process tokens
91
if ( !strncmp(token.c_str(), variantCompareString, 28)) { //only one of the variants, length of the two strings is 28 in both cases
96
if (!strncmp(token.c_str(), "div type=\"variant\"", 18)) {
100
if (!strncmp(token.c_str(), "/div", 4)) {