michael@0: /* michael@0: * Copyright (c) 2008-2010 Mozilla Foundation michael@0: * michael@0: * Permission is hereby granted, free of charge, to any person obtaining a michael@0: * copy of this software and associated documentation files (the "Software"), michael@0: * to deal in the Software without restriction, including without limitation michael@0: * the rights to use, copy, modify, merge, publish, distribute, sublicense, michael@0: * and/or sell copies of the Software, and to permit persons to whom the michael@0: * Software is furnished to do so, subject to the following conditions: michael@0: * michael@0: * The above copyright notice and this permission notice shall be included in michael@0: * all copies or substantial portions of the Software. michael@0: * michael@0: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR michael@0: * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, michael@0: * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL michael@0: * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER michael@0: * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING michael@0: * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER michael@0: * DEALINGS IN THE SOFTWARE. michael@0: */ michael@0: michael@0: #define nsHtml5NamedCharacters_cpp_ michael@0: #include "jArray.h" michael@0: #include "nscore.h" michael@0: #include "nsDebug.h" michael@0: #include "mozilla/ArrayUtils.h" michael@0: #include "prlog.h" michael@0: michael@0: #include "nsHtml5NamedCharacters.h" michael@0: michael@0: const char16_t nsHtml5NamedCharacters::VALUES[][2] = { michael@0: #define NAMED_CHARACTER_REFERENCE(N, CHARS, LEN, FLAG, VALUE) \ michael@0: { VALUE }, michael@0: #include "nsHtml5NamedCharactersInclude.h" michael@0: #undef NAMED_CHARACTER_REFERENCE michael@0: {0, 0} }; michael@0: michael@0: char16_t** nsHtml5NamedCharacters::WINDOWS_1252; michael@0: static char16_t const WINDOWS_1252_DATA[] = { michael@0: 0x20AC, michael@0: 0x0081, michael@0: 0x201A, michael@0: 0x0192, michael@0: 0x201E, michael@0: 0x2026, michael@0: 0x2020, michael@0: 0x2021, michael@0: 0x02C6, michael@0: 0x2030, michael@0: 0x0160, michael@0: 0x2039, michael@0: 0x0152, michael@0: 0x008D, michael@0: 0x017D, michael@0: 0x008F, michael@0: 0x0090, michael@0: 0x2018, michael@0: 0x2019, michael@0: 0x201C, michael@0: 0x201D, michael@0: 0x2022, michael@0: 0x2013, michael@0: 0x2014, michael@0: 0x02DC, michael@0: 0x2122, michael@0: 0x0161, michael@0: 0x203A, michael@0: 0x0153, michael@0: 0x009D, michael@0: 0x017E, michael@0: 0x0178 michael@0: }; michael@0: michael@0: /** michael@0: * To avoid having lots of pointers in the |charData| array, below, michael@0: * which would cause us to have to do lots of relocations at library michael@0: * load time, store all the string data for the names in one big array. michael@0: * Then use tricks with enums to help us build an array that contains michael@0: * the positions of each within the big arrays. michael@0: */ michael@0: michael@0: static const int8_t ALL_NAMES[] = { michael@0: #define NAMED_CHARACTER_REFERENCE(N, CHARS, LEN, FLAG, VALUE) \ michael@0: CHARS , michael@0: #include "nsHtml5NamedCharactersInclude.h" michael@0: #undef NAMED_CHARACTER_REFERENCE michael@0: }; michael@0: michael@0: enum NamePositions { michael@0: DUMMY_INITIAL_NAME_POSITION = 0, michael@0: /* enums don't take up space, so generate _START and _END */ michael@0: #define NAMED_CHARACTER_REFERENCE(N, CHARS, LEN, FLAG, VALUE) \ michael@0: NAME_##N##_DUMMY, /* automatically one higher than previous */ \ michael@0: NAME_##N##_START = NAME_##N##_DUMMY - 1, \ michael@0: NAME_##N##_END = NAME_##N##_START + LEN + FLAG, michael@0: #include "nsHtml5NamedCharactersInclude.h" michael@0: #undef NAMED_CHARACTER_REFERENCE michael@0: DUMMY_FINAL_NAME_VALUE michael@0: }; michael@0: michael@0: /* check that the start positions will fit in 16 bits */ michael@0: PR_STATIC_ASSERT(MOZ_ARRAY_LENGTH(ALL_NAMES) < 0x10000); michael@0: michael@0: const nsHtml5CharacterName nsHtml5NamedCharacters::NAMES[] = { michael@0: #ifdef DEBUG michael@0: #define NAMED_CHARACTER_REFERENCE(N, CHARS, LEN, FLAG, VALUE) \ michael@0: { NAME_##N##_START, LEN, N }, michael@0: #else michael@0: #define NAMED_CHARACTER_REFERENCE(N, CHARS, LEN, FLAG, VALUE) \ michael@0: { NAME_##N##_START, LEN, }, michael@0: #endif michael@0: #include "nsHtml5NamedCharactersInclude.h" michael@0: #undef NAMED_CHARACTER_REFERENCE michael@0: }; michael@0: michael@0: int32_t michael@0: nsHtml5CharacterName::length() const michael@0: { michael@0: return nameLen; michael@0: } michael@0: michael@0: char16_t michael@0: nsHtml5CharacterName::charAt(int32_t index) const michael@0: { michael@0: return static_cast (ALL_NAMES[nameStart + index]); michael@0: } michael@0: michael@0: void michael@0: nsHtml5NamedCharacters::initializeStatics() michael@0: { michael@0: WINDOWS_1252 = new char16_t*[32]; michael@0: for (int32_t i = 0; i < 32; ++i) { michael@0: WINDOWS_1252[i] = (char16_t*)&(WINDOWS_1252_DATA[i]); michael@0: } michael@0: } michael@0: michael@0: void michael@0: nsHtml5NamedCharacters::releaseStatics() michael@0: { michael@0: delete[] WINDOWS_1252; michael@0: }