File indexing completed on 2024-04-28 11:39:26

0001 /*
0002  * Copyright (C) 2007, 2008 Apple Inc. All rights reserved.
0003  *
0004  * This library is free software; you can redistribute it and/or
0005  * modify it under the terms of the GNU Library General Public
0006  * License as published by the Free Software Foundation; either
0007  * version 2 of the License, or (at your option) any later version.
0008  *
0009  * This library is distributed in the hope that it will be useful,
0010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
0011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0012  * Library General Public License for more details.
0013  *
0014  * You should have received a copy of the GNU Library General Public License
0015  * along with this library; see the file COPYING.LIB.  If not, write to
0016  * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
0017  * Boston, MA 02111-1307, USA.
0018  *
0019  */
0020 
0021 #ifndef ClassNames_h
0022 #define ClassNames_h
0023 
0024 #include "misc/AtomicString.h"
0025 #include <wtf/Vector.h>
0026 #include <wtf/OwnPtr.h>
0027 
0028 using khtml::AtomicString;
0029 
0030 namespace DOM
0031 {
0032 
0033 class ClassNames
0034 {
0035     typedef Vector<khtml::AtomicString, 8> ClassNameVector;
0036 public:
0037     ClassNames()
0038     {
0039     }
0040 
0041     bool contains(const khtml::AtomicString &str) const
0042     {
0043         if (!m_nameVector) {
0044             return false;
0045         }
0046 
0047         size_t size = m_nameVector->size();
0048         for (size_t i = 0; i < size; ++i) {
0049             if (m_nameVector->at(i) == str) {
0050                 return true;
0051             }
0052         }
0053 
0054         return false;
0055     }
0056 
0057     void parseClassAttribute(const DOMString &, bool inCompatMode);
0058 
0059     size_t size() const
0060     {
0061         return m_nameVector ? m_nameVector->size() : 0;
0062     }
0063     void clear()
0064     {
0065         if (m_nameVector) {
0066             m_nameVector->clear();
0067         }
0068     }
0069     const khtml::AtomicString &operator[](size_t i) const
0070     {
0071         ASSERT(m_nameVector);
0072         return m_nameVector->at(i);
0073     }
0074 
0075 private:
0076     OwnPtr<ClassNameVector> m_nameVector;
0077 };
0078 
0079 inline static bool isClassWhitespace(const QChar &c)
0080 {
0081     unsigned short u = c.unicode();
0082     if (u > 0x20) {
0083         return false;
0084     }
0085     return u == ' ' || u == '\r' || u == '\n' || u == '\t' || u == '\f';
0086 }
0087 
0088 } // namespace DOM
0089 
0090 #endif // ClassNames_h