1 : /*
2 : * Copyright (c) 2008-2010 Mozilla Foundation
3 : *
4 : * Permission is hereby granted, free of charge, to any person obtaining a
5 : * copy of this software and associated documentation files (the "Software"),
6 : * to deal in the Software without restriction, including without limitation
7 : * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 : * and/or sell copies of the Software, and to permit persons to whom the
9 : * Software is furnished to do so, subject to the following conditions:
10 : *
11 : * The above copyright notice and this permission notice shall be included in
12 : * all copies or substantial portions of the Software.
13 : *
14 : * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 : * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 : * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 : * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 : * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 : * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20 : * DEALINGS IN THE SOFTWARE.
21 : */
22 :
23 : #define nsHtml5NamedCharacters_cpp_
24 : #include "prtypes.h"
25 : #include "jArray.h"
26 : #include "nscore.h"
27 : #include "nsDebug.h"
28 : #include "prlog.h"
29 : #include "nsMemory.h"
30 :
31 : #include "nsHtml5NamedCharacters.h"
32 :
33 : const PRUnichar nsHtml5NamedCharacters::VALUES[][2] = {
34 : #define NAMED_CHARACTER_REFERENCE(N, CHARS, LEN, FLAG, VALUE) \
35 : { VALUE },
36 : #include "nsHtml5NamedCharactersInclude.h"
37 : #undef NAMED_CHARACTER_REFERENCE
38 : {0, 0} };
39 :
40 : PRUnichar** nsHtml5NamedCharacters::WINDOWS_1252;
41 : static PRUnichar const WINDOWS_1252_DATA[] = {
42 : 0x20AC,
43 : 0x0081,
44 : 0x201A,
45 : 0x0192,
46 : 0x201E,
47 : 0x2026,
48 : 0x2020,
49 : 0x2021,
50 : 0x02C6,
51 : 0x2030,
52 : 0x0160,
53 : 0x2039,
54 : 0x0152,
55 : 0x008D,
56 : 0x017D,
57 : 0x008F,
58 : 0x0090,
59 : 0x2018,
60 : 0x2019,
61 : 0x201C,
62 : 0x201D,
63 : 0x2022,
64 : 0x2013,
65 : 0x2014,
66 : 0x02DC,
67 : 0x2122,
68 : 0x0161,
69 : 0x203A,
70 : 0x0153,
71 : 0x009D,
72 : 0x017E,
73 : 0x0178
74 : };
75 :
76 : /**
77 : * To avoid having lots of pointers in the |charData| array, below,
78 : * which would cause us to have to do lots of relocations at library
79 : * load time, store all the string data for the names in one big array.
80 : * Then use tricks with enums to help us build an array that contains
81 : * the positions of each within the big arrays.
82 : */
83 :
84 : static const PRInt8 ALL_NAMES[] = {
85 : #define NAMED_CHARACTER_REFERENCE(N, CHARS, LEN, FLAG, VALUE) \
86 : CHARS ,
87 : #include "nsHtml5NamedCharactersInclude.h"
88 : #undef NAMED_CHARACTER_REFERENCE
89 : };
90 :
91 : enum NamePositions {
92 : DUMMY_INITIAL_NAME_POSITION = 0,
93 : /* enums don't take up space, so generate _START and _END */
94 : #define NAMED_CHARACTER_REFERENCE(N, CHARS, LEN, FLAG, VALUE) \
95 : NAME_##N##_DUMMY, /* automatically one higher than previous */ \
96 : NAME_##N##_START = NAME_##N##_DUMMY - 1, \
97 : NAME_##N##_END = NAME_##N##_START + LEN + FLAG,
98 : #include "nsHtml5NamedCharactersInclude.h"
99 : #undef NAMED_CHARACTER_REFERENCE
100 : DUMMY_FINAL_NAME_VALUE
101 : };
102 :
103 : /* check that the start positions will fit in 16 bits */
104 : PR_STATIC_ASSERT(NS_ARRAY_LENGTH(ALL_NAMES) < 0x10000);
105 :
106 : const nsHtml5CharacterName nsHtml5NamedCharacters::NAMES[] = {
107 : #ifdef DEBUG
108 : #define NAMED_CHARACTER_REFERENCE(N, CHARS, LEN, FLAG, VALUE) \
109 : { NAME_##N##_START, LEN, N },
110 : #else
111 : #define NAMED_CHARACTER_REFERENCE(N, CHARS, LEN, FLAG, VALUE) \
112 : { NAME_##N##_START, LEN, },
113 : #endif
114 : #include "nsHtml5NamedCharactersInclude.h"
115 : #undef NAMED_CHARACTER_REFERENCE
116 : };
117 :
118 : PRInt32
119 335 : nsHtml5CharacterName::length() const
120 : {
121 335 : return nameLen;
122 : }
123 :
124 : PRUnichar
125 150 : nsHtml5CharacterName::charAt(PRInt32 index) const
126 : {
127 150 : return static_cast<PRUnichar> (ALL_NAMES[nameStart + index]);
128 : }
129 :
130 : void
131 1404 : nsHtml5NamedCharacters::initializeStatics()
132 : {
133 1404 : WINDOWS_1252 = new PRUnichar*[32];
134 46332 : for (PRInt32 i = 0; i < 32; ++i) {
135 44928 : WINDOWS_1252[i] = (PRUnichar*)&(WINDOWS_1252_DATA[i]);
136 : }
137 1404 : }
138 :
139 : void
140 1403 : nsHtml5NamedCharacters::releaseStatics()
141 : {
142 1403 : delete[] WINDOWS_1252;
143 1403 : }
|