michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: /* keywords used within CSS property values */ michael@0: michael@0: #include "nsCSSKeywords.h" michael@0: #include "nsString.h" michael@0: #include "nsStaticNameTable.h" michael@0: michael@0: // required to make the symbol external, so that TestCSSPropertyLookup.cpp can link with it michael@0: extern const char* const kCSSRawKeywords[]; michael@0: michael@0: // define an array of all CSS keywords michael@0: #define CSS_KEY(_name,_id) #_name, michael@0: const char* const kCSSRawKeywords[] = { michael@0: #include "nsCSSKeywordList.h" michael@0: }; michael@0: #undef CSS_KEY michael@0: michael@0: static int32_t gKeywordTableRefCount; michael@0: static nsStaticCaseInsensitiveNameTable* gKeywordTable; michael@0: michael@0: void michael@0: nsCSSKeywords::AddRefTable(void) michael@0: { michael@0: if (0 == gKeywordTableRefCount++) { michael@0: NS_ASSERTION(!gKeywordTable, "pre existing array!"); michael@0: gKeywordTable = new nsStaticCaseInsensitiveNameTable(); michael@0: if (gKeywordTable) { michael@0: #ifdef DEBUG michael@0: { michael@0: // let's verify the table... michael@0: int32_t index = 0; michael@0: for (; index < eCSSKeyword_COUNT && kCSSRawKeywords[index]; ++index) { michael@0: nsAutoCString temp1(kCSSRawKeywords[index]); michael@0: nsAutoCString temp2(kCSSRawKeywords[index]); michael@0: ToLowerCase(temp1); michael@0: NS_ASSERTION(temp1.Equals(temp2), "upper case char in table"); michael@0: NS_ASSERTION(-1 == temp1.FindChar('_'), "underscore char in table"); michael@0: } michael@0: NS_ASSERTION(index == eCSSKeyword_COUNT, "kCSSRawKeywords and eCSSKeyword_COUNT are out of sync"); michael@0: } michael@0: #endif michael@0: gKeywordTable->Init(kCSSRawKeywords, eCSSKeyword_COUNT); michael@0: } michael@0: } michael@0: } michael@0: michael@0: void michael@0: nsCSSKeywords::ReleaseTable(void) michael@0: { michael@0: if (0 == --gKeywordTableRefCount) { michael@0: if (gKeywordTable) { michael@0: delete gKeywordTable; michael@0: gKeywordTable = nullptr; michael@0: } michael@0: } michael@0: } michael@0: michael@0: nsCSSKeyword michael@0: nsCSSKeywords::LookupKeyword(const nsACString& aKeyword) michael@0: { michael@0: NS_ASSERTION(gKeywordTable, "no lookup table, needs addref"); michael@0: if (gKeywordTable) { michael@0: return nsCSSKeyword(gKeywordTable->Lookup(aKeyword)); michael@0: } michael@0: return eCSSKeyword_UNKNOWN; michael@0: } michael@0: michael@0: nsCSSKeyword michael@0: nsCSSKeywords::LookupKeyword(const nsAString& aKeyword) michael@0: { michael@0: NS_ASSERTION(gKeywordTable, "no lookup table, needs addref"); michael@0: if (gKeywordTable) { michael@0: return nsCSSKeyword(gKeywordTable->Lookup(aKeyword)); michael@0: } michael@0: return eCSSKeyword_UNKNOWN; michael@0: } michael@0: michael@0: const nsAFlatCString& michael@0: nsCSSKeywords::GetStringValue(nsCSSKeyword aKeyword) michael@0: { michael@0: NS_ASSERTION(gKeywordTable, "no lookup table, needs addref"); michael@0: NS_ASSERTION(0 <= aKeyword && aKeyword < eCSSKeyword_COUNT, "out of range"); michael@0: if (gKeywordTable) { michael@0: return gKeywordTable->GetStringValue(int32_t(aKeyword)); michael@0: } else { michael@0: static nsDependentCString kNullStr(""); michael@0: return kNullStr; michael@0: } michael@0: } michael@0: