Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(274)

Side by Side Diff: third_party/WebKit/Source/core/svg/SVGPointList.cpp

Issue 1620203002: Extended error reporting for SVGNumber/Point/Rect and related types (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Blind is blind. Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2004, 2005, 2006, 2008 Nikolas Zimmermann <zimmermann@kde.org> 2 * Copyright (C) 2004, 2005, 2006, 2008 Nikolas Zimmermann <zimmermann@kde.org>
3 * Copyright (C) 2004, 2005 Rob Buis <buis@kde.org> 3 * Copyright (C) 2004, 2005 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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 for (; it != itEnd; ++it) { 49 for (; it != itEnd; ++it) {
50 builder.append(' '); 50 builder.append(' ');
51 builder.append(it->valueAsString()); 51 builder.append(it->valueAsString());
52 } 52 }
53 } 53 }
54 54
55 return builder.toString(); 55 return builder.toString();
56 } 56 }
57 57
58 template <typename CharType> 58 template <typename CharType>
59 bool SVGPointList::parse(const CharType*& ptr, const CharType* end) 59 SVGParsingError SVGPointList::parse(const CharType*& ptr, const CharType* end)
60 { 60 {
61 clear(); 61 if (!skipOptionalSVGSpaces(ptr, end))
62 return SVGParseStatus::NoError;
62 63
63 skipOptionalSVGSpaces(ptr, end); 64 const CharType* listStart = ptr;
64 if (ptr >= end) 65 for (;;) {
65 return true; 66 float x = 0;
67 float y = 0;
68 if (!parseNumber(ptr, end, x)
69 || !parseNumber(ptr, end, y, DisallowWhitespace))
70 return SVGParsingError(SVGParseStatus::ExpectedNumber, ptr - listSta rt);
66 71
67 for (;;) {
68 float x = 0.0f;
69 float y = 0.0f;
70 bool valid = parseNumber(ptr, end, x) && parseNumber(ptr, end, y, Disall owWhitespace);
71 if (!valid) {
72 return false;
73 }
74 append(SVGPoint::create(FloatPoint(x, y))); 72 append(SVGPoint::create(FloatPoint(x, y)));
75 73
76 skipOptionalSVGSpaces(ptr, end); 74 if (!skipOptionalSVGSpaces(ptr, end))
77 if (ptr < end && *ptr == ',') { 75 break;
76
77 if (*ptr == ',') {
78 ++ptr; 78 ++ptr;
79 skipOptionalSVGSpaces(ptr, end); 79 skipOptionalSVGSpaces(ptr, end);
80 80
81 // ',' requires the list to be continued 81 // ',' requires the list to be continued
82 continue; 82 continue;
83 } 83 }
84
85 // check end of list
86 if (ptr >= end)
87 return true;
88 } 84 }
85 return SVGParseStatus::NoError;
89 } 86 }
90 87
91 SVGParsingError SVGPointList::setValueAsString(const String& value) 88 SVGParsingError SVGPointList::setValueAsString(const String& value)
92 { 89 {
93 if (value.isEmpty()) { 90 clear();
94 clear(); 91
92 if (value.isEmpty())
95 return SVGParseStatus::NoError; 93 return SVGParseStatus::NoError;
96 }
97 94
98 bool valid = false;
99 if (value.is8Bit()) { 95 if (value.is8Bit()) {
100 const LChar* ptr = value.characters8(); 96 const LChar* ptr = value.characters8();
101 const LChar* end = ptr + value.length(); 97 const LChar* end = ptr + value.length();
102 valid = parse(ptr, end); 98 return parse(ptr, end);
103 } else {
104 const UChar* ptr = value.characters16();
105 const UChar* end = ptr + value.length();
106 valid = parse(ptr, end);
107 } 99 }
108 return valid ? SVGParseStatus::NoError : SVGParseStatus::ParsingFailed; 100 const UChar* ptr = value.characters16();
101 const UChar* end = ptr + value.length();
102 return parse(ptr, end);
109 } 103 }
110 104
111 void SVGPointList::add(PassRefPtrWillBeRawPtr<SVGPropertyBase> other, SVGElement * contextElement) 105 void SVGPointList::add(PassRefPtrWillBeRawPtr<SVGPropertyBase> other, SVGElement * contextElement)
112 { 106 {
113 RefPtrWillBeRawPtr<SVGPointList> otherList = toSVGPointList(other); 107 RefPtrWillBeRawPtr<SVGPointList> otherList = toSVGPointList(other);
114 108
115 if (length() != otherList->length()) 109 if (length() != otherList->length())
116 return; 110 return;
117 111
118 for (size_t i = 0; i < length(); ++i) 112 for (size_t i = 0; i < length(); ++i)
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 } 144 }
151 } 145 }
152 146
153 float SVGPointList::calculateDistance(PassRefPtrWillBeRawPtr<SVGPropertyBase> to , SVGElement*) 147 float SVGPointList::calculateDistance(PassRefPtrWillBeRawPtr<SVGPropertyBase> to , SVGElement*)
154 { 148 {
155 // FIXME: Distance calculation is not possible for SVGPointList right now. W e need the distance for every single value. 149 // FIXME: Distance calculation is not possible for SVGPointList right now. W e need the distance for every single value.
156 return -1; 150 return -1;
157 } 151 }
158 152
159 } 153 }
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/svg/SVGPointList.h ('k') | third_party/WebKit/Source/core/svg/SVGRect.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698