]>
Commit | Line | Data |
---|---|---|
a90939db JF |
1 | /* |
2 | * Copyright (C) 2007, 2008 Apple Inc. All rights reserved. | |
3 | * | |
4 | * This library is free software; you can redistribute it and/or | |
5 | * modify it under the terms of the GNU Library General Public | |
6 | * License as published by the Free Software Foundation; either | |
7 | * version 2 of the License, or (at your option) any later version. | |
8 | * | |
9 | * This library is distributed in the hope that it will be useful, | |
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
12 | * Library General Public License for more details. | |
13 | * | |
14 | * You should have received a copy of the GNU Library General Public License | |
15 | * along with this library; see the file COPYING.LIB. If not, write to | |
16 | * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
17 | * Boston, MA 02111-1307, USA. | |
18 | * | |
19 | */ | |
20 | ||
21 | #ifndef ClassNames_h | |
22 | #define ClassNames_h | |
23 | ||
24 | #include "AtomicString.h" | |
25 | #include <wtf/OwnPtr.h> | |
26 | #include <wtf/Vector.h> | |
27 | ||
28 | namespace WebCore { | |
29 | ||
30 | class ClassNamesData : Noncopyable { | |
31 | public: | |
32 | ClassNamesData(const String& string, bool shouldFoldCase) | |
33 | : m_string(string), m_shouldFoldCase(shouldFoldCase), m_createdVector(false) | |
34 | { | |
35 | } | |
36 | ||
37 | bool contains(const AtomicString& string) | |
38 | { | |
39 | ensureVector(); | |
40 | size_t size = m_vector.size(); | |
41 | for (size_t i = 0; i < size; ++i) { | |
42 | if (m_vector[i] == string) | |
43 | return true; | |
44 | } | |
45 | return false; | |
46 | } | |
47 | ||
48 | bool containsAll(ClassNamesData&); | |
49 | ||
50 | size_t size() { ensureVector(); return m_vector.size(); } | |
51 | const AtomicString& operator[](size_t i) { ensureVector(); ASSERT(i < size()); return m_vector[i]; } | |
52 | ||
53 | private: | |
54 | void ensureVector() { if (!m_createdVector) createVector(); } | |
55 | void createVector(); | |
56 | ||
57 | typedef Vector<AtomicString, 8> ClassNameVector; | |
58 | String m_string; | |
59 | bool m_shouldFoldCase; | |
60 | ClassNameVector m_vector; | |
61 | bool m_createdVector; | |
62 | }; | |
63 | ||
64 | class ClassNames { | |
65 | public: | |
66 | ClassNames() { } | |
67 | ClassNames(const String& string, bool shouldFoldCase) : m_data(new ClassNamesData(string, shouldFoldCase)) { } | |
68 | ||
69 | void set(const String& string, bool shouldFoldCase) { m_data.set(new ClassNamesData(string, shouldFoldCase)); } | |
70 | void clear() { m_data.clear(); } | |
71 | ||
72 | bool contains(const AtomicString& string) const { return m_data && m_data->contains(string); } | |
73 | bool containsAll(const ClassNames& names) const { return !names.m_data || (m_data && m_data->containsAll(*names.m_data)); } | |
74 | ||
75 | size_t size() const { return m_data ? m_data->size() : 0; } | |
76 | const AtomicString& operator[](size_t i) const { ASSERT(i < size()); return (*m_data)[i]; } | |
77 | ||
78 | private: | |
79 | OwnPtr<ClassNamesData> m_data; | |
80 | }; | |
81 | ||
82 | inline bool isClassWhitespace(UChar c) | |
83 | { | |
84 | return c == ' ' || c == '\r' || c == '\n' || c == '\t' || c == '\f'; | |
85 | } | |
86 | ||
87 | } // namespace WebCore | |
88 | ||
89 | #endif // ClassNames_h |