1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/xpcom/ds/nsStaticNameTable.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,50 @@ 1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- 1.5 + * 1.6 + * This Source Code Form is subject to the terms of the Mozilla Public 1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.9 + 1.10 +/* Classes to manage lookup of static names in a table. */ 1.11 + 1.12 +#ifndef nsStaticNameTable_h___ 1.13 +#define nsStaticNameTable_h___ 1.14 + 1.15 +#include "pldhash.h" 1.16 +#include "nsString.h" 1.17 + 1.18 +/* This class supports case insensitive lookup. 1.19 + * 1.20 + * It differs from atom tables: 1.21 + * - It supports case insensitive lookup. 1.22 + * - It has minimal footprint by not copying the string table. 1.23 + * - It does no locking. 1.24 + * - It returns zero based indexes and const nsCString& as required by its 1.25 + * callers in the parser. 1.26 + * - It is not an xpcom interface - meant for fast lookup in static tables. 1.27 + * 1.28 + * ***REQUIREMENTS*** 1.29 + * - It *requires* that all entries in the table be lowercase only. 1.30 + * - It *requires* that the table of strings be in memory that lives at least 1.31 + * as long as this table object - typically a static string array. 1.32 + */ 1.33 + 1.34 +class nsStaticCaseInsensitiveNameTable 1.35 +{ 1.36 +public: 1.37 + enum { NOT_FOUND = -1 }; 1.38 + 1.39 + bool Init(const char* const aNames[], int32_t Count); 1.40 + int32_t Lookup(const nsACString& aName); 1.41 + int32_t Lookup(const nsAString& aName); 1.42 + const nsAFlatCString& GetStringValue(int32_t index); 1.43 + 1.44 + nsStaticCaseInsensitiveNameTable(); 1.45 + ~nsStaticCaseInsensitiveNameTable(); 1.46 + 1.47 +private: 1.48 + nsDependentCString* mNameArray; 1.49 + PLDHashTable mNameTable; 1.50 + nsDependentCString mNullStr; 1.51 +}; 1.52 + 1.53 +#endif /* nsStaticNameTable_h___ */