parser/html/nsHtml5NamedCharacters.cpp

Fri, 16 Jan 2015 18:13:44 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Fri, 16 Jan 2015 18:13:44 +0100
branch
TOR_BUG_9701
changeset 14
925c144e1f1f
permissions
-rw-r--r--

Integrate suggestion from review to improve consistency with existing code.

michael@0 1 /*
michael@0 2 * Copyright (c) 2008-2010 Mozilla Foundation
michael@0 3 *
michael@0 4 * Permission is hereby granted, free of charge, to any person obtaining a
michael@0 5 * copy of this software and associated documentation files (the "Software"),
michael@0 6 * to deal in the Software without restriction, including without limitation
michael@0 7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
michael@0 8 * and/or sell copies of the Software, and to permit persons to whom the
michael@0 9 * Software is furnished to do so, subject to the following conditions:
michael@0 10 *
michael@0 11 * The above copyright notice and this permission notice shall be included in
michael@0 12 * all copies or substantial portions of the Software.
michael@0 13 *
michael@0 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
michael@0 15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
michael@0 16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
michael@0 17 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
michael@0 18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
michael@0 19 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
michael@0 20 * DEALINGS IN THE SOFTWARE.
michael@0 21 */
michael@0 22
michael@0 23 #define nsHtml5NamedCharacters_cpp_
michael@0 24 #include "jArray.h"
michael@0 25 #include "nscore.h"
michael@0 26 #include "nsDebug.h"
michael@0 27 #include "mozilla/ArrayUtils.h"
michael@0 28 #include "prlog.h"
michael@0 29
michael@0 30 #include "nsHtml5NamedCharacters.h"
michael@0 31
michael@0 32 const char16_t nsHtml5NamedCharacters::VALUES[][2] = {
michael@0 33 #define NAMED_CHARACTER_REFERENCE(N, CHARS, LEN, FLAG, VALUE) \
michael@0 34 { VALUE },
michael@0 35 #include "nsHtml5NamedCharactersInclude.h"
michael@0 36 #undef NAMED_CHARACTER_REFERENCE
michael@0 37 {0, 0} };
michael@0 38
michael@0 39 char16_t** nsHtml5NamedCharacters::WINDOWS_1252;
michael@0 40 static char16_t const WINDOWS_1252_DATA[] = {
michael@0 41 0x20AC,
michael@0 42 0x0081,
michael@0 43 0x201A,
michael@0 44 0x0192,
michael@0 45 0x201E,
michael@0 46 0x2026,
michael@0 47 0x2020,
michael@0 48 0x2021,
michael@0 49 0x02C6,
michael@0 50 0x2030,
michael@0 51 0x0160,
michael@0 52 0x2039,
michael@0 53 0x0152,
michael@0 54 0x008D,
michael@0 55 0x017D,
michael@0 56 0x008F,
michael@0 57 0x0090,
michael@0 58 0x2018,
michael@0 59 0x2019,
michael@0 60 0x201C,
michael@0 61 0x201D,
michael@0 62 0x2022,
michael@0 63 0x2013,
michael@0 64 0x2014,
michael@0 65 0x02DC,
michael@0 66 0x2122,
michael@0 67 0x0161,
michael@0 68 0x203A,
michael@0 69 0x0153,
michael@0 70 0x009D,
michael@0 71 0x017E,
michael@0 72 0x0178
michael@0 73 };
michael@0 74
michael@0 75 /**
michael@0 76 * To avoid having lots of pointers in the |charData| array, below,
michael@0 77 * which would cause us to have to do lots of relocations at library
michael@0 78 * load time, store all the string data for the names in one big array.
michael@0 79 * Then use tricks with enums to help us build an array that contains
michael@0 80 * the positions of each within the big arrays.
michael@0 81 */
michael@0 82
michael@0 83 static const int8_t ALL_NAMES[] = {
michael@0 84 #define NAMED_CHARACTER_REFERENCE(N, CHARS, LEN, FLAG, VALUE) \
michael@0 85 CHARS ,
michael@0 86 #include "nsHtml5NamedCharactersInclude.h"
michael@0 87 #undef NAMED_CHARACTER_REFERENCE
michael@0 88 };
michael@0 89
michael@0 90 enum NamePositions {
michael@0 91 DUMMY_INITIAL_NAME_POSITION = 0,
michael@0 92 /* enums don't take up space, so generate _START and _END */
michael@0 93 #define NAMED_CHARACTER_REFERENCE(N, CHARS, LEN, FLAG, VALUE) \
michael@0 94 NAME_##N##_DUMMY, /* automatically one higher than previous */ \
michael@0 95 NAME_##N##_START = NAME_##N##_DUMMY - 1, \
michael@0 96 NAME_##N##_END = NAME_##N##_START + LEN + FLAG,
michael@0 97 #include "nsHtml5NamedCharactersInclude.h"
michael@0 98 #undef NAMED_CHARACTER_REFERENCE
michael@0 99 DUMMY_FINAL_NAME_VALUE
michael@0 100 };
michael@0 101
michael@0 102 /* check that the start positions will fit in 16 bits */
michael@0 103 PR_STATIC_ASSERT(MOZ_ARRAY_LENGTH(ALL_NAMES) < 0x10000);
michael@0 104
michael@0 105 const nsHtml5CharacterName nsHtml5NamedCharacters::NAMES[] = {
michael@0 106 #ifdef DEBUG
michael@0 107 #define NAMED_CHARACTER_REFERENCE(N, CHARS, LEN, FLAG, VALUE) \
michael@0 108 { NAME_##N##_START, LEN, N },
michael@0 109 #else
michael@0 110 #define NAMED_CHARACTER_REFERENCE(N, CHARS, LEN, FLAG, VALUE) \
michael@0 111 { NAME_##N##_START, LEN, },
michael@0 112 #endif
michael@0 113 #include "nsHtml5NamedCharactersInclude.h"
michael@0 114 #undef NAMED_CHARACTER_REFERENCE
michael@0 115 };
michael@0 116
michael@0 117 int32_t
michael@0 118 nsHtml5CharacterName::length() const
michael@0 119 {
michael@0 120 return nameLen;
michael@0 121 }
michael@0 122
michael@0 123 char16_t
michael@0 124 nsHtml5CharacterName::charAt(int32_t index) const
michael@0 125 {
michael@0 126 return static_cast<char16_t> (ALL_NAMES[nameStart + index]);
michael@0 127 }
michael@0 128
michael@0 129 void
michael@0 130 nsHtml5NamedCharacters::initializeStatics()
michael@0 131 {
michael@0 132 WINDOWS_1252 = new char16_t*[32];
michael@0 133 for (int32_t i = 0; i < 32; ++i) {
michael@0 134 WINDOWS_1252[i] = (char16_t*)&(WINDOWS_1252_DATA[i]);
michael@0 135 }
michael@0 136 }
michael@0 137
michael@0 138 void
michael@0 139 nsHtml5NamedCharacters::releaseStatics()
michael@0 140 {
michael@0 141 delete[] WINDOWS_1252;
michael@0 142 }

mercurial