|
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- |
|
2 * |
|
3 * This Source Code Form is subject to the terms of the Mozilla Public |
|
4 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
6 |
|
7 /* Classes to manage lookup of static names in a table. */ |
|
8 |
|
9 #ifndef nsStaticNameTable_h___ |
|
10 #define nsStaticNameTable_h___ |
|
11 |
|
12 #include "pldhash.h" |
|
13 #include "nsString.h" |
|
14 |
|
15 /* This class supports case insensitive lookup. |
|
16 * |
|
17 * It differs from atom tables: |
|
18 * - It supports case insensitive lookup. |
|
19 * - It has minimal footprint by not copying the string table. |
|
20 * - It does no locking. |
|
21 * - It returns zero based indexes and const nsCString& as required by its |
|
22 * callers in the parser. |
|
23 * - It is not an xpcom interface - meant for fast lookup in static tables. |
|
24 * |
|
25 * ***REQUIREMENTS*** |
|
26 * - It *requires* that all entries in the table be lowercase only. |
|
27 * - It *requires* that the table of strings be in memory that lives at least |
|
28 * as long as this table object - typically a static string array. |
|
29 */ |
|
30 |
|
31 class nsStaticCaseInsensitiveNameTable |
|
32 { |
|
33 public: |
|
34 enum { NOT_FOUND = -1 }; |
|
35 |
|
36 bool Init(const char* const aNames[], int32_t Count); |
|
37 int32_t Lookup(const nsACString& aName); |
|
38 int32_t Lookup(const nsAString& aName); |
|
39 const nsAFlatCString& GetStringValue(int32_t index); |
|
40 |
|
41 nsStaticCaseInsensitiveNameTable(); |
|
42 ~nsStaticCaseInsensitiveNameTable(); |
|
43 |
|
44 private: |
|
45 nsDependentCString* mNameArray; |
|
46 PLDHashTable mNameTable; |
|
47 nsDependentCString mNullStr; |
|
48 }; |
|
49 |
|
50 #endif /* nsStaticNameTable_h___ */ |