| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2007, 2008, 2010, 2011, 2012 Apple Inc. All rights reserved. | 2 * Copyright (C) 2007, 2008, 2010, 2011, 2012 Apple Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * This library is free software; you can redistribute it and/or | 4 * This library is free software; you can redistribute it and/or |
| 5 * modify it under the terms of the GNU Library General Public | 5 * modify it under the terms of the GNU Library General Public |
| 6 * License as published by the Free Software Foundation; either | 6 * License as published by the Free Software Foundation; either |
| 7 * version 2 of the License, or (at your option) any later version. | 7 * version 2 of the License, or (at your option) any later version. |
| 8 * | 8 * |
| 9 * This library is distributed in the hope that it will be useful, | 9 * This library is distributed in the hope that it will be useful, |
| 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 12 * Library General Public License for more details. | 12 * Library General Public License for more details. |
| 13 * | 13 * |
| 14 * You should have received a copy of the GNU Library General Public License | 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 | 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, | 16 * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
| 17 * Boston, MA 02111-1307, USA. | 17 * Boston, MA 02111-1307, USA. |
| 18 * | 18 * |
| 19 */ | 19 */ |
| 20 | 20 |
| 21 #ifndef SpaceSplitString_h | 21 #ifndef SpaceSplitString_h |
| 22 #define SpaceSplitString_h | 22 #define SpaceSplitString_h |
| 23 | 23 |
| 24 #include "wtf/RefCounted.h" | 24 #include "wtf/RefCounted.h" |
| 25 #include "wtf/Vector.h" | 25 #include "wtf/Vector.h" |
| 26 #include "wtf/text/AtomicString.h" | 26 #include "wtf/text/AtomicString.h" |
| 27 | 27 |
| 28 namespace blink { | 28 namespace blink { |
| 29 | 29 |
| 30 class SpaceSplitStringData : public RefCounted<SpaceSplitStringData> { | 30 class SpaceSplitString { |
| 31 public: |
| 32 SpaceSplitString() { } |
| 33 SpaceSplitString(const AtomicString& string, bool shouldFoldCase) { set(stri
ng, shouldFoldCase); } |
| 34 |
| 35 bool operator!=(const SpaceSplitString& other) const { return m_data != othe
r.m_data; } |
| 36 |
| 37 void set(const AtomicString&, bool shouldFoldCase); |
| 38 void clear() { m_data.clear(); } |
| 39 |
| 40 bool contains(const AtomicString& string) const { return m_data && m_data->c
ontains(string); } |
| 41 bool containsAll(const SpaceSplitString& names) const { return !names.m_data
|| (m_data && m_data->containsAll(*names.m_data)); } |
| 42 void add(const AtomicString&); |
| 43 bool remove(const AtomicString&); |
| 44 |
| 45 size_t size() const { return m_data ? m_data->size() : 0; } |
| 46 bool isNull() const { return !m_data; } |
| 47 const AtomicString& operator[](size_t i) const { ASSERT_WITH_SECURITY_IMPLIC
ATION(i < size()); return (*m_data)[i]; } |
| 48 |
| 49 private: |
| 50 class Data : public RefCounted<Data> { |
| 31 public: | 51 public: |
| 32 static PassRefPtr<SpaceSplitStringData> create(const AtomicString&); | 52 static PassRefPtr<Data> create(const AtomicString&); |
| 33 static PassRefPtr<SpaceSplitStringData> createUnique(const SpaceSplitStr
ingData&); | 53 static PassRefPtr<Data> createUnique(const Data&); |
| 34 | 54 |
| 35 ~SpaceSplitStringData(); | 55 ~Data(); |
| 36 | 56 |
| 37 bool contains(const AtomicString& string) | 57 bool contains(const AtomicString& string) |
| 38 { | 58 { |
| 39 size_t size = m_vector.size(); | 59 size_t size = m_vector.size(); |
| 40 for (size_t i = 0; i < size; ++i) { | 60 for (size_t i = 0; i < size; ++i) { |
| 41 if (m_vector[i] == string) | 61 if (m_vector[i] == string) |
| 42 return true; | 62 return true; |
| 43 } | 63 } |
| 44 return false; | 64 return false; |
| 45 } | 65 } |
| 46 | 66 |
| 47 bool containsAll(SpaceSplitStringData&); | 67 bool containsAll(Data&); |
| 48 | 68 |
| 49 void add(const AtomicString&); | 69 void add(const AtomicString&); |
| 50 void remove(unsigned index); | 70 void remove(unsigned index); |
| 51 | 71 |
| 52 bool isUnique() const { return m_keyString.isNull(); } | 72 bool isUnique() const { return m_keyString.isNull(); } |
| 53 size_t size() const { return m_vector.size(); } | 73 size_t size() const { return m_vector.size(); } |
| 54 const AtomicString& operator[](size_t i) { ASSERT_WITH_SECURITY_IMPLICAT
ION(i < size()); return m_vector[i]; } | 74 const AtomicString& operator[](size_t i) { ASSERT_WITH_SECURITY_IMPLICAT
ION(i < size()); return m_vector[i]; } |
| 55 | 75 |
| 56 private: | 76 private: |
| 57 explicit SpaceSplitStringData(const AtomicString&); | 77 explicit Data(const AtomicString&); |
| 58 explicit SpaceSplitStringData(const SpaceSplitStringData&); | 78 explicit Data(const Data&); |
| 59 | 79 |
| 60 void createVector(const String&); | 80 void createVector(const String&); |
| 61 template <typename CharacterType> | 81 template <typename CharacterType> |
| 62 inline void createVector(const CharacterType*, unsigned); | 82 inline void createVector(const CharacterType*, unsigned); |
| 63 | 83 |
| 64 AtomicString m_keyString; | 84 AtomicString m_keyString; |
| 65 Vector<AtomicString, 4> m_vector; | 85 Vector<AtomicString, 4> m_vector; |
| 66 }; | 86 }; |
| 87 typedef HashMap<AtomicString, Data*> DataMap; |
| 67 | 88 |
| 68 class SpaceSplitString { | 89 static DataMap& sharedDataMap(); |
| 69 public: | |
| 70 SpaceSplitString() { } | |
| 71 SpaceSplitString(const AtomicString& string, bool shouldFoldCase) { set(
string, shouldFoldCase); } | |
| 72 | 90 |
| 73 bool operator!=(const SpaceSplitString& other) const { return m_data !=
other.m_data; } | 91 void ensureUnique() |
| 92 { |
| 93 if (m_data && !m_data->isUnique()) |
| 94 m_data = Data::createUnique(*m_data); |
| 95 } |
| 74 | 96 |
| 75 void set(const AtomicString&, bool shouldFoldCase); | 97 RefPtr<Data> m_data; |
| 76 void clear() { m_data.clear(); } | 98 }; |
| 77 | |
| 78 bool contains(const AtomicString& string) const { return m_data && m_dat
a->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&); | |
| 82 | |
| 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_IM
PLICATION(i < size()); return (*m_data)[i]; } | |
| 86 | |
| 87 private: | |
| 88 void ensureUnique() | |
| 89 { | |
| 90 if (m_data && !m_data->isUnique()) | |
| 91 m_data = SpaceSplitStringData::createUnique(*m_data); | |
| 92 } | |
| 93 | |
| 94 RefPtr<SpaceSplitStringData> m_data; | |
| 95 }; | |
| 96 | 99 |
| 97 } // namespace blink | 100 } // namespace blink |
| 98 | 101 |
| 99 #endif // SpaceSplitString_h | 102 #endif // SpaceSplitString_h |
| OLD | NEW |