aboutsummaryrefslogtreecommitdiffstats
path: root/src/keys
diff options
context:
space:
mode:
Diffstat (limited to 'src/keys')
-rw-r--r--src/keys/listkey.cpp18
-rw-r--r--src/keys/swkey.cpp34
-rw-r--r--src/keys/versekey.cpp75
3 files changed, 90 insertions, 37 deletions
diff --git a/src/keys/listkey.cpp b/src/keys/listkey.cpp
index 0d1ff33..a8afd93 100644
--- a/src/keys/listkey.cpp
+++ b/src/keys/listkey.cpp
@@ -255,3 +255,21 @@ void ListKey::Remove() {
SetToElement((arraypos)?arraypos-1:0);
}
}
+
+
+/******************************************************************************
+ * VerseKey::getRangeText - returns parsable range text for this key
+ */
+
+const char *ListKey::getRangeText() const {
+ char *buf = new char[(arraycnt + 1) * 255];
+ buf[0] = 0;
+ for (int i = 0; i < arraycnt; i++) {
+ strcat(buf, array[i]->getRangeText());
+ if (i < arraycnt-1)
+ strcat(buf, "; ");
+ }
+ stdstr(&rangeText, buf);
+ return rangeText;
+}
+
diff --git a/src/keys/swkey.cpp b/src/keys/swkey.cpp
index 307e848..f2491c4 100644
--- a/src/keys/swkey.cpp
+++ b/src/keys/swkey.cpp
@@ -19,21 +19,23 @@ SWClass SWKey::classdef(classes);
SWKey::SWKey(const char *ikey)
{
- index = 0;
- persist = 0;
- keytext = 0;
- error = 0;
+ index = 0;
+ persist = 0;
+ keytext = 0;
+ rangeText = 0;
+ error = 0;
stdstr(&keytext, ikey);
init();
}
SWKey::SWKey(SWKey const &k)
{
- index = k.index;
- persist = k.persist;
- userData = k.userData;
- keytext = 0;
- error = k.error;
+ index = k.index;
+ persist = k.persist;
+ userData = k.userData;
+ keytext = 0;
+ rangeText = 0;
+ error = k.error;
stdstr(&keytext, k.keytext);
init();
}
@@ -54,6 +56,8 @@ SWKey *SWKey::clone() const
SWKey::~SWKey() {
if (keytext)
delete [] keytext;
+ if (rangeText)
+ delete [] rangeText;
}
@@ -130,7 +134,7 @@ void SWKey::copyFrom(const SWKey &ikey) {
/******************************************************************************
- * SWKey::getText - returns text key if (char *) cast is requested
+ * SWKey::getText - returns text key if (const char *) cast is requested
*/
const char *SWKey::getText() const {
@@ -139,6 +143,16 @@ const char *SWKey::getText() const {
/******************************************************************************
+ * SWKey::getRangeText - returns parsable range text for this key
+ */
+
+const char *SWKey::getRangeText() const {
+ stdstr(&rangeText, keytext);
+ return rangeText;
+}
+
+
+/******************************************************************************
* SWKey::compare - Compares another VerseKey object
*
* ENT: ikey - key to compare with this one
diff --git a/src/keys/versekey.cpp b/src/keys/versekey.cpp
index 484e5ce..8773298 100644
--- a/src/keys/versekey.cpp
+++ b/src/keys/versekey.cpp
@@ -310,34 +310,39 @@ void VerseKey::freshtext() const
int VerseKey::getBookAbbrev(const char *iabbr)
{
- int loop, diff, abLen, min, max, target, retVal = -1;
-
- char *abbr = 0;
-
- stdstr(&abbr, iabbr);
- strstrip(abbr);
- toupperstr(abbr);
- abLen = strlen(abbr);
-
- if (abLen) {
- min = 0;
-// max = abbrevsCnt - 1;
- max = abbrevsCnt;
- while(1) {
- target = min + ((max - min) / 2);
- diff = strncmp(abbr, abbrevs[target].ab, abLen);
- if ((!diff)||(target >= max)||(target <= min))
- break;
- if (diff > 0)
- min = target;
- else max = target;
- }
- for (; target > 0; target--) {
- if (strncmp(abbr, abbrevs[target-1].ab, abLen))
- break;
+ int loop, diff, abLen, min, max, target, retVal = -1;
+
+ char *abbr = 0;
+
+ for (int i = 0; i < 2; i++) {
+ stdstr(&abbr, iabbr);
+ strstrip(abbr);
+ if (!i)
+ toupperstr(abbr);
+ abLen = strlen(abbr);
+
+ if (abLen) {
+ min = 0;
+// max = abbrevsCnt - 1;
+ max = abbrevsCnt;
+ while(1) {
+ target = min + ((max - min) / 2);
+ diff = strncmp(abbr, abbrevs[target].ab, abLen);
+ if ((!diff)||(target >= max)||(target <= min))
+ break;
+ if (diff > 0)
+ min = target;
+ else max = target;
+ }
+ for (; target > 0; target--) {
+ if (strncmp(abbr, abbrevs[target-1].ab, abLen))
+ break;
+ }
+
+ retVal = (!diff) ? abbrevs[target].book : -1;
}
-
- retVal = (!diff) ? abbrevs[target].book : -1;
+ if (retVal > 0)
+ break;
}
delete [] abbr;
return retVal;
@@ -1454,3 +1459,19 @@ const char *VerseKey::getOSISRef() const {
else sprintf(buf[loop], "");
return buf[loop++];
}
+
+
+/******************************************************************************
+ * VerseKey::getRangeText - returns parsable range text for this key
+ */
+
+const char *VerseKey::getRangeText() const {
+ if ((upperBound) && (lowerBound)) {
+ char buf[1023];
+ sprintf(buf, "%s-%s", (const char *)lowerBound, (const char *)upperBound);
+ stdstr(&rangeText, buf);
+ }
+ else stdstr(&rangeText, getText());
+ return rangeText;
+}
+