diff options
Diffstat (limited to 'src/keys/versekey.cpp')
-rw-r--r-- | src/keys/versekey.cpp | 111 |
1 files changed, 80 insertions, 31 deletions
diff --git a/src/keys/versekey.cpp b/src/keys/versekey.cpp index 25af540..84aa6ff 100644 --- a/src/keys/versekey.cpp +++ b/src/keys/versekey.cpp @@ -3,7 +3,7 @@ * versekey.cpp - code for class 'VerseKey'- a standard Biblical * verse key * - * $Id: versekey.cpp 3281 2014-12-03 06:07:22Z greg.hellings $ + * $Id: versekey.cpp 3439 2016-10-23 08:32:02Z scribe $ * * Copyright 1998-2013 CrossWire Bible Society (http://www.crosswire.org) * CrossWire Bible Society @@ -128,18 +128,55 @@ void VerseKey::setFromOther(const VerseKey &ikey) { chapter = ikey.getChapter(); verse = ikey.getVerse(); suffix = ikey.getSuffix(); - } - // TODO: versification mapping - // Here is where we will do v11n system conversions in the future - // when we have a conversion mechanism - // Ben Morgan has started thinking about this - // Konstantin Maslyuk <kalemas@mail.ru> has submitted a patch) - // Asked Konstantin to try his patch out with his favorite - // SWORD frontend and report back how it goes. Need to follow up - else { - // For now, this is the best we can do - setText(ikey.getText()); - } + } + else { + // map verse between systems + const char* map_book = ikey.getOSISBookName(); + int map_chapter = ikey.getChapter(); + int map_verse = ikey.getVerse(); + int map_range = map_verse; + + ikey.refSys->translateVerse(refSys, &map_book, &map_chapter, &map_verse, &map_range); + //printf("verse: %s.%i.%i-%i\n",map_book,map_chapter,map_verse,map_range); + + book = refSys->getBookNumberByOSISName(map_book); + + // check existence + if (book == -1) { + book = 1; + error = KEYERR_OUTOFBOUNDS; + } + else if (refSys->getBook(book-1)->getChapterMax() < map_chapter) { + map_chapter = refSys->getBook(book-1)->getChapterMax(); + map_verse = refSys->getBook(book-1)->getVerseMax(map_chapter); + error = KEYERR_OUTOFBOUNDS; + } + else if (map_chapter > 0 && refSys->getBook(book-1)->getVerseMax(map_chapter) < map_verse) { + map_verse = refSys->getBook(book-1)->getVerseMax(map_chapter); + error = KEYERR_OUTOFBOUNDS; + } + + // set values + if (book > BMAX[0]) + book -= BMAX[0], testament = 2; + else + testament = 1; + + //if (map_verse == 0) Headings(1); + + chapter = map_chapter; + verse = map_verse; + suffix = ikey.getSuffix(); + + if (map_verse < map_range) { + if (map_range > refSys->getBook(((testament>1)?BMAX[0]:0)+book-1)->getVerseMax(chapter)) + ++map_range; + verse = map_range; + setUpperBound(this); + verse = map_verse; + setLowerBound(this); + } + } } @@ -381,14 +418,14 @@ int VerseKey::getBookFromAbbrev(const char *iabbr) const if (!i) { if (hasUTF8Support) { //we have support for UTF-8 handling; we expect UTF-8 encoded locales - stringMgr->upperUTF8(abbr, strlen(abbr)*2); + stringMgr->upperUTF8(abbr, (unsigned int)(strlen(abbr)*2)); } else { stringMgr->upperLatin1(abbr); } } - abLen = strlen(abbr); + abLen = (int)strlen(abbr); if (abLen) { min = 0; @@ -446,7 +483,7 @@ void VerseKey::validateCurrentLocale() const { StringMgr* stringMgr = StringMgr::getSystemStringMgr(); const bool hasUTF8Support = StringMgr::hasUTF8Support(); if (hasUTF8Support) { //we have support for UTF-8 handling; we expect UTF-8 encoded locales - stringMgr->upperUTF8(abbr, strlen(abbr)*2); + stringMgr->upperUTF8(abbr, (unsigned int)(strlen(abbr)*2)); } else { stringMgr->upperLatin1(abbr); @@ -560,6 +597,7 @@ ListKey VerseKey::parseVerseList(const char *buf, const char *defaultKey, bool e comma = 0; break; } + goto terminate_range; // otherwise drop down to next case case ' ': inTerm = true; @@ -593,6 +631,7 @@ ListKey VerseKey::parseVerseList(const char *buf, const char *defaultKey, bool e } case ',': // on number new verse case ';': // on number new chapter +terminate_range: number[tonumber] = 0; tonumber = 0; if (*number) { @@ -605,7 +644,7 @@ ListKey VerseKey::parseVerseList(const char *buf, const char *defaultKey, bool e tobook = 0; bookno = -1; if (*book) { - loop = strlen(book) - 1; + loop = (int)strlen(book) - 1; for (; loop+1; loop--) { if (book[loop] == ' ') book[loop] = 0; else break; } @@ -628,7 +667,7 @@ ListKey VerseKey::parseVerseList(const char *buf, const char *defaultKey, bool e break; } - for (loop = strlen(book) - 1; loop+1; loop--) { + for (loop = (int)strlen(book) - 1; loop+1; loop--) { if (book[loop] == ' ') { // "PS C" is ok, but "II C" is not ok if (isroman(&book[loop+1]) && !isroman(book,loop)) { @@ -643,14 +682,14 @@ ListKey VerseKey::parseVerseList(const char *buf, const char *defaultKey, bool e } // check for special inscriptio and subscriptio which are saved as book intro and chap 1 intro (for INTF) - for (loop = strlen(book) - 1; loop+1; loop--) { + for (loop = (int)strlen(book) - 1; loop+1; loop--) { if (book[loop] == ' ') { - if (!strnicmp(&book[loop+1], "inscriptio", strlen(&book[loop+1]))) { + if (!strnicmp(&book[loop+1], "inscriptio", (int)strlen(&book[loop+1]))) { book[loop] = 0; verse = 0; chap = 0; } - else if (!strnicmp(&book[loop+1], "subscriptio", strlen(&book[loop+1]))) { + else if (!strnicmp(&book[loop+1], "subscriptio", (int)strlen(&book[loop+1]))) { book[loop] = 0; verse = 0; chap = 1; @@ -876,7 +915,7 @@ ListKey VerseKey::parseVerseList(const char *buf, const char *defaultKey, bool e book[tobook] = 0; tobook = 0; if (*book) { - loop = strlen(book) - 1; + loop = (int)strlen(book) - 1; // strip trailing spaces for (; loop+1; loop--) { if (book[loop] == ' ') book[loop] = 0; else break; } @@ -905,7 +944,7 @@ ListKey VerseKey::parseVerseList(const char *buf, const char *defaultKey, bool e } // check for roman numeral chapter - for (loop = strlen(book) - 1; loop+1; loop--) { + for (loop = (int)strlen(book) - 1; loop+1; loop--) { if (book[loop] == ' ') { // "PS C" is ok, but "II C" is not ok if (isroman(&book[loop+1]) && !isroman(book,loop)) { @@ -919,19 +958,19 @@ ListKey VerseKey::parseVerseList(const char *buf, const char *defaultKey, bool e } } // check for special inscriptio and subscriptio which are saved as book intro and chap 1 intro (for INTF) - for (loop = strlen(book) - 1; loop+1; loop--) { + for (loop = (int)strlen(book) - 1; loop+1; loop--) { if (book[loop] == ' ') { - if (!strnicmp(&book[loop+1], "inscriptio", strlen(&book[loop+1]))) { + if (!strnicmp(&book[loop+1], "inscriptio", (int)strlen(&book[loop+1]))) { book[loop] = 0; verse = 0; chap = 0; suffix = 0; } - else if (!strnicmp(&book[loop+1], "subscriptio", strlen(&book[loop+1]))) { + else if (!strnicmp(&book[loop+1], "subscriptio", (int)strlen(&book[loop+1]))) { book[loop] = 0; verse = 0; chap = 1; - suffix = 0; + suffix = 0; } break; } @@ -1391,6 +1430,11 @@ void VerseKey::normalize(bool autocheck) } if (chapter < (intros?0:1)) { --book; + if (book < (intros?0:1)) { + if (--testament > 0) { + book += (BMAX[testament-1] + (intros?1:0)); + } + } chapter += (getChapterMax() + (intros?1:0)); continue; } @@ -1404,6 +1448,11 @@ void VerseKey::normalize(bool autocheck) if (verse < (intros?0:1)) { if (--chapter < (intros?0:1)) { --book; + if (book < (intros?0:1)) { + if (--testament > 0) { + book += (BMAX[testament-1] + (intros?1:0)); + } + } chapter += (getChapterMax() + (intros?1:0)); } verse += (getVerseMax() + (intros?1:0)); @@ -1756,7 +1805,7 @@ int VerseKey::_compare(const VerseKey &ivkey) keyval1 += (int)getSuffix(); keyval2 += (int)ivkey.getSuffix(); keyval1 = (keyval1 != keyval2) ? ((keyval1 > keyval2) ? 1 : -1) : 0; // -1 | 0 | 1 - return keyval1; + return (int)keyval1; } @@ -1831,14 +1880,14 @@ const char *VerseKey::convertToOSIS(const char *inRef, const SWKey *lastKnownKey memset(frag, 0, 800); memset(preJunk, 0, 800); memset(postJunk, 0, 800); - while ((*startFrag) && (strchr(" {};,()[].", *startFrag))) { + while ((*startFrag) && (strchr(" {}:;,()[].", *startFrag))) { outRef += *startFrag; startFrag++; } - memmove(frag, startFrag, ((const char *)element->userData - startFrag) + 1); + memmove(frag, startFrag, (size_t)((const char *)element->userData - startFrag) + 1); frag[((const char *)element->userData - startFrag) + 1] = 0; int j; - for (j = strlen(frag)-1; j && (strchr(" {};,()[].", frag[j])); j--); + for (j = strlen(frag)-1; j && (strchr(" {}:;,()[].", frag[j])); j--); if (frag[j+1]) strcpy(postJunk, frag+j+1); frag[j+1]=0; |