/src/mozilla-central/parser/html/nsHtml5NamedCharacters.cpp
Line | Count | Source (jump to first uncovered line) |
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 "jArray.h" |
25 | | #include "mozilla/ArrayUtils.h" |
26 | | #include "mozilla/Logging.h" |
27 | | #include "nsDebug.h" |
28 | | #include "nscore.h" |
29 | | |
30 | | #include "nsHtml5NamedCharacters.h" |
31 | | |
32 | | const char16_t nsHtml5NamedCharacters::VALUES[][2] = { |
33 | | #define NAMED_CHARACTER_REFERENCE(N, CHARS, LEN, FLAG, VALUE) { VALUE }, |
34 | | #include "nsHtml5NamedCharactersInclude.h" |
35 | | #undef NAMED_CHARACTER_REFERENCE |
36 | | { 0, 0 } |
37 | | }; |
38 | | |
39 | | char16_t** nsHtml5NamedCharacters::WINDOWS_1252; |
40 | | static char16_t const WINDOWS_1252_DATA[] = { |
41 | | 0x20AC, 0x0081, 0x201A, 0x0192, 0x201E, 0x2026, 0x2020, 0x2021, |
42 | | 0x02C6, 0x2030, 0x0160, 0x2039, 0x0152, 0x008D, 0x017D, 0x008F, |
43 | | 0x0090, 0x2018, 0x2019, 0x201C, 0x201D, 0x2022, 0x2013, 0x2014, |
44 | | 0x02DC, 0x2122, 0x0161, 0x203A, 0x0153, 0x009D, 0x017E, 0x0178 |
45 | | }; |
46 | | |
47 | | /** |
48 | | * To avoid having lots of pointers in the |charData| array, below, |
49 | | * which would cause us to have to do lots of relocations at library |
50 | | * load time, store all the string data for the names in one big array. |
51 | | * Then use tricks with enums to help us build an array that contains |
52 | | * the positions of each within the big arrays. |
53 | | */ |
54 | | |
55 | | static const int8_t ALL_NAMES[] = { |
56 | | #define NAMED_CHARACTER_REFERENCE(N, CHARS, LEN, FLAG, VALUE) CHARS, |
57 | | #include "nsHtml5NamedCharactersInclude.h" |
58 | | #undef NAMED_CHARACTER_REFERENCE |
59 | | }; |
60 | | |
61 | | enum NamePositions |
62 | | { |
63 | | DUMMY_INITIAL_NAME_POSITION = 0, |
64 | | /* enums don't take up space, so generate _START and _END */ |
65 | | #define NAMED_CHARACTER_REFERENCE(N, CHARS, LEN, FLAG, VALUE) \ |
66 | | NAME_##N##_DUMMY, /* automatically one higher than previous */ \ |
67 | | NAME_##N##_START = NAME_##N##_DUMMY - 1, \ |
68 | | NAME_##N##_END = NAME_##N##_START + LEN + FLAG, |
69 | | #include "nsHtml5NamedCharactersInclude.h" |
70 | | #undef NAMED_CHARACTER_REFERENCE |
71 | | DUMMY_FINAL_NAME_VALUE |
72 | | }; |
73 | | |
74 | | static_assert(MOZ_ARRAY_LENGTH(ALL_NAMES) < 0x10000, |
75 | | "Start positions should fit in 16 bits"); |
76 | | |
77 | | const nsHtml5CharacterName nsHtml5NamedCharacters::NAMES[] = { |
78 | | #ifdef DEBUG |
79 | | #define NAMED_CHARACTER_REFERENCE(N, CHARS, LEN, FLAG, VALUE) \ |
80 | | { NAME_##N##_START, LEN, N }, |
81 | | #else |
82 | | #define NAMED_CHARACTER_REFERENCE(N, CHARS, LEN, FLAG, VALUE) \ |
83 | | { \ |
84 | | NAME_##N##_START, \ |
85 | | LEN, \ |
86 | | }, |
87 | | #endif |
88 | | #include "nsHtml5NamedCharactersInclude.h" |
89 | | #undef NAMED_CHARACTER_REFERENCE |
90 | | }; |
91 | | |
92 | | int32_t |
93 | | nsHtml5CharacterName::length() const |
94 | 0 | { |
95 | 0 | return nameLen; |
96 | 0 | } |
97 | | |
98 | | char16_t |
99 | | nsHtml5CharacterName::charAt(int32_t index) const |
100 | 0 | { |
101 | 0 | return static_cast<char16_t>(ALL_NAMES[nameStart + index]); |
102 | 0 | } |
103 | | |
104 | | void |
105 | | nsHtml5NamedCharacters::initializeStatics() |
106 | 3 | { |
107 | 3 | WINDOWS_1252 = new char16_t*[32]; |
108 | 99 | for (int32_t i = 0; i < 32; ++i) { |
109 | 96 | WINDOWS_1252[i] = (char16_t*)&(WINDOWS_1252_DATA[i]); |
110 | 96 | } |
111 | 3 | } |
112 | | |
113 | | void |
114 | | nsHtml5NamedCharacters::releaseStatics() |
115 | 0 | { |
116 | 0 | delete[] WINDOWS_1252; |
117 | 0 | } |