Rubber-stamped by Brady Eidson.
[webbrowser.git] / WebCore / dom / SpaceSplitString.cpp
blobb062dbf133c440d55ba92c9b03c5013b607a2b3c
1 /*
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.
21 #include "config.h"
22 #include "SpaceSplitString.h"
24 #include <wtf/ASCIICType.h>
26 using namespace WTF;
28 namespace WebCore {
30 static bool hasNonASCIIOrUpper(const String& string)
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;
41 return hasUpper || (ored & ~0x7F);
44 void SpaceSplitStringData::createVector()
46 ASSERT(!m_createdVector);
47 ASSERT(m_vector.isEmpty());
49 if (m_shouldFoldCase && hasNonASCIIOrUpper(m_string))
50 m_string = m_string.foldCase();
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;
64 m_vector.append(AtomicString(characters + start, end - start));
66 start = end + 1;
69 m_string = String();
70 m_createdVector = true;
73 bool SpaceSplitStringData::containsAll(SpaceSplitStringData& other)
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;
86 if (j == thisSize)
87 return false;
89 return true;
92 } // namespace WebCore