OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2004, 2005, 2008 Nikolas Zimmermann <zimmermann@kde.org> | 2 * Copyright (C) 2004, 2005, 2008 Nikolas Zimmermann <zimmermann@kde.org> |
3 * Copyright (C) 2004, 2005, 2006 Rob Buis <buis@kde.org> | 3 * Copyright (C) 2004, 2005, 2006 Rob Buis <buis@kde.org> |
4 * | 4 * |
5 * This library is free software; you can redistribute it and/or | 5 * This library is free software; you can redistribute it and/or |
6 * modify it under the terms of the GNU Library General Public | 6 * modify it under the terms of the GNU Library General Public |
7 * License as published by the Free Software Foundation; either | 7 * License as published by the Free Software Foundation; either |
8 * version 2 of the License, or (at your option) any later version. | 8 * version 2 of the License, or (at your option) any later version. |
9 * | 9 * |
10 * This library is distributed in the hope that it will be useful, | 10 * This library is distributed in the hope that it will be useful, |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
48 for (; it != itEnd; ++it) { | 48 for (; it != itEnd; ++it) { |
49 builder.append(' '); | 49 builder.append(' '); |
50 builder.append(it->valueAsString()); | 50 builder.append(it->valueAsString()); |
51 } | 51 } |
52 } | 52 } |
53 | 53 |
54 return builder.toString(); | 54 return builder.toString(); |
55 } | 55 } |
56 | 56 |
57 template <typename CharType> | 57 template <typename CharType> |
58 bool SVGNumberList::parse(const CharType*& ptr, const CharType* end) | 58 SVGParsingError SVGNumberList::parse(const CharType*& ptr, const CharType* end) |
59 { | 59 { |
60 clear(); | 60 const CharType* listStart = ptr; |
61 | |
62 while (ptr < end) { | 61 while (ptr < end) { |
63 float number = 0; | 62 float number = 0; |
64 if (!parseNumber(ptr, end, number)) | 63 if (!parseNumber(ptr, end, number)) |
65 return false; | 64 return SVGParsingError(SVGParseStatus::ExpectedNumber, ptr - listSta
rt); |
66 append(SVGNumber::create(number)); | 65 append(SVGNumber::create(number)); |
67 } | 66 } |
68 | 67 return SVGParseStatus::NoError; |
69 return true; | |
70 } | 68 } |
71 | 69 |
72 SVGParsingError SVGNumberList::setValueAsString(const String& value) | 70 SVGParsingError SVGNumberList::setValueAsString(const String& value) |
73 { | 71 { |
74 if (value.isEmpty()) { | 72 clear(); |
75 clear(); | 73 |
| 74 if (value.isEmpty()) |
76 return SVGParseStatus::NoError; | 75 return SVGParseStatus::NoError; |
77 } | |
78 | 76 |
79 bool valid = false; | 77 // Don't call |clear()| if an error is encountered. SVG policy is to use |
| 78 // valid items before error. |
| 79 // Spec: http://www.w3.org/TR/SVG/single-page.html#implnote-ErrorProcessing |
80 if (value.is8Bit()) { | 80 if (value.is8Bit()) { |
81 const LChar* ptr = value.characters8(); | 81 const LChar* ptr = value.characters8(); |
82 const LChar* end = ptr + value.length(); | 82 const LChar* end = ptr + value.length(); |
83 valid = parse(ptr, end); | 83 return parse(ptr, end); |
84 } else { | |
85 const UChar* ptr = value.characters16(); | |
86 const UChar* end = ptr + value.length(); | |
87 valid = parse(ptr, end); | |
88 } | 84 } |
89 | 85 const UChar* ptr = value.characters16(); |
90 if (!valid) { | 86 const UChar* end = ptr + value.length(); |
91 // No call to |clear()| here. SVG policy is to use valid items before er
ror. | 87 return parse(ptr, end); |
92 // Spec: http://www.w3.org/TR/SVG/single-page.html#implnote-ErrorProcess
ing | |
93 return SVGParseStatus::ParsingFailed; | |
94 } | |
95 return SVGParseStatus::NoError; | |
96 } | 88 } |
97 | 89 |
98 void SVGNumberList::add(PassRefPtrWillBeRawPtr<SVGPropertyBase> other, SVGElemen
t* contextElement) | 90 void SVGNumberList::add(PassRefPtrWillBeRawPtr<SVGPropertyBase> other, SVGElemen
t* contextElement) |
99 { | 91 { |
100 RefPtrWillBeRawPtr<SVGNumberList> otherList = toSVGNumberList(other); | 92 RefPtrWillBeRawPtr<SVGNumberList> otherList = toSVGNumberList(other); |
101 | 93 |
102 if (length() != otherList->length()) | 94 if (length() != otherList->length()) |
103 return; | 95 return; |
104 | 96 |
105 for (size_t i = 0; i < length(); ++i) | 97 for (size_t i = 0; i < length(); ++i) |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
139 Vector<float> SVGNumberList::toFloatVector() const | 131 Vector<float> SVGNumberList::toFloatVector() const |
140 { | 132 { |
141 Vector<float> vec; | 133 Vector<float> vec; |
142 vec.reserveInitialCapacity(length()); | 134 vec.reserveInitialCapacity(length()); |
143 for (size_t i = 0; i < length(); ++i) | 135 for (size_t i = 0; i < length(); ++i) |
144 vec.uncheckedAppend(at(i)->value()); | 136 vec.uncheckedAppend(at(i)->value()); |
145 return vec; | 137 return vec; |
146 } | 138 } |
147 | 139 |
148 } | 140 } |
OLD | NEW |