OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "core/svg/SVGParsingError.h" | 5 #include "core/svg/SVGParsingError.h" |
6 | 6 |
7 #include "core/dom/QualifiedName.h" | 7 #include "core/dom/QualifiedName.h" |
8 #include "platform/JSONValues.h" | 8 #include "platform/JSONValues.h" |
9 #include "wtf/text/CharacterNames.h" | 9 #include "wtf/text/CharacterNames.h" |
10 #include "wtf/text/StringBuilder.h" | 10 #include "wtf/text/StringBuilder.h" |
11 | 11 |
12 #include <utility> | 12 #include <utility> |
13 | 13 |
14 namespace blink { | 14 namespace blink { |
15 | 15 |
16 namespace { | 16 namespace { |
17 | 17 |
18 void appendErrorContextInfo(StringBuilder& builder, const String& tagName, const
QualifiedName& name) | 18 void appendErrorContextInfo(StringBuilder& builder, const String& tagName, const
QualifiedName& name) |
19 { | 19 { |
20 builder.append('<'); | 20 builder.append('<'); |
21 builder.append(tagName); | 21 builder.append(tagName); |
22 builder.appendLiteral("> attribute "); | 22 builder.append("> attribute "); |
23 builder.append(name.toString()); | 23 builder.append(name.toString()); |
24 } | 24 } |
25 | 25 |
26 std::pair<const char*, const char*> messageForStatus(SVGParseStatus status) | 26 std::pair<const char*, const char*> messageForStatus(SVGParseStatus status) |
27 { | 27 { |
28 switch (status) { | 28 switch (status) { |
29 case SVGParseStatus::TrailingGarbage: | 29 case SVGParseStatus::TrailingGarbage: |
30 return std::make_pair("Trailing garbage, ", "."); | 30 return std::make_pair("Trailing garbage, ", "."); |
31 case SVGParseStatus::ExpectedAngle: | 31 case SVGParseStatus::ExpectedAngle: |
32 return std::make_pair("Expected angle, ", "."); | 32 return std::make_pair("Expected angle, ", "."); |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 builder.append('"'); | 101 builder.append('"'); |
102 } | 102 } |
103 | 103 |
104 } // namespace | 104 } // namespace |
105 | 105 |
106 String SVGParsingError::format(const String& tagName, const QualifiedName& name,
const AtomicString& value) const | 106 String SVGParsingError::format(const String& tagName, const QualifiedName& name,
const AtomicString& value) const |
107 { | 107 { |
108 StringBuilder builder; | 108 StringBuilder builder; |
109 | 109 |
110 appendErrorContextInfo(builder, tagName, name); | 110 appendErrorContextInfo(builder, tagName, name); |
111 builder.appendLiteral(": "); | 111 builder.append(": "); |
112 | 112 |
113 if (hasLocus() && locus() == value.length()) | 113 if (hasLocus() && locus() == value.length()) |
114 builder.appendLiteral("Unexpected end of attribute. "); | 114 builder.append("Unexpected end of attribute. "); |
115 | 115 |
116 auto message = messageForStatus(status()); | 116 auto message = messageForStatus(status()); |
117 builder.append(message.first); | 117 builder.append(message.first); |
118 appendValue(builder, *this, value); | 118 appendValue(builder, *this, value); |
119 builder.append(message.second); | 119 builder.append(message.second); |
120 return builder.toString(); | 120 return builder.toString(); |
121 } | 121 } |
122 | 122 |
123 } // namespace blink | 123 } // namespace blink |
OLD | NEW |