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

Side by Side Diff: third_party/WebKit/Source/core/svg/SVGRect.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
« no previous file with comments | « third_party/WebKit/Source/core/svg/SVGRect.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2004, 2005, 2006 Nikolas Zimmermann <zimmermann@kde.org> 2 * Copyright (C) 2004, 2005, 2006 Nikolas Zimmermann <zimmermann@kde.org>
3 * Copyright (C) 2004, 2005, 2006, 2007 Rob Buis <buis@kde.org> 3 * Copyright (C) 2004, 2005, 2006, 2007 Rob Buis <buis@kde.org>
4 * Copyright (C) 2007 Apple Inc. All rights reserved. 4 * Copyright (C) 2007 Apple Inc. All rights reserved.
5 * 5 *
6 * This library is free software; you can redistribute it and/or 6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public 7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either 8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version. 9 * version 2 of the License, or (at your option) any later version.
10 * 10 *
(...skipping 27 matching lines...) Expand all
38 , m_value(rect) 38 , m_value(rect)
39 { 39 {
40 } 40 }
41 41
42 PassRefPtrWillBeRawPtr<SVGRect> SVGRect::clone() const 42 PassRefPtrWillBeRawPtr<SVGRect> SVGRect::clone() const
43 { 43 {
44 return SVGRect::create(m_value); 44 return SVGRect::create(m_value);
45 } 45 }
46 46
47 template<typename CharType> 47 template<typename CharType>
48 bool SVGRect::parse(const CharType*& ptr, const CharType* end) 48 SVGParsingError SVGRect::parse(const CharType*& ptr, const CharType* end)
49 { 49 {
50 skipOptionalSVGSpaces(ptr, end); 50 const CharType* start = ptr;
51 51 float x = 0;
52 float x = 0.0f; 52 float y = 0;
53 float y = 0.0f; 53 float width = 0;
54 float width = 0.0f; 54 float height = 0;
55 float height = 0.0f; 55 if (!parseNumber(ptr, end, x)
56 bool valid = parseNumber(ptr, end, x) && parseNumber(ptr, end, y) && parseNu mber(ptr, end, width) && parseNumber(ptr, end, height, DisallowWhitespace); 56 || !parseNumber(ptr, end, y)
57 57 || !parseNumber(ptr, end, width)
58 if (!valid) 58 || !parseNumber(ptr, end, height, DisallowWhitespace))
59 return false; 59 return SVGParsingError(SVGParseStatus::ExpectedNumber, ptr - start);
60 60
61 if (skipOptionalSVGSpaces(ptr, end)) { 61 if (skipOptionalSVGSpaces(ptr, end)) {
62 // Nothing should come after the last, fourth number. 62 // Nothing should come after the last, fourth number.
63 return false; 63 return SVGParsingError(SVGParseStatus::TrailingGarbage, ptr - start);
64 } 64 }
65 65
66 m_value = FloatRect(x, y, width, height); 66 m_value = FloatRect(x, y, width, height);
67 m_isValid = true; 67 m_isValid = true;
68 return true; 68 return SVGParseStatus::NoError;
69 } 69 }
70 70
71 SVGParsingError SVGRect::setValueAsString(const String& string) 71 SVGParsingError SVGRect::setValueAsString(const String& string)
72 { 72 {
73 setInvalid(); 73 setInvalid();
74 74
75 if (string.isNull()) 75 if (string.isNull())
76 return SVGParseStatus::NoError; 76 return SVGParseStatus::NoError;
77 77
78 if (string.isEmpty()) { 78 if (string.isEmpty()) {
79 m_value = FloatRect(0.0f, 0.0f, 0.0f, 0.0f); 79 m_value = FloatRect(0.0f, 0.0f, 0.0f, 0.0f);
80 m_isValid = true; 80 m_isValid = true;
81 return SVGParseStatus::NoError; 81 return SVGParseStatus::NoError;
82 } 82 }
83 83
84 bool valid;
85 if (string.is8Bit()) { 84 if (string.is8Bit()) {
86 const LChar* ptr = string.characters8(); 85 const LChar* ptr = string.characters8();
87 const LChar* end = ptr + string.length(); 86 const LChar* end = ptr + string.length();
88 valid = parse(ptr, end); 87 return parse(ptr, end);
89 } else {
90 const UChar* ptr = string.characters16();
91 const UChar* end = ptr + string.length();
92 valid = parse(ptr, end);
93 } 88 }
94 return valid ? SVGParseStatus::NoError : SVGParseStatus::ParsingFailed; 89 const UChar* ptr = string.characters16();
90 const UChar* end = ptr + string.length();
91 return parse(ptr, end);
95 } 92 }
96 93
97 String SVGRect::valueAsString() const 94 String SVGRect::valueAsString() const
98 { 95 {
99 StringBuilder builder; 96 StringBuilder builder;
100 builder.appendNumber(x()); 97 builder.appendNumber(x());
101 builder.append(' '); 98 builder.append(' ');
102 builder.appendNumber(y()); 99 builder.appendNumber(y());
103 builder.append(' '); 100 builder.append(' ');
104 builder.appendNumber(width()); 101 builder.appendNumber(width());
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 return -1; 134 return -1;
138 } 135 }
139 136
140 void SVGRect::setInvalid() 137 void SVGRect::setInvalid()
141 { 138 {
142 m_value = FloatRect(0.0f, 0.0f, 0.0f, 0.0f); 139 m_value = FloatRect(0.0f, 0.0f, 0.0f, 0.0f);
143 m_isValid = false; 140 m_isValid = false;
144 } 141 }
145 142
146 } 143 }
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/svg/SVGRect.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698