2 * Copyright (C) 2007, 2008, 2010, 2011, 2012 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/RefCounted.h"
25 #include "wtf/Vector.h"
26 #include "wtf/text/AtomicString.h"
30 class SpaceSplitStringData : public RefCounted<SpaceSplitStringData> {
32 static PassRefPtr<SpaceSplitStringData> create(const AtomicString&);
33 static PassRefPtr<SpaceSplitStringData> createUnique(const SpaceSplitStringData&);
35 ~SpaceSplitStringData();
37 bool contains(const AtomicString& string)
39 size_t size = m_vector.size();
40 for (size_t i = 0; i < size; ++i) {
41 if (m_vector[i] == string)
47 bool containsAll(SpaceSplitStringData&);
49 void add(const AtomicString&);
50 void remove(unsigned index);
52 bool isUnique() const { return m_keyString.isNull(); }
53 size_t size() const { return m_vector.size(); }
54 const AtomicString& operator[](size_t i) { ASSERT_WITH_SECURITY_IMPLICATION(i < size()); return m_vector[i]; }
57 explicit SpaceSplitStringData(const AtomicString&);
58 explicit SpaceSplitStringData(const SpaceSplitStringData&);
60 void createVector(const String&);
61 template <typename CharacterType>
62 inline void createVector(const CharacterType*, unsigned);
64 AtomicString m_keyString;
65 Vector<AtomicString, 4> m_vector;
68 class SpaceSplitString {
70 SpaceSplitString() { }
71 SpaceSplitString(const AtomicString& string, bool shouldFoldCase) { set(string, shouldFoldCase); }
73 bool operator!=(const SpaceSplitString& other) const { return m_data != other.m_data; }
75 void set(const AtomicString&, bool shouldFoldCase);
76 void clear() { m_data.clear(); }
78 bool contains(const AtomicString& string) const { return m_data && m_data->contains(string); }
79 bool containsAll(const SpaceSplitString& names) const { return !names.m_data || (m_data && m_data->containsAll(*names.m_data)); }
80 void add(const AtomicString&);
81 bool remove(const AtomicString&);
83 size_t size() const { return m_data ? m_data->size() : 0; }
84 bool isNull() const { return !m_data; }
85 const AtomicString& operator[](size_t i) const { ASSERT_WITH_SECURITY_IMPLICATION(i < size()); return (*m_data)[i]; }
90 if (m_data && !m_data->isUnique())
91 m_data = SpaceSplitStringData::createUnique(*m_data);
94 RefPtr<SpaceSplitStringData> m_data;
99 #endif // SpaceSplitString_h