]>
git.saurik.com Git - iphone-api.git/blob - WebCore/ClassNames.h
2 * Copyright (C) 2007, 2008 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.
24 #include "AtomicString.h"
25 #include <wtf/OwnPtr.h>
26 #include <wtf/Vector.h>
30 class ClassNamesData
: Noncopyable
{
32 ClassNamesData(const String
& string
, bool shouldFoldCase
)
33 : m_string(string
), m_shouldFoldCase(shouldFoldCase
), m_createdVector(false)
37 bool contains(const AtomicString
& string
)
40 size_t size
= m_vector
.size();
41 for (size_t i
= 0; i
< size
; ++i
) {
42 if (m_vector
[i
] == string
)
48 bool containsAll(ClassNamesData
&);
50 size_t size() { ensureVector(); return m_vector
.size(); }
51 const AtomicString
& operator[](size_t i
) { ensureVector(); ASSERT(i
< size()); return m_vector
[i
]; }
54 void ensureVector() { if (!m_createdVector
) createVector(); }
57 typedef Vector
<AtomicString
, 8> ClassNameVector
;
59 bool m_shouldFoldCase
;
60 ClassNameVector m_vector
;
67 ClassNames(const String
& string
, bool shouldFoldCase
) : m_data(new ClassNamesData(string
, shouldFoldCase
)) { }
69 void set(const String
& string
, bool shouldFoldCase
) { m_data
.set(new ClassNamesData(string
, shouldFoldCase
)); }
70 void clear() { m_data
.clear(); }
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
)); }
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
]; }
79 OwnPtr
<ClassNamesData
> m_data
;
82 inline bool isClassWhitespace(UChar c
)
84 return c
== ' ' || c
== '\r' || c
== '\n' || c
== '\t' || c
== '\f';
87 } // namespace WebCore
89 #endif // ClassNames_h