2 * Copyright (C) 2007, 2008, 2010 Apple Inc. All rights reserved.
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.
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.
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.
21 #ifndef SpaceSplitString_h
22 #define SpaceSplitString_h
24 #include <wtf/OwnPtr.h>
25 #include <wtf/PassOwnPtr.h>
26 #include <wtf/Vector.h>
27 #include <wtf/text/AtomicString.h>
31 class SpaceSplitStringData {
32 WTF_MAKE_NONCOPYABLE(SpaceSplitStringData); WTF_MAKE_FAST_ALLOCATED;
34 SpaceSplitStringData(const String& string, bool shouldFoldCase)
35 : m_string(string), m_shouldFoldCase(shouldFoldCase), m_createdVector(false)
39 bool contains(const AtomicString& string)
42 size_t size = m_vector.size();
43 for (size_t i = 0; i < size; ++i) {
44 if (m_vector[i] == string)
50 bool containsAll(SpaceSplitStringData&);
52 void add(const AtomicString&);
53 void remove(const AtomicString&);
55 size_t size() { ensureVector(); return m_vector.size(); }
56 const AtomicString& operator[](size_t i) { ensureVector(); ASSERT(i < size()); return m_vector[i]; }
59 void ensureVector() { if (!m_createdVector) createVector(); }
62 typedef Vector<AtomicString, 8> StringVector;
64 StringVector m_vector;
65 bool m_shouldFoldCase;
69 class SpaceSplitString {
71 SpaceSplitString() { }
72 SpaceSplitString(const String& string, bool shouldFoldCase) : m_data(adoptPtr(new SpaceSplitStringData(string, shouldFoldCase))) { }
74 void set(const String& string, bool shouldFoldCase) { m_data = adoptPtr(new SpaceSplitStringData(string, shouldFoldCase)); }
75 void clear() { m_data.clear(); }
77 bool contains(const AtomicString& string) const { return m_data && m_data->contains(string); }
78 bool containsAll(const SpaceSplitString& names) const { return !names.m_data || (m_data && m_data->containsAll(*names.m_data)); }
79 void add(const AtomicString&);
80 void remove(const AtomicString&);
82 size_t size() const { return m_data ? m_data->size() : 0; }
83 bool isNull() const { return !m_data; }
84 const AtomicString& operator[](size_t i) const { ASSERT(i < size()); return (*m_data)[i]; }
87 OwnPtr<SpaceSplitStringData> m_data;
90 } // namespace WebCore
92 #endif // SpaceSplitString_h