2 * Copyright (c) 2008-2010 Mozilla Foundation
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:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
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.
23 #define nsHtml5NamedCharacters_cpp_
31 #include "nsHtml5NamedCharacters.h"
33 jArray
<jArray
<PRInt8
,PRInt32
>,PRInt32
> nsHtml5NamedCharacters::NAMES
;
35 const PRUnichar
nsHtml5NamedCharacters::VALUES
[][2] = {
36 #define NAMED_CHARACTER_REFERENCE(N, CHARS, LEN, FLAG, VALUE) \
38 #include "nsHtml5NamedCharactersInclude.h"
39 #undef NAMED_CHARACTER_REFERENCE
42 PRUnichar
** nsHtml5NamedCharacters::WINDOWS_1252
;
43 static PRUnichar
const WINDOWS_1252_DATA
[] = {
79 * To avoid having lots of pointers in the |charData| array, below,
80 * which would cause us to have to do lots of relocations at library
81 * load time, store all the string data for the names in one big array.
82 * Then use tricks with enums to help us build an array that contains
83 * the positions of each within the big arrays.
86 static const PRInt8 ALL_NAMES
[] = {
87 #define NAMED_CHARACTER_REFERENCE(N, CHARS, LEN, FLAG, VALUE) \
89 #include "nsHtml5NamedCharactersInclude.h"
90 #undef NAMED_CHARACTER_REFERENCE
94 DUMMY_INITIAL_NAME_POSITION
= 0,
95 /* enums don't take up space, so generate _START and _END */
96 #define NAMED_CHARACTER_REFERENCE(N, CHARS, LEN, FLAG, VALUE) \
97 NAME_##N##_DUMMY, /* automatically one higher than previous */ \
98 NAME_##N##_START = NAME_##N##_DUMMY - 1, \
99 NAME_##N##_END = NAME_##N##_START + LEN + FLAG,
100 #include "nsHtml5NamedCharactersInclude.h"
101 #undef NAMED_CHARACTER_REFERENCE
102 DUMMY_FINAL_NAME_VALUE
105 #define NAMED_CHARACTERS_COUNT 2138
107 /* check that the start positions will fit in 16 bits */
108 PR_STATIC_ASSERT(NS_ARRAY_LENGTH(ALL_NAMES
) < 0x10000);
110 struct NamedCharacterData
{
118 static const NamedCharacterData charData
[NAMED_CHARACTERS_COUNT
] = {
120 #define NAMED_CHARACTER_REFERENCE(N, CHARS, LEN, FLAG, VALUE) \
121 { NAME_##N##_START, LEN, N },
123 #define NAMED_CHARACTER_REFERENCE(N, CHARS, LEN, FLAG, VALUE) \
124 { NAME_##N##_START, LEN, },
126 #include "nsHtml5NamedCharactersInclude.h"
127 #undef NAMED_CHARACTER_REFERENCE
131 nsHtml5NamedCharacters::initializeStatics()
133 NAMES
= jArray
<jArray
<PRInt8
,PRInt32
>,PRInt32
>(NAMED_CHARACTERS_COUNT
);
134 PRInt8
* allNames
= const_cast<PRInt8
*>(ALL_NAMES
);
135 for (PRInt32 i
= 0; i
< NAMED_CHARACTERS_COUNT
; ++i
) {
136 const NamedCharacterData
&data
= charData
[i
];
137 NS_ABORT_IF_FALSE(data
.n
== i
,
138 "index error in nsHtml5NamedCharactersInclude.h");
139 NAMES
[i
] = jArray
<PRInt8
,PRInt32
>(allNames
+ data
.nameStart
, data
.nameLen
);
142 WINDOWS_1252
= new PRUnichar
*[32];
143 for (PRInt32 i
= 0; i
< 32; ++i
) {
144 WINDOWS_1252
[i
] = (PRUnichar
*)&(WINDOWS_1252_DATA
[i
]);
149 nsHtml5NamedCharacters::releaseStatics()
152 delete[] WINDOWS_1252
;