1/*
2 * Copyright (C) 2004, 2005, 2008 Nikolas Zimmermann <zimmermann@kde.org>
3 * Copyright (C) 2004, 2005, 2006 Rob Buis <buis@kde.org>
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., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
19 */
20
21#include "config.h"
22
23#if ENABLE(SVG)
24#include "SVGStringList.h"
25
26#include "SVGElement.h"
27#include "SVGParserUtilities.h"
28#include <wtf/text/StringBuilder.h>
29
30namespace WebCore {
31
32void SVGStringList::commitChange(SVGElement* contextElement)
33{
34    ASSERT(contextElement);
35    contextElement->invalidateSVGAttributes();
36    contextElement->svgAttributeChanged(m_attributeName);
37}
38
39void SVGStringList::reset(const String& string)
40{
41    parse(string, ' ');
42
43    // Add empty string, if list is empty.
44    if (isEmpty())
45        append(String(""));
46}
47
48void SVGStringList::parse(const String& data, UChar delimiter)
49{
50    // TODO : more error checking/reporting
51    clear();
52
53    const UChar* ptr = data.characters();
54    const UChar* end = ptr + data.length();
55    while (ptr < end) {
56        const UChar* start = ptr;
57        while (ptr < end && *ptr != delimiter && !isWhitespace(*ptr))
58            ptr++;
59        if (ptr == start)
60            break;
61        append(String(start, ptr - start));
62        skipOptionalSpacesOrDelimiter(ptr, end, delimiter);
63    }
64}
65
66String SVGStringList::valueAsString() const
67{
68    StringBuilder builder;
69
70    unsigned size = this->size();
71    for (unsigned i = 0; i < size; ++i) {
72        if (i > 0)
73            builder.append(' ');
74
75        builder.append(at(i));
76    }
77
78    return builder.toString();
79}
80
81}
82
83#endif // ENABLE(SVG)
84