LCOV - code coverage report
Current view: top level - layout/style - nsCSSKeywords.cpp (source / functions) Hit Total Coverage
Test: output.info Lines: 20 34 58.8 %
Date: 2017-07-14 16:53:18 Functions: 3 5 60.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
       2             : /* This Source Code Form is subject to the terms of the Mozilla Public
       3             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       4             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
       5             : 
       6             : /* keywords used within CSS property values */
       7             : 
       8             : #include "nsCSSKeywords.h"
       9             : #include "nsString.h"
      10             : #include "nsStaticNameTable.h"
      11             : 
      12             : // required to make the symbol external, so that TestCSSPropertyLookup.cpp can link with it
      13             : extern const char* const kCSSRawKeywords[];
      14             : 
      15             : // define an array of all CSS keywords
      16             : #define CSS_KEY(_name,_id) #_name,
      17             : const char* const kCSSRawKeywords[] = {
      18             : #include "nsCSSKeywordList.h"
      19             : };
      20             : #undef CSS_KEY
      21             : 
      22             : static int32_t gKeywordTableRefCount;
      23             : static nsStaticCaseInsensitiveNameTable* gKeywordTable;
      24             : 
      25             : void
      26           3 : nsCSSKeywords::AddRefTable(void)
      27             : {
      28           3 :   if (0 == gKeywordTableRefCount++) {
      29           3 :     NS_ASSERTION(!gKeywordTable, "pre existing array!");
      30           3 :     gKeywordTable =
      31           3 :       new nsStaticCaseInsensitiveNameTable(kCSSRawKeywords, eCSSKeyword_COUNT);
      32             : #ifdef DEBUG
      33             :     // Partially verify the entries.
      34           3 :     int32_t index = 0;
      35        4581 :     for (; index < eCSSKeyword_COUNT && kCSSRawKeywords[index]; ++index) {
      36        4578 :       nsAutoCString temp(kCSSRawKeywords[index]);
      37        2289 :       NS_ASSERTION(-1 == temp.FindChar('_'), "underscore char in table");
      38             :     }
      39           3 :     NS_ASSERTION(index == eCSSKeyword_COUNT, "kCSSRawKeywords and eCSSKeyword_COUNT are out of sync");
      40             : #endif
      41             :   }
      42           3 : }
      43             : 
      44             : void
      45           0 : nsCSSKeywords::ReleaseTable(void)
      46             : {
      47           0 :   if (0 == --gKeywordTableRefCount) {
      48           0 :     if (gKeywordTable) {
      49           0 :       delete gKeywordTable;
      50           0 :       gKeywordTable = nullptr;
      51             :     }
      52             :   }
      53           0 : }
      54             : 
      55             : nsCSSKeyword
      56           0 : nsCSSKeywords::LookupKeyword(const nsACString& aKeyword)
      57             : {
      58           0 :   NS_ASSERTION(gKeywordTable, "no lookup table, needs addref");
      59           0 :   if (gKeywordTable) {
      60           0 :     return nsCSSKeyword(gKeywordTable->Lookup(aKeyword));
      61             :   }
      62           0 :   return eCSSKeyword_UNKNOWN;
      63             : }
      64             : 
      65             : nsCSSKeyword
      66        5490 : nsCSSKeywords::LookupKeyword(const nsAString& aKeyword)
      67             : {
      68        5490 :   NS_ASSERTION(gKeywordTable, "no lookup table, needs addref");
      69        5490 :   if (gKeywordTable) {
      70        5490 :     return nsCSSKeyword(gKeywordTable->Lookup(aKeyword));
      71             :   }
      72           0 :   return eCSSKeyword_UNKNOWN;
      73             : }
      74             : 
      75             : const nsCString&
      76           1 : nsCSSKeywords::GetStringValue(nsCSSKeyword aKeyword)
      77             : {
      78           1 :   NS_ASSERTION(gKeywordTable, "no lookup table, needs addref");
      79           1 :   NS_ASSERTION(0 <= aKeyword && aKeyword < eCSSKeyword_COUNT, "out of range");
      80           1 :   if (gKeywordTable) {
      81           1 :     return gKeywordTable->GetStringValue(int32_t(aKeyword));
      82             :   } else {
      83           0 :     static nsDependentCString kNullStr("");
      84           0 :     return kNullStr;
      85             :   }
      86             : }
      87             : 

Generated by: LCOV version 1.13