Add GNU LGPL headers to all .c .C and .h files
[oweals/cde.git] / cde / programs / nsgmls / CharsetInfo.h
1 /*
2  * CDE - Common Desktop Environment
3  *
4  * Copyright (c) 1993-2012, The Open Group. All rights reserved.
5  *
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)
10  * any later version.
11  *
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
16  * details.
17  *
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
22  */
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.
26
27 #ifndef CharsetInfo_INCLUDED
28 #define CharsetInfo_INCLUDED 1
29 #ifdef __GNUG__
30 #pragma interface
31 #endif
32
33 #include <limits.h>
34 #include "UnivCharsetDesc.h"
35 #include "Boolean.h"
36 #include "types.h"
37 #include "StringC.h"
38 #include "ISet.h"
39
40 #ifdef SP_NAMESPACE
41 namespace SP_NAMESPACE {
42 #endif
43
44 class SP_API CharsetInfo {
45 public:
46   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
51   // character set.
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)
60        const;
61   unsigned univToDesc(UnivChar from, WideChar &to, ISet<WideChar> &toSet,
62                       WideChar &count)
63        const;
64   void getDescSet(ISet<Char> &) const;
65   int digitWeight(Char) const;
66   const UnivCharsetDesc &desc() const;
67 private:
68   void init();
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];
77 };
78
79 inline
80 unsigned CharsetInfo::univToDesc(UnivChar from, WideChar &to,
81                                  ISet<WideChar> &toSet)
82      const
83 {
84   if (from < nSmall && smallUnivValid_[from] <= 1) {
85     if (smallUnivValid_[from]) {
86       to = smallUnivToDesc_[from];
87       return 1;
88     }
89     else
90       return 0;
91   }
92   else
93     return desc_.univToDesc(from, to, toSet);
94 }
95
96 inline
97 Boolean CharsetInfo::descToUniv(UnivChar from, WideChar &to) const
98 {
99   if (from < nSmall) {
100     if (smallDescValid_[from]) {
101       to = smallDescToUniv_[from];
102       return 1;
103     }
104     else
105       return 0;
106   }
107   else
108     return desc_.descToUniv(from, to);
109 }
110
111 inline
112 Char CharsetInfo::execToDesc(char c) const
113 {
114   return execToDesc_[(unsigned char)c];
115 }
116
117 inline
118 Boolean CharsetInfo::descToUniv(WideChar from, UnivChar &to,
119                                 WideChar &alsoMax) const
120 {
121   return desc_.descToUniv(from, to, alsoMax);
122 }
123
124 inline
125 unsigned CharsetInfo::univToDesc(UnivChar from, WideChar &to,
126                                  ISet<WideChar> &toSet, WideChar &count)
127      const
128 {
129   return desc_.univToDesc(from, to, toSet, count);
130 }
131
132 inline
133 const UnivCharsetDesc &CharsetInfo::desc() const
134 {
135   return desc_;
136 }
137
138 #ifdef SP_NAMESPACE
139 }
140 #endif
141
142 #endif /* not CharsetInfo_INCLUDED */