Bug 601299: Find RegExpStatics in cx->globalObject if necessary. (r=mrbkap)
[mozilla-central.git] / parser / html / nsHtml5NamedCharacters.cpp
blob639740cae4cbb75eb3608d09269cef5e3fe245b2
1 /*
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_
24 #include "prtypes.h"
25 #include "jArray.h"
26 #include "nscore.h"
27 #include "nsDebug.h"
28 #include "prlog.h"
29 #include "nsMemory.h"
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) \
37 { VALUE },
38 #include "nsHtml5NamedCharactersInclude.h"
39 #undef NAMED_CHARACTER_REFERENCE
40 {0, 0} };
42 PRUnichar** nsHtml5NamedCharacters::WINDOWS_1252;
43 static PRUnichar const WINDOWS_1252_DATA[] = {
44 0x20AC,
45 0x0081,
46 0x201A,
47 0x0192,
48 0x201E,
49 0x2026,
50 0x2020,
51 0x2021,
52 0x02C6,
53 0x2030,
54 0x0160,
55 0x2039,
56 0x0152,
57 0x008D,
58 0x017D,
59 0x008F,
60 0x0090,
61 0x2018,
62 0x2019,
63 0x201C,
64 0x201D,
65 0x2022,
66 0x2013,
67 0x2014,
68 0x02DC,
69 0x2122,
70 0x0161,
71 0x203A,
72 0x0153,
73 0x009D,
74 0x017E,
75 0x0178
78 /**
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) \
88 CHARS ,
89 #include "nsHtml5NamedCharactersInclude.h"
90 #undef NAMED_CHARACTER_REFERENCE
93 enum NamePositions {
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 {
111 PRUint16 nameStart;
112 PRUint16 nameLen;
113 #ifdef DEBUG
114 PRInt32 n;
115 #endif
118 static const NamedCharacterData charData[NAMED_CHARACTERS_COUNT] = {
119 #ifdef DEBUG
120 #define NAMED_CHARACTER_REFERENCE(N, CHARS, LEN, FLAG, VALUE) \
121 { NAME_##N##_START, LEN, N },
122 #else
123 #define NAMED_CHARACTER_REFERENCE(N, CHARS, LEN, FLAG, VALUE) \
124 { NAME_##N##_START, LEN, },
125 #endif
126 #include "nsHtml5NamedCharactersInclude.h"
127 #undef NAMED_CHARACTER_REFERENCE
130 void
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]);
148 void
149 nsHtml5NamedCharacters::releaseStatics()
151 NAMES.release();
152 delete[] WINDOWS_1252;