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: CharsetRegistry.C /main/1 1996/07/29 16:47:29 cde-hp $ */
24 // Copyright (c) 1994 James Clark
25 // See the file COPYING for copying permission.
28 #pragma implementation
31 #include "CharsetRegistry.h"
32 #include "ExternalId.h"
33 #include "CharsetInfo.h"
34 #include "UnivCharsetDesc.h"
40 namespace SP_NAMESPACE {
43 static UnivCharsetDesc::Range iso646_irv[] = {
47 static UnivCharsetDesc::Range iso646_C0[] = {
54 const UnivCharsetDesc::Range *ranges;
57 { "ESC 2/5 4/0", iso646_irv, SIZEOF(iso646_irv) },
58 { "ESC 2/8 4/0", iso646_irv, SIZEOF(iso646_irv) },
59 { "ESC 2/8 4/2", iso646_irv, SIZEOF(iso646_irv) }, // ASCII
60 { "ESC 2/1 4/0", iso646_C0, SIZEOF(iso646_C0) },
63 Boolean CharsetRegistry::findCharset(const PublicId &id,
64 const CharsetInfo &charset,
65 UnivCharsetDesc &desc)
67 PublicId::OwnerType ownerType;
68 if (!id.getOwnerType(ownerType) || ownerType != PublicId::ISO)
71 if (!id.getDesignatingSequence(sequence))
73 // Canonicalize the escape sequence by mapping esc -> ESC,
74 // removing leading zeros from escape sequences, and removing
78 for (i = 0; i < sequence.size(); i++) {
80 if (c == charset.execToDesc('e'))
81 s += charset.execToDesc('E');
82 else if (c == charset.execToDesc('s'))
83 s += charset.execToDesc('S');
84 else if (c == charset.execToDesc('c'))
85 s += charset.execToDesc('C');
86 else if (charset.digitWeight(c) >= 0
88 && s[s.size() - 1] == charset.execToDesc('0')
90 || charset.digitWeight(s[s.size() - 2]) >= 0))
92 else if (c != charset.execToDesc(' ') || s.size() > 0)
95 for (i = 0; i < SIZEOF(table); i++)
96 if (s == charset.execToDesc(table[i].sequence)) {
97 desc.set(table[i].ranges, table[i].nRanges);