|
1 /* |
|
2 * Copyright (C) 2007, 2008, 2010 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 SpaceSplitString_h |
|
22 #define SpaceSplitString_h |
|
23 |
|
24 #include "AtomicString.h" |
|
25 #include <wtf/OwnPtr.h> |
|
26 #include <wtf/PassOwnPtr.h> |
|
27 #include <wtf/Vector.h> |
|
28 |
|
29 namespace WebCore { |
|
30 |
|
31 class SpaceSplitStringData : public Noncopyable { |
|
32 public: |
|
33 SpaceSplitStringData(const String& string, bool shouldFoldCase) |
|
34 : m_string(string), m_shouldFoldCase(shouldFoldCase), m_createdVector(false) |
|
35 { |
|
36 } |
|
37 |
|
38 bool contains(const AtomicString& string) |
|
39 { |
|
40 ensureVector(); |
|
41 size_t size = m_vector.size(); |
|
42 for (size_t i = 0; i < size; ++i) { |
|
43 if (m_vector[i] == string) |
|
44 return true; |
|
45 } |
|
46 return false; |
|
47 } |
|
48 |
|
49 bool containsAll(SpaceSplitStringData&); |
|
50 |
|
51 size_t size() { ensureVector(); return m_vector.size(); } |
|
52 const AtomicString& operator[](size_t i) { ensureVector(); ASSERT(i < size()); return m_vector[i]; } |
|
53 |
|
54 private: |
|
55 void ensureVector() { if (!m_createdVector) createVector(); } |
|
56 void createVector(); |
|
57 |
|
58 typedef Vector<AtomicString, 8> StringVector; |
|
59 String m_string; |
|
60 StringVector m_vector; |
|
61 bool m_shouldFoldCase; |
|
62 bool m_createdVector; |
|
63 }; |
|
64 |
|
65 class SpaceSplitString { |
|
66 public: |
|
67 SpaceSplitString() { } |
|
68 SpaceSplitString(const String& string, bool shouldFoldCase) : m_data(adoptPtr(new SpaceSplitStringData(string, shouldFoldCase))) { } |
|
69 |
|
70 void set(const String& string, bool shouldFoldCase) { m_data = adoptPtr(new SpaceSplitStringData(string, shouldFoldCase)); } |
|
71 void clear() { m_data.clear(); } |
|
72 |
|
73 bool contains(const AtomicString& string) const { return m_data && m_data->contains(string); } |
|
74 bool containsAll(const SpaceSplitString& names) const { return !names.m_data || (m_data && m_data->containsAll(*names.m_data)); } |
|
75 |
|
76 size_t size() const { return m_data ? m_data->size() : 0; } |
|
77 const AtomicString& operator[](size_t i) const { ASSERT(i < size()); return (*m_data)[i]; } |
|
78 |
|
79 private: |
|
80 OwnPtr<SpaceSplitStringData> m_data; |
|
81 }; |
|
82 |
|
83 inline bool isClassWhitespace(UChar c) |
|
84 { |
|
85 return c == ' ' || c == '\r' || c == '\n' || c == '\t' || c == '\f'; |
|
86 } |
|
87 |
|
88 } // namespace WebCore |
|
89 |
|
90 #endif // SpaceSplitString_h |