1 /* $XConsortium: CharsetRegistry.C /main/1 1996/07/29 16:47:29 cde-hp $ */
2 // Copyright (c) 1994 James Clark
3 // See the file COPYING for copying permission.
9 #include "CharsetRegistry.h"
10 #include "ExternalId.h"
11 #include "CharsetInfo.h"
12 #include "UnivCharsetDesc.h"
18 namespace SP_NAMESPACE {
21 static UnivCharsetDesc::Range iso646_irv[] = {
25 static UnivCharsetDesc::Range iso646_C0[] = {
32 const UnivCharsetDesc::Range *ranges;
35 { "ESC 2/5 4/0", iso646_irv, SIZEOF(iso646_irv) },
36 { "ESC 2/8 4/0", iso646_irv, SIZEOF(iso646_irv) },
37 { "ESC 2/8 4/2", iso646_irv, SIZEOF(iso646_irv) }, // ASCII
38 { "ESC 2/1 4/0", iso646_C0, SIZEOF(iso646_C0) },
41 Boolean CharsetRegistry::findCharset(const PublicId &id,
42 const CharsetInfo &charset,
43 UnivCharsetDesc &desc)
45 PublicId::OwnerType ownerType;
46 if (!id.getOwnerType(ownerType) || ownerType != PublicId::ISO)
49 if (!id.getDesignatingSequence(sequence))
51 // Canonicalize the escape sequence by mapping esc -> ESC,
52 // removing leading zeros from escape sequences, and removing
56 for (i = 0; i < sequence.size(); i++) {
58 if (c == charset.execToDesc('e'))
59 s += charset.execToDesc('E');
60 else if (c == charset.execToDesc('s'))
61 s += charset.execToDesc('S');
62 else if (c == charset.execToDesc('c'))
63 s += charset.execToDesc('C');
64 else if (charset.digitWeight(c) >= 0
66 && s[s.size() - 1] == charset.execToDesc('0')
68 || charset.digitWeight(s[s.size() - 2]) >= 0))
70 else if (c != charset.execToDesc(' ') || s.size() > 0)
73 for (i = 0; i < SIZEOF(table); i++)
74 if (s == charset.execToDesc(table[i].sequence)) {
75 desc.set(table[i].ranges, table[i].nRanges);