Add GNU LGPL headers to all .c .C and .h files
[oweals/cde.git] / cde / programs / nsgmls / UnivCharsetDesc.C
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: UnivCharsetDesc.C /main/1 1996/07/29 17:07:43 cde-hp $ */
24 // Copyright (c) 1994 James Clark
25 // See the file COPYING for copying permission.
26
27 #ifdef __GNUG__
28 #pragma implementation
29 #endif
30 #include "splib.h"
31 #include "UnivCharsetDesc.h"
32 #include "macros.h"
33 #include "constant.h"
34
35 #ifdef SP_NAMESPACE
36 namespace SP_NAMESPACE {
37 #endif
38
39 UnivCharsetDesc::UnivCharsetDesc()
40 {
41 }
42
43 UnivCharsetDesc::UnivCharsetDesc(const Range *p, size_t n)
44 {
45   set(p, n);
46 }
47
48 void UnivCharsetDesc::set(const Range *p, size_t n)
49 {
50   for (size_t i = 0; i < n; i++) {
51     const Range &r = p[i];
52     WideChar max;
53     if (r.count > wideCharMax || r.descMin > wideCharMax - r.count)
54       max = wideCharMax;
55     else
56       max = r.descMin + (r.count - 1);
57     if (max - r.descMin > univCharMax
58         || r.univMin > univCharMax - (max - r.descMin))
59       max = r.descMin + (univCharMax - r.univMin);
60     descToUniv_.addRange(r.descMin, max, r.univMin);
61   }
62 }
63
64 void UnivCharsetDesc::addBaseRange(const UnivCharsetDesc &baseSet,
65                                    WideChar descMin,
66                                    WideChar descMax,
67                                    WideChar baseMin,
68                                    ISet<WideChar> &baseMissing)
69 {
70   UnivCharsetDescIter iter(baseSet);
71   WideChar baseMax = baseMin + (descMax - descMin);
72   WideChar iDescMin, iDescMax;
73   UnivChar iBaseMin;
74   WideChar missingBaseMin = baseMin;
75   Boolean usedAll = 0;
76   while (iter.next(iDescMin, iDescMax, iBaseMin) && iDescMin <= baseMax) {
77     //  baseMin   baseMax
78     //          iDescMin iDescMax
79     if (iDescMax >= baseMin) {
80       WideChar min = baseMin > iDescMin ? baseMin : iDescMin;
81       if (min > missingBaseMin)
82         baseMissing.addRange(missingBaseMin, min - 1);
83       WideChar max = baseMax < iDescMax ? baseMax : iDescMax;
84       missingBaseMin = max + 1;
85       if (missingBaseMin == 0)
86         usedAll = 1;
87       ASSERT(min <= max);
88       descToUniv_.addRange(descMin + (min - baseMin),
89                            descMin + (max - baseMin),
90                            iBaseMin + (min - iDescMin));
91     }
92   }
93   if (!usedAll && baseMax >= missingBaseMin)
94     baseMissing.addRange(missingBaseMin, baseMax);
95 }
96
97 #ifdef SP_NAMESPACE
98 }
99 #endif