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 librararies 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.h /main/1 1996/07/29 16:47:24 cde-hp $ */
24 // Copyright (c) 1994 James Clark
25 // See the file COPYING for copying permission.
27 #ifndef CharsetInfo_INCLUDED
28 #define CharsetInfo_INCLUDED 1
34 #include "UnivCharsetDesc.h"
41 namespace SP_NAMESPACE {
44 class SP_API CharsetInfo {
47 CharsetInfo(const UnivCharsetDesc &);
48 void set(const UnivCharsetDesc &);
49 // Use only for characters guaranteed to me in the C basic execution
50 // character set and which have been verified to be in this
52 Char execToDesc(char) const;
53 StringC execToDesc(const char *s) const;
54 Boolean descToUniv(WideChar from, UnivChar &to) const;
55 Boolean descToUniv(WideChar from, UnivChar &to, WideChar &alsoMax) const;
56 // Return 0 for no matches, 1 for 1, 2 for more than 1
57 // to gets the first character; toSet gets all the characters
58 // if there's more than 1.
59 unsigned univToDesc(UnivChar from, WideChar &to, ISet<WideChar> &toSet)
61 unsigned univToDesc(UnivChar from, WideChar &to, ISet<WideChar> &toSet,
64 void getDescSet(ISet<Char> &) const;
65 int digitWeight(Char) const;
66 const UnivCharsetDesc &desc() const;
69 UnivCharsetDesc desc_;
70 enum { nSmall = 128 };
71 // 0 for no matches, 1 for 1, 2 for more than 1
72 unsigned smallUnivValid_[nSmall];
73 WideChar smallUnivToDesc_[nSmall];
74 PackedBoolean smallDescValid_[nSmall];
75 UnivChar smallDescToUniv_[nSmall];
76 Char execToDesc_[UCHAR_MAX + 1];
80 unsigned CharsetInfo::univToDesc(UnivChar from, WideChar &to,
81 ISet<WideChar> &toSet)
84 if (from < nSmall && smallUnivValid_[from] <= 1) {
85 if (smallUnivValid_[from]) {
86 to = smallUnivToDesc_[from];
93 return desc_.univToDesc(from, to, toSet);
97 Boolean CharsetInfo::descToUniv(UnivChar from, WideChar &to) const
100 if (smallDescValid_[from]) {
101 to = smallDescToUniv_[from];
108 return desc_.descToUniv(from, to);
112 Char CharsetInfo::execToDesc(char c) const
114 return execToDesc_[(unsigned char)c];
118 Boolean CharsetInfo::descToUniv(WideChar from, UnivChar &to,
119 WideChar &alsoMax) const
121 return desc_.descToUniv(from, to, alsoMax);
125 unsigned CharsetInfo::univToDesc(UnivChar from, WideChar &to,
126 ISet<WideChar> &toSet, WideChar &count)
129 return desc_.univToDesc(from, to, toSet, count);
133 const UnivCharsetDesc &CharsetInfo::desc() const
142 #endif /* not CharsetInfo_INCLUDED */