Home | History | Annotate | Download | only in dom
      1 /*
      2  * Copyright (C) 2007 David Smith (catfish.man (at) gmail.com)
      3  * Copyright (C) 2007, 2008 Apple Inc. All rights reserved.
      4  *
      5  * This library is free software; you can redistribute it and/or
      6  * modify it under the terms of the GNU Library General Public
      7  * License as published by the Free Software Foundation; either
      8  * version 2 of the License, or (at your option) any later version.
      9  *
     10  * This library is distributed in the hope that it will be useful,
     11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
     12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     13  * Library General Public License for more details.
     14  *
     15  * You should have received a copy of the GNU Library General Public License
     16  * along with this library; see the file COPYING.LIB.  If not, write to
     17  * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
     18  * Boston, MA 02111-1307, USA.
     19  */
     20 
     21 #include "config.h"
     22 #include "SpaceSplitString.h"
     23 
     24 #include <wtf/ASCIICType.h>
     25 
     26 using namespace WTF;
     27 
     28 namespace WebCore {
     29 
     30 static bool hasNonASCIIOrUpper(const String& string)
     31 {
     32     const UChar* characters = string.characters();
     33     unsigned length = string.length();
     34     bool hasUpper = false;
     35     UChar ored = 0;
     36     for (unsigned i = 0; i < length; i++) {
     37         UChar c = characters[i];
     38         hasUpper |= isASCIIUpper(c);
     39         ored |= c;
     40     }
     41     return hasUpper || (ored & ~0x7F);
     42 }
     43 
     44 void SpaceSplitStringData::createVector()
     45 {
     46     ASSERT(!m_createdVector);
     47     ASSERT(m_vector.isEmpty());
     48 
     49     if (m_shouldFoldCase && hasNonASCIIOrUpper(m_string))
     50         m_string = m_string.foldCase();
     51 
     52     const UChar* characters = m_string.characters();
     53     unsigned length = m_string.length();
     54     unsigned start = 0;
     55     while (true) {
     56         while (start < length && isClassWhitespace(characters[start]))
     57             ++start;
     58         if (start >= length)
     59             break;
     60         unsigned end = start + 1;
     61         while (end < length && !isClassWhitespace(characters[end]))
     62             ++end;
     63 
     64         m_vector.append(AtomicString(characters + start, end - start));
     65 
     66         start = end + 1;
     67     }
     68 
     69     m_string = String();
     70     m_createdVector = true;
     71 }
     72 
     73 bool SpaceSplitStringData::containsAll(SpaceSplitStringData& other)
     74 {
     75     ensureVector();
     76     other.ensureVector();
     77     size_t thisSize = m_vector.size();
     78     size_t otherSize = other.m_vector.size();
     79     for (size_t i = 0; i < otherSize; ++i) {
     80         const AtomicString& name = other.m_vector[i];
     81         size_t j;
     82         for (j = 0; j < thisSize; ++j) {
     83             if (m_vector[j] == name)
     84                 break;
     85         }
     86         if (j == thisSize)
     87             return false;
     88     }
     89     return true;
     90 }
     91 
     92 } // namespace WebCore
     93