diff options
Diffstat (limited to 'src/mgr/swlocale.cpp')
-rw-r--r-- | src/mgr/swlocale.cpp | 104 |
1 files changed, 43 insertions, 61 deletions
diff --git a/src/mgr/swlocale.cpp b/src/mgr/swlocale.cpp index facb1ee..3d09313 100644 --- a/src/mgr/swlocale.cpp +++ b/src/mgr/swlocale.cpp @@ -2,7 +2,7 @@ * swlocale.cpp - implementation of Class SWLocale used for retrieval * of locale lookups * - * $Id: swlocale.cpp 1864 2005-11-20 06:06:40Z scribe $ + * $Id: swlocale.cpp 2346 2009-04-27 01:53:58Z scribe $ * * Copyright 2000 CrossWire Bible Society (http://www.crosswire.org) * CrossWire Bible Society @@ -25,29 +25,42 @@ #include <map> #include <swconfig.h> #include <versekey.h> +#include <versemgr.h> SWORD_NAMESPACE_START typedef std::map < SWBuf, SWBuf, std::less < SWBuf > >LookupMap; +const char *SWLocale::DEFAULT_LOCALE_NAME="en_US"; + // I have bridge patterns, but this hides swconfig and map from lots o stuff class SWLocale::Private { public: LookupMap lookupTable; + LookupMap mergedAbbrevs; }; -SWLocale::SWLocale(const char * ifilename) { +SWLocale::SWLocale(const char *ifilename) { p = new Private; ConfigEntMap::iterator confEntry; - name = 0; - description = 0; - encoding = 0; - bookAbbrevs = 0; - BMAX = 0; - books = 0; - localeSource = new SWConfig(ifilename); + name = 0; + description = 0; + encoding = 0; + bookAbbrevs = 0; + bookLongNames = 0; + bookPrefAbbrev = 0; + if (ifilename) { + localeSource = new SWConfig(ifilename); + } + else { + localeSource = new SWConfig(0); + (*localeSource)["Meta"]["Name"] = DEFAULT_LOCALE_NAME; + (*localeSource)["Meta"]["Description"] = "English (US)"; + bookAbbrevs = (struct abbrev *)builtin_abbrevs; + for (abbrevsCnt = 0; builtin_abbrevs[abbrevsCnt].osis[0]; abbrevsCnt++); + } confEntry = localeSource->Sections["Meta"].find("Name"); if (confEntry != localeSource->Sections["Meta"].end()) @@ -76,15 +89,9 @@ SWLocale::~SWLocale() { if (name) delete [] name; - if (bookAbbrevs) + if (bookAbbrevs != builtin_abbrevs) delete [] bookAbbrevs; - if (BMAX) { - for (int i = 0; i < 2; i++) - delete [] books[i]; - delete [] BMAX; - delete [] books; - } delete p; } @@ -145,60 +152,35 @@ void SWLocale::augment(SWLocale &addFrom) { *localeSource += *addFrom.localeSource; } -//#define NONNUMERICLOCALETHING 1 -const struct abbrev *SWLocale::getBookAbbrevs() { +const struct abbrev *SWLocale::getBookAbbrevs(int *retSize) { static const char *nullstr = ""; if (!bookAbbrevs) { - ConfigEntMap::iterator it; - int i, j; - int size = localeSource->Sections["Book Abbrevs"].size(); + // Assure all english abbrevs are present + for (int j = 0; builtin_abbrevs[j].osis[0]; j++) { + p->mergedAbbrevs[builtin_abbrevs[j].ab] = builtin_abbrevs[j].osis; + } + ConfigEntMap::iterator it = localeSource->Sections["Book Abbrevs"].begin(); + ConfigEntMap::iterator end = localeSource->Sections["Book Abbrevs"].end(); + for (; it != end; it++) { + p->mergedAbbrevs[it->first.c_str()] = it->second.c_str(); + } + int size = p->mergedAbbrevs.size(); bookAbbrevs = new struct abbrev[size + 1]; - for (i = 0, j = 0, it = localeSource->Sections["Book Abbrevs"].begin(); it != localeSource->Sections["Book Abbrevs"].end(); it++, i++) { - #ifdef NONNUMERICLOCALETHING - int booknum = VerseKey::getOSISBookNum((*it).second.c_str()); - if (booknum != -1) { - bookAbbrevs[j].ab = (*it).first.c_str(); - bookAbbrevs[j].book = booknum; - j++; - } - #else - bookAbbrevs[i].ab = (*it).first.c_str(); - bookAbbrevs[i].book = atoi((*it).second.c_str()); - j++; - #endif - //printf("SWLocale::getBookAbbrevs %s:%s %d\n",bookAbbrevs[i].ab, - // (*it).second.c_str(), bookAbbrevs[i].book); + int i = 0; + for (LookupMap::iterator it = p->mergedAbbrevs.begin(); it != p->mergedAbbrevs.end(); it++, i++) { + bookAbbrevs[i].ab = it->first.c_str(); + bookAbbrevs[i].osis = it->second.c_str(); } - bookAbbrevs[j].ab = nullstr; - bookAbbrevs[j].book = -1; + + bookAbbrevs[i].ab = nullstr; + bookAbbrevs[i].osis = nullstr; + abbrevsCnt = size; } + *retSize = abbrevsCnt; return bookAbbrevs; } -void SWLocale::getBooks(char **iBMAX, struct sbook ***ibooks) { - if (!BMAX) { - BMAX = new char [2]; - BMAX[0] = VerseKey::builtin_BMAX[0]; - BMAX[1] = VerseKey::builtin_BMAX[1]; - - books = new struct sbook *[2]; - books[0] = new struct sbook[BMAX[0]]; - books[1] = new struct sbook[BMAX[1]]; - - for (int i = 0; i < 2; i++) { - for (int j = 0; j < BMAX[i]; j++) { - books[i][j] = VerseKey::builtin_books[i][j]; - books[i][j].name = translate(VerseKey::builtin_books[i][j].name); - } - } - } - - *iBMAX = BMAX; - *ibooks = books; -} - - SWORD_NAMESPACE_END |