summaryrefslogtreecommitdiffstats
path: root/util/unicode
diff options
context:
space:
mode:
authorRitt Konstantin <ritt.ks@gmail.com>2010-02-24 19:13:32 (GMT)
committerThiago Macieira <thiago.macieira@nokia.com>2010-03-05 15:58:08 (GMT)
commitf87056c6e58dd691f15967067c6faac29f912bfd (patch)
tree03d50a8d5ce2e18f8affa40b2efc773063062ec4 /util/unicode
parentae9f34db6c59c2446513a7ba81da220ac9db38c7 (diff)
downloadQt-f87056c6e58dd691f15967067c6faac29f912bfd.zip
Qt-f87056c6e58dd691f15967067c6faac29f912bfd.tar.gz
Qt-f87056c6e58dd691f15967067c6faac29f912bfd.tar.bz2
use QHash for age map
to be consistent with other maps Merge-request: 480 Reviewed-by: Thiago Macieira <thiago.macieira@nokia.com>
Diffstat (limited to 'util/unicode')
-rw-r--r--util/unicode/main.cpp55
1 files changed, 29 insertions, 26 deletions
diff --git a/util/unicode/main.cpp b/util/unicode/main.cpp
index bbcd286..2c80e0e 100644
--- a/util/unicode/main.cpp
+++ b/util/unicode/main.cpp
@@ -55,21 +55,31 @@
#define LAST_CODEPOINT 0x10ffff
-static struct AgeMap {
- const char *age;
- const QChar::UnicodeVersion version;
-} ageMap[] = {
- { "1.1", QChar::Unicode_1_1 },
- { "2.0", QChar::Unicode_2_0 },
- { "2.1", QChar::Unicode_2_1_2 },
- { "3.0", QChar::Unicode_3_0 },
- { "3.1", QChar::Unicode_3_1 },
- { "3.2", QChar::Unicode_3_2 },
- { "4.0", QChar::Unicode_4_0 },
- { "4.1", QChar::Unicode_4_1 },
- { "5.0", QChar::Unicode_5_0 },
- { 0, QChar::Unicode_Unassigned }
-};
+static QHash<QByteArray, QChar::UnicodeVersion> age_map;
+
+static void initAgeMap()
+{
+ struct AgeMap {
+ const QChar::UnicodeVersion version;
+ const char *age;
+ } ageMap[] = {
+ { QChar::Unicode_1_1, "1.1" },
+ { QChar::Unicode_2_0, "2.0" },
+ { QChar::Unicode_2_1_2, "2.1" },
+ { QChar::Unicode_3_0, "3.0" },
+ { QChar::Unicode_3_1, "3.1" },
+ { QChar::Unicode_3_2, "3.2" },
+ { QChar::Unicode_4_0, "4.0" },
+ { QChar::Unicode_4_1, "4.1" },
+ { QChar::Unicode_5_0, "5.0" },
+ { QChar::Unicode_Unassigned, 0 }
+ };
+ AgeMap *d = ageMap;
+ while (d->age) {
+ age_map.insert(d->age, d->version);
+ ++d;
+ }
+}
static const char *grapheme_break_string =
@@ -822,18 +832,10 @@ static void readDerivedAge()
if (cl.size() == 2)
to = cl[1].toInt(&ok, 16);
- QChar::UnicodeVersion age = QChar::Unicode_Unassigned;
- QByteArray ba = l[1];
- AgeMap *map = ageMap;
- while (map->age) {
- if (ba == map->age) {
- age = map->version;
- break;
- }
- ++map;
- }
+ QChar::UnicodeVersion age = age_map.value(l[1].trimmed(), QChar::Unicode_Unassigned);
//qDebug() << hex << from << ".." << to << ba << age;
- Q_ASSERT(age != QChar::Unicode_Unassigned);
+ if (age == QChar::Unicode_Unassigned)
+ qFatal("unassigned or unhandled age value: %s", l[1].constData());
for (int codepoint = from; codepoint <= to; ++codepoint) {
UnicodeData d = unicodeData.value(codepoint, UnicodeData(codepoint));
@@ -2444,6 +2446,7 @@ QByteArray createCasingInfo()
int main(int, char **)
{
+ initAgeMap();
initCategoryMap();
initDirectionMap();
initDecompositionMap();