2
* Copyright 2010 Google Inc.
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
* you may not use this file except in compliance with the License.
6
* You may obtain a copy of the License at
8
* http://www.apache.org/licenses/LICENSE-2.0
10
* Unless required by applicable law or agreed to in writing, software
11
* distributed under the License is distributed on an "AS IS" BASIS,
12
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
* See the License for the specific language governing permissions and
14
* limitations under the License.
17
// Copyright 2006, Google Inc. All rights reserved.
18
// Author: mec@google.com (Michael Chastain)
20
// Map an html tag to a dense index number.
21
// Hardwired for speed on builtin tags.
22
// Caller can add tags on top of the builtins.
23
// Caller can choose case-sensitive or case-insensitive.
25
// TODO(mec): merge this with webutil/html/htmltag
27
#ifndef WEBUTIL_HTML_HTMLTAGINDEX_H__
28
#define WEBUTIL_HTML_HTMLTAGINDEX_H__
32
#include "string_using.h"
34
#include "base/basictypes.h"
35
#include "base/integral_types.h"
36
#include "base/macros.h"
37
#include "base/scoped_ptr.h"
38
#include "util/gtl/dense_hash_map.h"
39
#include "webutil/html/htmltagenum.h"
46
// Add a tag and return its index. It is okay to add a builtin
47
// tag or to add the same tag more than once.
48
int AddHtmlTag(const char* tag, int length);
49
int AddHtmlTag(const char* tag) {
50
return AddHtmlTag(tag, strlen(tag));
53
// Find returns a value in the half-open range [0..GetIndexMax()).
55
COMPILE_ASSERT(kHtmlTagUnknown == 0, unknown_tag_equals_zero);
56
int FindHtmlTag(const char* tag, int length) const;
57
int FindHtmlTag(const char* tag) const {
58
return FindHtmlTag(tag, strlen(tag));
61
// Return the half-open upper bound on lookup return value.
62
// If GetIndexMax returns 10, then find will return [0..9).
63
int GetIndexMax() const {
67
// Set case sensitivity. This cannot be done after any calls to AddHtmlTag.
68
void SetCaseSensitive(bool case_sensitive);
69
bool IsCaseSensitive() const {
70
return case_sensitive_;
74
// Case sensitive stuff.
75
bool case_sensitive_fixed_;
87
typedef dense_hash_map<string, int> CustomTagMap;
88
scoped_ptr<CustomTagMap> custom_tag_map_;
90
DISALLOW_COPY_AND_ASSIGN(HtmlTagIndex);
93
#endif // WEBUTIL_HTML_HTMLTAGINDEX_H__