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/. */
6 /* keywords used within CSS property values */
8 #include "nsCSSKeywords.h"
10 #include "nsStaticNameTable.h"
12 // required to make the symbol external, so that TestCSSPropertyLookup.cpp can link with it
13 extern const char* const kCSSRawKeywords
[];
15 // define an array of all CSS keywords
16 #define CSS_KEY(_name,_id) #_name,
17 const char* const kCSSRawKeywords
[] = {
18 #include "nsCSSKeywordList.h"
22 static int32_t gKeywordTableRefCount
;
23 static nsStaticCaseInsensitiveNameTable
* gKeywordTable
;
26 nsCSSKeywords::AddRefTable(void)
28 if (0 == gKeywordTableRefCount
++) {
29 NS_ASSERTION(!gKeywordTable
, "pre existing array!");
30 gKeywordTable
= new nsStaticCaseInsensitiveNameTable();
34 // let's verify the table...
36 for (; index
< eCSSKeyword_COUNT
&& kCSSRawKeywords
[index
]; ++index
) {
37 nsAutoCString
temp1(kCSSRawKeywords
[index
]);
38 nsAutoCString
temp2(kCSSRawKeywords
[index
]);
40 NS_ASSERTION(temp1
.Equals(temp2
), "upper case char in table");
41 NS_ASSERTION(-1 == temp1
.FindChar('_'), "underscore char in table");
43 NS_ASSERTION(index
== eCSSKeyword_COUNT
, "kCSSRawKeywords and eCSSKeyword_COUNT are out of sync");
46 gKeywordTable
->Init(kCSSRawKeywords
, eCSSKeyword_COUNT
);
52 nsCSSKeywords::ReleaseTable(void)
54 if (0 == --gKeywordTableRefCount
) {
57 gKeywordTable
= nullptr;
63 nsCSSKeywords::LookupKeyword(const nsACString
& aKeyword
)
65 NS_ASSERTION(gKeywordTable
, "no lookup table, needs addref");
67 return nsCSSKeyword(gKeywordTable
->Lookup(aKeyword
));
69 return eCSSKeyword_UNKNOWN
;
73 nsCSSKeywords::LookupKeyword(const nsAString
& aKeyword
)
75 NS_ASSERTION(gKeywordTable
, "no lookup table, needs addref");
77 return nsCSSKeyword(gKeywordTable
->Lookup(aKeyword
));
79 return eCSSKeyword_UNKNOWN
;
83 nsCSSKeywords::GetStringValue(nsCSSKeyword aKeyword
)
85 NS_ASSERTION(gKeywordTable
, "no lookup table, needs addref");
86 NS_ASSERTION(0 <= aKeyword
&& aKeyword
< eCSSKeyword_COUNT
, "out of range");
88 return gKeywordTable
->GetStringValue(int32_t(aKeyword
));
90 static nsDependentCString
kNullStr("");