2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
6 * These libraries and programs are free software; you can
7 * redistribute them and/or modify them under the terms of the GNU
8 * Lesser General Public License as published by the Free Software
9 * Foundation; either version 2 of the License, or (at your option)
12 * These libraries and programs are distributed in the hope that
13 * they will be useful, but WITHOUT ANY WARRANTY; without even the
14 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU Lesser General Public License for more
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with these libraries and programs; if not, write
20 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21 * Floor, Boston, MA 02110-1301 USA
23 /* $XConsortium: CharsetInfo.C /main/1 1996/07/29 16:47:17 cde-hp $ */
24 // Copyright (c) 1994 James Clark
25 // See the file COPYING for copying permission.
28 #pragma implementation
31 #include "CharsetInfo.h"
36 namespace SP_NAMESPACE {
39 CharsetInfo::CharsetInfo(const UnivCharsetDesc &desc)
42 // FIXME remove mappings from desc for characters greater charMax
46 CharsetInfo::CharsetInfo()
48 for (size_t i = 0; i < nSmall; i++) {
49 smallUnivValid_[i] = 0;
50 smallDescValid_[i] = 0;
54 void CharsetInfo::set(const UnivCharsetDesc &desc)
60 void CharsetInfo::init()
63 for (i = 0; i < nSmall; i++) {
64 smallUnivValid_[i] = 0;
65 smallDescValid_[i] = 0;
68 UnivCharsetDescIter iter(desc_);
70 WideChar descMin, descMax;
72 while (iter.next(descMin, descMax, univMin)) {
75 UnivChar k = univMin + (j - descMin);
78 if (!smallUnivValid_[k]) {
79 smallUnivValid_[k] = 1;
80 smallUnivToDesc_[k] = j;
83 smallUnivValid_[k] = 2;
84 } while (j++ != descMax);
89 if (!smallDescValid_[j]) {
90 smallDescValid_[j] = 1;
91 smallDescToUniv_[j] = univMin + (j - descMin);
93 } while (j++ != descMax);
95 // These are the characters that the ANSI C
96 // standard guarantees will be in the basic execution
98 static char execChars[] =
100 "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
101 "abcdefghijklmnopqrstuvwxyz"
105 // These are the corresponding ISO 646 codes.
106 static char univCodes[] = {
108 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77,
109 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90,
110 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109,
111 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122,
112 48, 49, 50, 51, 52, 53, 54, 55, 56, 57,
113 33, 34, 35, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 58,
114 59, 60, 61, 62, 63, 91, 92, 93, 94, 95, 123, 124, 125, 126,
116 for (i = 0; execChars[i] != '\0'; i++) {
119 if (univToDesc(univCodes[i], c, set) > 0 && c <= Char(-1))
120 execToDesc_[(unsigned char)execChars[i]] = Char(c);
124 void CharsetInfo::getDescSet(ISet<Char> &set) const
126 UnivCharsetDescIter iter(desc_);
127 WideChar descMin, descMax;
129 while (iter.next(descMin, descMax, univMin)) {
130 if (descMin > charMax)
132 if (descMax > charMax)
134 set.addRange(Char(descMin), Char(descMax));
138 int CharsetInfo::digitWeight(Char c) const
140 for (int i = 0; i < 10; i++)
141 if (c == execToDesc('0' + i))
146 StringC CharsetInfo::execToDesc(const char *s) const
150 result += execToDesc(*s++);