~ubuntu-branches/debian/squeeze/sword/squeeze

« back to all changes in this revision

Viewing changes to src/mgr/swlocale.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Marsden, Jonathan Marsden, Dmitrijs Ledkovs, Closed Bugs
  • Date: 2009-05-30 11:55:55 UTC
  • mfrom: (1.3.1 upstream) (6.1.1 experimental)
  • Revision ID: james.westby@ubuntu.com-20090530115555-r427zsn3amivdpfu
Tags: 1.6.0+dfsg-1
[ Jonathan Marsden ]
* New upstream release. (Closes: #507960) (LP: #320558)
* debian/patches/02_libver.diff:
  - Bump SONAME to 8 -- SWORD 1.6 is not backward compatible with 1.5.11.
* debian/patches/series:
  - Remove 10_diatheke.diff -- included in upstream source.
* debian/patches/:
  - Remove several old unused .diff files.
  - Add 11_regex_only_when_needed.diff to conditionally include regex lib.
  - Add 12_fix_compiler_warnings.diff to remove all compiler warnings.
  - Add 13_fix_osis2mod_compression_default.diff from upstream svn.
  - Add 14_closing_section_not_chapter.diff from upstream svn.
* debian/libsword7.*: 
  - Rename to libsword8.*
  - Change libsword7 to libsword8 within files.
* debian/rules: 
  - SONAME bump to 8.
  - Set library version check to >= 1.6
* debian/control:
  - Change libsword7 to libsword8.
  - Add libsword7 to Conflicts.
  - Fix case of sword to SWORD in package descriptions.
  - Bump Standards-Version to 3.8.1 (no changes needed).
  - Fix section for libsword-dbg to avoid lintian warning.
* debian/rules:
  - Add DFSG get-orig-source target.
* debian/copyright:
  - Fix various mistakes in initial attempt to document copyrights.

[ Dmitrijs Ledkovs ]
* debian/rules: Added utils.mk to use missing-files target and call it on
  each build.
* debian/libsword-dev.install: Added libsword.la, previously missing.
* debian/libsword7.install: Added missing libicu translit files.
* debian/control:
  - Updated all uses of SWORD version to 1.6
  - Added libsword-dbg package
* debian/watch: Fixed a small mistake which was resulting in extra "."
  in final version name.
* debian/rules: simplified manpage processing.
* debian/libsword8.lintian-overrides: added override for module
  installation directory.
* debian/copyright: Updated with information about everyfile.
  Closes: #513448 LP: #322638
* debian/diatheke.examples: moved examples here from the diatheke.install
* debian/rules:
  - enabled shell script based testsuite
  - added commented out cppunit testsuite
* debian/patches/40_missing_includes.diff: 
  - added several missing stdio.h includes to prevent FTBFS of testsuite.

[ Closed Bugs ]
* FTBFS on intrepid (LP: #305172)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/******************************************************************************
 
2
 *  swlocale.cpp   - implementation of Class SWLocale used for retrieval
 
3
 *                              of locale lookups
 
4
 *
 
5
 * $Id: swlocale.cpp 2346 2009-04-27 01:53:58Z scribe $
 
6
 *
 
7
 * Copyright 2000 CrossWire Bible Society (http://www.crosswire.org)
 
8
 *      CrossWire Bible Society
 
9
 *      P. O. Box 2528
 
10
 *      Tempe, AZ  85280-2528
 
11
 *
 
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.
 
15
 *
 
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.
 
20
 *
 
21
 */
 
22
 
 
23
#include <swlocale.h>
 
24
#include <utilstr.h>
 
25
#include <map>
 
26
#include <swconfig.h>
 
27
#include <versekey.h>
 
28
#include <versemgr.h>
 
29
 
 
30
SWORD_NAMESPACE_START
 
31
 
 
32
typedef std::map < SWBuf, SWBuf, std::less < SWBuf > >LookupMap;
 
33
 
 
34
const char *SWLocale::DEFAULT_LOCALE_NAME="en_US";
 
35
 
 
36
// I have bridge patterns, but this hides swconfig and map from lots o stuff
 
37
class SWLocale::Private {
 
38
public:
 
39
        LookupMap lookupTable;
 
40
        LookupMap mergedAbbrevs;
 
41
};
 
42
 
 
43
 
 
44
SWLocale::SWLocale(const char *ifilename) {
 
45
        p = new Private;
 
46
        ConfigEntMap::iterator confEntry;
 
47
 
 
48
        name           = 0;
 
49
        description    = 0;
 
50
        encoding       = 0;
 
51
        bookAbbrevs    = 0;
 
52
        bookLongNames  = 0;
 
53
        bookPrefAbbrev = 0;
 
54
        if (ifilename) {
 
55
                localeSource   = new SWConfig(ifilename);
 
56
        }
 
57
        else {
 
58
                localeSource   = new SWConfig(0);
 
59
                (*localeSource)["Meta"]["Name"] = DEFAULT_LOCALE_NAME;
 
60
                (*localeSource)["Meta"]["Description"] = "English (US)";
 
61
                bookAbbrevs = (struct abbrev *)builtin_abbrevs;
 
62
                for (abbrevsCnt = 0; builtin_abbrevs[abbrevsCnt].osis[0]; abbrevsCnt++);
 
63
        }
 
64
 
 
65
        confEntry = localeSource->Sections["Meta"].find("Name");
 
66
        if (confEntry != localeSource->Sections["Meta"].end())
 
67
                stdstr(&name, (*confEntry).second.c_str());
 
68
        
 
69
        confEntry = localeSource->Sections["Meta"].find("Description");
 
70
        if (confEntry != localeSource->Sections["Meta"].end())
 
71
                stdstr(&description, (*confEntry).second.c_str());
 
72
 
 
73
        confEntry = localeSource->Sections["Meta"].find("Encoding"); //Either empty (==Latin1) or UTF-8
 
74
        if (confEntry != localeSource->Sections["Meta"].end())
 
75
                stdstr(&encoding, (*confEntry).second.c_str());
 
76
}
 
77
 
 
78
 
 
79
SWLocale::~SWLocale() {
 
80
 
 
81
        delete localeSource;
 
82
 
 
83
        if (encoding)
 
84
                delete [] encoding;
 
85
        
 
86
        if (description)
 
87
                delete [] description;
 
88
 
 
89
        if (name)
 
90
                delete [] name;
 
91
 
 
92
        if (bookAbbrevs != builtin_abbrevs)
 
93
                delete [] bookAbbrevs;
 
94
 
 
95
        delete p;
 
96
}
 
97
 
 
98
 
 
99
const char *SWLocale::translate(const char *text) {
 
100
        LookupMap::iterator entry;
 
101
 
 
102
        entry = p->lookupTable.find(text);
 
103
 
 
104
        if (entry == p->lookupTable.end()) {
 
105
                ConfigEntMap::iterator confEntry;
 
106
                confEntry = localeSource->Sections["Text"].find(text);
 
107
                if (confEntry == localeSource->Sections["Text"].end())
 
108
                        p->lookupTable.insert(LookupMap::value_type(text, text));
 
109
                else {//valid value found
 
110
                        /*
 
111
                        - If Encoding==Latin1 and we have a StringHelper, convert to UTF-8
 
112
                        - If StringHelper present and Encoding is UTF-8, use UTF8
 
113
                        - If StringHelper not present and Latin1, use Latin1
 
114
                        - If StringHelper not present and UTF-8, no idea what to do. Should't happen
 
115
                        */
 
116
/*                      if (StringHelper::getSystemStringHelper()) {
 
117
                                if (!strcmp(encoding, "UTF-8")) {
 
118
                                        p->lookupTable.insert(LookupMap::value_type(text, (*confEntry).second.c_str()));
 
119
                                }
 
120
                                else { //latin1 expected, convert to UTF-8
 
121
                                        SWBuf t((*confEntry).second.c_str());
 
122
                                        t = StringHelper::getSystemStringHelper()->latin2unicode( t );
 
123
                                        
 
124
                                        p->lookupTable.insert(LookupMap::value_type(text, t.c_str()));
 
125
                                }
 
126
                        }
 
127
                        else { //no stringhelper, just insert. Nothing we can do*/
 
128
                                p->lookupTable.insert(LookupMap::value_type(text, (*confEntry).second.c_str()));
 
129
//                      }
 
130
                        
 
131
                }
 
132
                entry = p->lookupTable.find(text);
 
133
        }
 
134
        return (*entry).second.c_str();
 
135
}
 
136
 
 
137
 
 
138
const char *SWLocale::getName() {
 
139
        return name;
 
140
}
 
141
 
 
142
 
 
143
const char *SWLocale::getDescription() {
 
144
        return description;
 
145
}
 
146
 
 
147
const char *SWLocale::getEncoding() {
 
148
        return encoding;
 
149
}
 
150
 
 
151
void SWLocale::augment(SWLocale &addFrom) {
 
152
        *localeSource += *addFrom.localeSource;
 
153
}
 
154
 
 
155
 
 
156
const struct abbrev *SWLocale::getBookAbbrevs(int *retSize) {
 
157
        static const char *nullstr = "";
 
158
        if (!bookAbbrevs) {
 
159
                // Assure all english abbrevs are present
 
160
                for (int j = 0; builtin_abbrevs[j].osis[0]; j++) {
 
161
                        p->mergedAbbrevs[builtin_abbrevs[j].ab] = builtin_abbrevs[j].osis;
 
162
                }
 
163
                ConfigEntMap::iterator it = localeSource->Sections["Book Abbrevs"].begin();
 
164
                ConfigEntMap::iterator end = localeSource->Sections["Book Abbrevs"].end();
 
165
                for (; it != end; it++) {
 
166
                        p->mergedAbbrevs[it->first.c_str()] = it->second.c_str();
 
167
                }
 
168
                int size = p->mergedAbbrevs.size();
 
169
                bookAbbrevs = new struct abbrev[size + 1];
 
170
                int i = 0;
 
171
                for (LookupMap::iterator it = p->mergedAbbrevs.begin(); it != p->mergedAbbrevs.end(); it++, i++) {
 
172
                        bookAbbrevs[i].ab = it->first.c_str();
 
173
                        bookAbbrevs[i].osis = it->second.c_str();
 
174
                }
 
175
 
 
176
                bookAbbrevs[i].ab = nullstr;
 
177
                bookAbbrevs[i].osis = nullstr;
 
178
                abbrevsCnt = size;
 
179
        }
 
180
                
 
181
        *retSize = abbrevsCnt;
 
182
        return bookAbbrevs;
 
183
}
 
184
 
 
185
 
 
186
SWORD_NAMESPACE_END