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