1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/parser/html/nsHtml5NamedCharacters.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,142 @@ 1.4 +/* 1.5 + * Copyright (c) 2008-2010 Mozilla Foundation 1.6 + * 1.7 + * Permission is hereby granted, free of charge, to any person obtaining a 1.8 + * copy of this software and associated documentation files (the "Software"), 1.9 + * to deal in the Software without restriction, including without limitation 1.10 + * the rights to use, copy, modify, merge, publish, distribute, sublicense, 1.11 + * and/or sell copies of the Software, and to permit persons to whom the 1.12 + * Software is furnished to do so, subject to the following conditions: 1.13 + * 1.14 + * The above copyright notice and this permission notice shall be included in 1.15 + * all copies or substantial portions of the Software. 1.16 + * 1.17 + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 1.18 + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 1.19 + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 1.20 + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 1.21 + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 1.22 + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 1.23 + * DEALINGS IN THE SOFTWARE. 1.24 + */ 1.25 + 1.26 +#define nsHtml5NamedCharacters_cpp_ 1.27 +#include "jArray.h" 1.28 +#include "nscore.h" 1.29 +#include "nsDebug.h" 1.30 +#include "mozilla/ArrayUtils.h" 1.31 +#include "prlog.h" 1.32 + 1.33 +#include "nsHtml5NamedCharacters.h" 1.34 + 1.35 +const char16_t nsHtml5NamedCharacters::VALUES[][2] = { 1.36 +#define NAMED_CHARACTER_REFERENCE(N, CHARS, LEN, FLAG, VALUE) \ 1.37 +{ VALUE }, 1.38 +#include "nsHtml5NamedCharactersInclude.h" 1.39 +#undef NAMED_CHARACTER_REFERENCE 1.40 +{0, 0} }; 1.41 + 1.42 +char16_t** nsHtml5NamedCharacters::WINDOWS_1252; 1.43 +static char16_t const WINDOWS_1252_DATA[] = { 1.44 + 0x20AC, 1.45 + 0x0081, 1.46 + 0x201A, 1.47 + 0x0192, 1.48 + 0x201E, 1.49 + 0x2026, 1.50 + 0x2020, 1.51 + 0x2021, 1.52 + 0x02C6, 1.53 + 0x2030, 1.54 + 0x0160, 1.55 + 0x2039, 1.56 + 0x0152, 1.57 + 0x008D, 1.58 + 0x017D, 1.59 + 0x008F, 1.60 + 0x0090, 1.61 + 0x2018, 1.62 + 0x2019, 1.63 + 0x201C, 1.64 + 0x201D, 1.65 + 0x2022, 1.66 + 0x2013, 1.67 + 0x2014, 1.68 + 0x02DC, 1.69 + 0x2122, 1.70 + 0x0161, 1.71 + 0x203A, 1.72 + 0x0153, 1.73 + 0x009D, 1.74 + 0x017E, 1.75 + 0x0178 1.76 +}; 1.77 + 1.78 +/** 1.79 + * To avoid having lots of pointers in the |charData| array, below, 1.80 + * which would cause us to have to do lots of relocations at library 1.81 + * load time, store all the string data for the names in one big array. 1.82 + * Then use tricks with enums to help us build an array that contains 1.83 + * the positions of each within the big arrays. 1.84 + */ 1.85 + 1.86 +static const int8_t ALL_NAMES[] = { 1.87 +#define NAMED_CHARACTER_REFERENCE(N, CHARS, LEN, FLAG, VALUE) \ 1.88 +CHARS , 1.89 +#include "nsHtml5NamedCharactersInclude.h" 1.90 +#undef NAMED_CHARACTER_REFERENCE 1.91 +}; 1.92 + 1.93 +enum NamePositions { 1.94 + DUMMY_INITIAL_NAME_POSITION = 0, 1.95 +/* enums don't take up space, so generate _START and _END */ 1.96 +#define NAMED_CHARACTER_REFERENCE(N, CHARS, LEN, FLAG, VALUE) \ 1.97 +NAME_##N##_DUMMY, /* automatically one higher than previous */ \ 1.98 +NAME_##N##_START = NAME_##N##_DUMMY - 1, \ 1.99 +NAME_##N##_END = NAME_##N##_START + LEN + FLAG, 1.100 +#include "nsHtml5NamedCharactersInclude.h" 1.101 +#undef NAMED_CHARACTER_REFERENCE 1.102 + DUMMY_FINAL_NAME_VALUE 1.103 +}; 1.104 + 1.105 +/* check that the start positions will fit in 16 bits */ 1.106 +PR_STATIC_ASSERT(MOZ_ARRAY_LENGTH(ALL_NAMES) < 0x10000); 1.107 + 1.108 +const nsHtml5CharacterName nsHtml5NamedCharacters::NAMES[] = { 1.109 +#ifdef DEBUG 1.110 + #define NAMED_CHARACTER_REFERENCE(N, CHARS, LEN, FLAG, VALUE) \ 1.111 +{ NAME_##N##_START, LEN, N }, 1.112 +#else 1.113 + #define NAMED_CHARACTER_REFERENCE(N, CHARS, LEN, FLAG, VALUE) \ 1.114 +{ NAME_##N##_START, LEN, }, 1.115 +#endif 1.116 +#include "nsHtml5NamedCharactersInclude.h" 1.117 +#undef NAMED_CHARACTER_REFERENCE 1.118 +}; 1.119 + 1.120 +int32_t 1.121 +nsHtml5CharacterName::length() const 1.122 +{ 1.123 + return nameLen; 1.124 +} 1.125 + 1.126 +char16_t 1.127 +nsHtml5CharacterName::charAt(int32_t index) const 1.128 +{ 1.129 + return static_cast<char16_t> (ALL_NAMES[nameStart + index]); 1.130 +} 1.131 + 1.132 +void 1.133 +nsHtml5NamedCharacters::initializeStatics() 1.134 +{ 1.135 + WINDOWS_1252 = new char16_t*[32]; 1.136 + for (int32_t i = 0; i < 32; ++i) { 1.137 + WINDOWS_1252[i] = (char16_t*)&(WINDOWS_1252_DATA[i]); 1.138 + } 1.139 +} 1.140 + 1.141 +void 1.142 +nsHtml5NamedCharacters::releaseStatics() 1.143 +{ 1.144 + delete[] WINDOWS_1252; 1.145 +}