1 // Copyright (c) 1994, 1997 James Clark
2 // See the file COPYING for copying permission.
8 #include "CharsetInfo.h"
13 namespace SP_NAMESPACE {
16 CharsetInfo::CharsetInfo(const UnivCharsetDesc &desc)
19 // FIXME remove mappings from desc for characters greater charMax
23 CharsetInfo::CharsetInfo()
25 inverse_.setAll(unsigned(-1));
28 void CharsetInfo::set(const UnivCharsetDesc &desc)
34 void CharsetInfo::init()
36 inverse_.setAll(Unsigned32(-1));
38 UnivCharsetDescIter iter(desc_);
40 WideChar descMin, descMax;
42 while (iter.next(descMin, descMax, univMin)) {
43 if (univMin <= charMax) {
45 if (charMax - univMin < descMax - descMin)
48 univMax = univMin + (descMax - descMin);
50 = ((descMin - univMin) & ((Unsigned32(1) << 31) - 1));
53 Unsigned32 n = inverse_.getRange(univMin, max);
56 if (n == Unsigned32(-1))
57 inverse_.setRange(univMin, max, diff);
58 else if (n != Unsigned32(-2))
59 inverse_.setRange(univMin, max, Unsigned32(-2));
66 // These are the characters that the ANSI C
67 // standard guarantees will be in the basic execution
69 static char execChars[] =
71 "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
72 "abcdefghijklmnopqrstuvwxyz"
76 // These are the corresponding ISO 646 codes.
77 static char univCodes[] = {
79 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77,
80 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90,
81 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109,
82 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122,
83 48, 49, 50, 51, 52, 53, 54, 55, 56, 57,
84 33, 34, 35, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 58,
85 59, 60, 61, 62, 63, 91, 92, 93, 94, 95, 123, 124, 125, 126,
87 for (size_t i = 0; execChars[i] != '\0'; i++) {
90 if (univToDesc(univCodes[i], c, set) > 0 && c <= charMax)
91 execToDesc_[(unsigned char)execChars[i]] = Char(c);
95 void CharsetInfo::getDescSet(ISet<Char> &set) const
97 UnivCharsetDescIter iter(desc_);
98 WideChar descMin, descMax;
100 while (iter.next(descMin, descMax, univMin)) {
101 if (descMin > charMax)
103 if (descMax > charMax)
105 set.addRange(Char(descMin), Char(descMax));
109 int CharsetInfo::digitWeight(Char c) const
111 for (int i = 0; i < 10; i++)
112 if (c == execToDesc('0' + i))
117 int CharsetInfo::hexDigitWeight(Char c) const
119 for (int i = 0; i < 10; i++)
120 if (c == execToDesc('0' + i))
122 for (int i = 0; i < 6; i++)
123 if (c == execToDesc('a' + i) || c == execToDesc('A' + i))
128 StringC CharsetInfo::execToDesc(const char *s) const
132 result += execToDesc(*s++);