LCOV - code coverage report
Current view: top level - parser/html - nsHtml5NamedCharacters.cpp (source / functions) Hit Total Coverage
Test: output.info Lines: 5 12 41.7 %
Date: 2017-07-14 16:53:18 Functions: 1 4 25.0 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.13