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#include "SVGLengthList.h"
23
24#include "SVGParserUtilities.h"
25#include <wtf/text/StringBuilder.h>
26
27namespace WebCore {
28
29void SVGLengthList::parse(const String& value, SVGLengthMode mode)
30{
31    clear();
32    ExceptionCode ec = 0;
33
34    auto upconvertedCharacters = StringView(value).upconvertedCharacters();
35    const UChar* ptr = upconvertedCharacters;
36    const UChar* end = ptr + value.length();
37    while (ptr < end) {
38        const UChar* start = ptr;
39        while (ptr < end && *ptr != ',' && !isSVGSpace(*ptr))
40            ptr++;
41        if (ptr == start)
42            break;
43
44        SVGLength length(mode);
45        String valueString(start, ptr - start);
46        if (valueString.isEmpty())
47            return;
48        length.setValueAsString(valueString, ec);
49        if (ec)
50            return;
51        append(length);
52        skipOptionalSVGSpacesOrDelimiter(ptr, end);
53    }
54}
55
56String SVGLengthList::valueAsString() const
57{
58    StringBuilder builder;
59
60    unsigned size = this->size();
61    for (unsigned i = 0; i < size; ++i) {
62        if (i > 0)
63            builder.append(' ');
64
65        builder.append(at(i).valueAsString());
66    }
67
68    return builder.toString();
69}
70
71}
72