2 * Copyright (C) 2007 David Smith (catfish.man@gmail.com)
3 * Copyright (C) 2007, 2008 Apple Inc. All rights reserved.
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.
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.
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.
22 #include "SpaceSplitString.h"
24 #include "HTMLParserIdioms.h"
25 #include <wtf/ASCIICType.h>
26 #include <wtf/text/StringBuilder.h>
32 static bool hasNonASCIIOrUpper(const String& string)
34 const UChar* characters = string.characters();
35 unsigned length = string.length();
36 bool hasUpper = false;
38 for (unsigned i = 0; i < length; i++) {
39 UChar c = characters[i];
40 hasUpper |= isASCIIUpper(c);
43 return hasUpper || (ored & ~0x7F);
46 void SpaceSplitStringData::createVector()
48 ASSERT(!m_createdVector);
49 ASSERT(m_vector.isEmpty());
51 if (m_shouldFoldCase && hasNonASCIIOrUpper(m_string))
52 m_string = m_string.foldCase();
54 const UChar* characters = m_string.characters();
55 unsigned length = m_string.length();
58 while (start < length && isHTMLSpace(characters[start]))
62 unsigned end = start + 1;
63 while (end < length && isNotHTMLSpace(characters[end]))
66 m_vector.append(AtomicString(characters + start, end - start));
72 m_createdVector = true;
75 bool SpaceSplitStringData::containsAll(SpaceSplitStringData& other)
79 size_t thisSize = m_vector.size();
80 size_t otherSize = other.m_vector.size();
81 for (size_t i = 0; i < otherSize; ++i) {
82 const AtomicString& name = other.m_vector[i];
84 for (j = 0; j < thisSize; ++j) {
85 if (m_vector[j] == name)
94 void SpaceSplitStringData::add(const AtomicString& string)
99 m_vector.append(string);
102 void SpaceSplitStringData::remove(const AtomicString& string)
107 while (position < m_vector.size()) {
108 if (m_vector[position] == string)
109 m_vector.remove(position);
115 void SpaceSplitString::add(const AtomicString& string)
121 void SpaceSplitString::remove(const AtomicString& string)
124 m_data->remove(string);
127 } // namespace WebCore