aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYour Name <you@example.com>2020-11-10 08:29:20 -0500
committerYour Name <you@example.com>2020-11-10 08:29:20 -0500
commit41cdb2d5e3f8e5f08b4933cbb9693ee4a6908580 (patch)
treeab3e84c50fbe6ec6887e642edc87d867731c6a85
parenta308af1cd84185989f1262ba66b01f6a9ceafa6a (diff)
downloadlibbible-41cdb2d5e3f8e5f08b4933cbb9693ee4a6908580.tar.gz
libbible-41cdb2d5e3f8e5f08b4933cbb9693ee4a6908580.tar.bz2
libbible-41cdb2d5e3f8e5f08b4933cbb9693ee4a6908580.zip
Fixed handling of paragraph symbol
-rw-r--r--libbible.cc42
-rw-r--r--modules/ESV2011.zipbin12087753 -> 0 bytes
-rw-r--r--modules/KJV.zipbin0 -> 4061008 bytes
-rw-r--r--testLibbible.cc30
4 files changed, 48 insertions, 24 deletions
diff --git a/libbible.cc b/libbible.cc
index c7f3f4c..92d6ee8 100644
--- a/libbible.cc
+++ b/libbible.cc
@@ -157,28 +157,34 @@ vector<libbible::text> libbible::getText(libbible::passage pass) {
for(; key->getChapter() < pass.chapterEnd ||
(key->getChapter() == pass.chapterEnd && key->getVerse() <= pass.verseEnd);
(*key)++) {
- texts.push_back(getEmptyText(key));
string text = string(target->renderText());
+ //printf("Processing text \"%s\"", text.c_str());
// Handle ¶ symbol if at beginning of line
- if(text.find("¶") == 0) {
- text.replace(0, 1, "\n");
+ /*if(text.find("¶") == 0) {
+ text.erase(0, 1);
+ // Append \n to text in previous texts (if applicable)
+ if(! texts.empty()) {
+ texts.back().text += '\n';
+ }
endOfParagraph = true;
- }
+ }*/
+
+ texts.push_back(getEmptyText(key));
- while(text[0] == ' ' || text[0] == '\t') {
- text.erase(0, 1);
- }
+ /* Things to enforce:
+ * 1. No whitespace at start of verse
+ */
// Find and replace everything in "subs" map
- const map<string, string> subs = {{"¶", "\n\t"}};
+ /*const map<string, string> subs = {{"¶", "\n\t"}};
for(auto const &repl : subs) {
string::size_type location;
while((location = text.find(repl.first)) != string::npos) {
text.replace(location, repl.first.size(), repl.second);
}
- }
+ }*/
if(key->getVerse() == 1 || endOfParagraph) {
if(find(texts.back().modifiers.begin(), texts.back().modifiers.end(), "paragraph") == texts.back().modifiers.end()) {
@@ -190,6 +196,7 @@ vector<libbible::text> libbible::getText(libbible::passage pass) {
// Variable to accumulate unterminated spans
std::vector<string> spans;
bool spansChanged = false;
+ bool hasAddedText = false;
// Iterate over text
for(auto i = text.begin(); i != text.end(); i++) {
if(*i != '<') {
@@ -204,7 +211,24 @@ vector<libbible::text> libbible::getText(libbible::passage pass) {
}
}
}
+ if(! hasAddedText && (*i == ' ' || *i == '\t')) {
+ continue;
+ }
+ if(*i == "¶"[0] && *(i+1) == "¶"[1]) {
+ i++;
+ if(hasAddedText) {
+ texts.back().text += '\n';
+ } else {
+ // Append \n to text in previous texts (if applicable)
+ if(texts.size() > 1) {
+ texts[texts.size()-2].text += '\n';
+ }
+ texts.back().modifiers.push_back("paragraph");
+ continue;
+ }
+ }
texts.back().text += *i;
+ hasAddedText = true;
}
else {
string span;
diff --git a/modules/ESV2011.zip b/modules/ESV2011.zip
deleted file mode 100644
index b037436..0000000
--- a/modules/ESV2011.zip
+++ /dev/null
Binary files differ
diff --git a/modules/KJV.zip b/modules/KJV.zip
new file mode 100644
index 0000000..27c161d
--- /dev/null
+++ b/modules/KJV.zip
Binary files differ
diff --git a/testLibbible.cc b/testLibbible.cc
index b06a0bd..3850aa0 100644
--- a/testLibbible.cc
+++ b/testLibbible.cc
@@ -53,20 +53,20 @@ void TestLibbible::testGetModules(void) {
libbible::uninstallMod(pair.first);
}
CPPUNIT_ASSERT(libbible::getModules().empty());
- libbible::installModFromZip("modules/ESV2011.zip");
+ libbible::installModFromZip("modules/KJV.zip");
libbible::installModFromZip("modules/JPS.zip");
mods = libbible::getModules();
- CPPUNIT_ASSERT(mods.find("ESV2011") != mods.end());
- CPPUNIT_ASSERT(mods["ESV2011"].size() == 66);
- CPPUNIT_ASSERT(mods["ESV2011"][7] == "Ruth");
- CPPUNIT_ASSERT(mods["ESV2011"][42] == "John");
+ CPPUNIT_ASSERT(mods.find("KJV") != mods.end());
+ CPPUNIT_ASSERT(mods["KJV"].size() == 66);
+ CPPUNIT_ASSERT(mods["KJV"][7] == "Ruth");
+ CPPUNIT_ASSERT(mods["KJV"][42] == "John");
CPPUNIT_ASSERT(mods.find("JPS") != mods.end());
CPPUNIT_ASSERT(mods["JPS"].size() == 39);
}
void TestLibbible::testGetPassages(void) {
- auto passages = libbible::getPassages("ESV2011", "Romans");
- CPPUNIT_ASSERT(passages[0].modName == "ESV2011");
+ auto passages = libbible::getPassages("KJV", "Romans");
+ CPPUNIT_ASSERT(passages[0].modName == "KJV");
CPPUNIT_ASSERT(passages[0].book == "Romans");
CPPUNIT_ASSERT(passages[0].bookShort == "Rom");
CPPUNIT_ASSERT(passages[0].chapterStart == 1);
@@ -94,7 +94,7 @@ vector<pair<int, int>> getChapVerses(std::vector<libbible::text> text) {
void TestLibbible::testGetText(void) {
libbible::passage pass;
- pass.modName = "ESV2011";
+ pass.modName = "KJV";
pass.bookShort = "Matt";
pass.chapterStart = 3;
pass.verseStart = 16;
@@ -114,7 +114,7 @@ void TestLibbible::testGetText(void) {
pair<int, int>(4, 7)});
CPPUNIT_ASSERT(chapVerses == shouldContain);
libbible::passage pass2;
- pass2.modName = "ESV2011";
+ pass2.modName = "KJV";
pass2.book = "John";
pass2.chapterStart = 3;
pass2.verseStart = 16;
@@ -126,27 +126,27 @@ void TestLibbible::testGetText(void) {
allText += tex.text;
}
//printf("Text is: `%s`\n", allText.c_str());
- CPPUNIT_ASSERT(allText == " “For God so loved the world, that he gave his only Son, that whoever believes in him should not perish but have eternal life. ");
+ CPPUNIT_ASSERT(allText == "For God so loved the world, that he gave his only begotten Son, that whosoever believeth in him should not perish, but have everlasting life. ");
- text = libbible::getText(libbible::passage{.modName = "ESV2011", .reference="John 3:3"});
+ text = libbible::getText(libbible::passage{.modName = "KJV", .reference="John 3:3"});
allText.clear();
for(auto tex : text) {
allText += tex.text;
}
//printf("Text is: `%s`\n", allText.c_str());
- CPPUNIT_ASSERT(allText == "Jesus answered him, “Truly, truly, I say to you, unless one is born again he cannot see the kingdom of God.” ");
+ CPPUNIT_ASSERT(allText == "Jesus answered and said unto him, Verily, verily, I say unto thee, Except a man be born again, he cannot see the kingdom of God. ");
- text = libbible::getText(libbible::passage{.modName = "ESV2011", .reference="Gal 5:22-23"});
+ text = libbible::getText(libbible::passage{.modName = "KJV", .reference="Gal 5:22-23"});
chapVerses = getChapVerses(text);
shouldContain = vector<pair<int, int>>({pair<int, int>(5, 22), pair<int, int>(5, 23)});
CPPUNIT_ASSERT(chapVerses == shouldContain);
- text = libbible::getText(libbible::passage{.modName = "ESV2011", .reference="1 cor 1:31-2:1"});
+ text = libbible::getText(libbible::passage{.modName = "KJV", .reference="1 cor 1:31-2:1"});
chapVerses = getChapVerses(text);
shouldContain = vector<pair<int, int>>({pair<int, int>(1, 31), pair<int, int>(2, 1)});
CPPUNIT_ASSERT(chapVerses == shouldContain);
- text = libbible::getText(libbible::passage{.modName = "ESV2011", .reference="ps 14-15"});
+ text = libbible::getText(libbible::passage{.modName = "KJV", .reference="ps 14-15"});
chapVerses = getChapVerses(text);
shouldContain = vector<pair<int, int>>({pair<int, int>(14, 1),
pair<int, int>(14, 2),