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" |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
72 // Disable locus for semantic errors and generic errors (see TODO below). | 72 // Disable locus for semantic errors and generic errors (see TODO below). |
73 return status == SVGParseStatus::NegativeValue | 73 return status == SVGParseStatus::NegativeValue |
74 || status == SVGParseStatus::ZeroValue | 74 || status == SVGParseStatus::ZeroValue |
75 || status == SVGParseStatus::ParsingFailed; | 75 || status == SVGParseStatus::ParsingFailed; |
76 } | 76 } |
77 | 77 |
78 void appendValue(StringBuilder& builder, SVGParsingError error, const AtomicStri
ng& value) | 78 void appendValue(StringBuilder& builder, SVGParsingError error, const AtomicStri
ng& value) |
79 { | 79 { |
80 builder.append('"'); | 80 builder.append('"'); |
81 if (!error.hasLocus() || disableLocus(error.status())) { | 81 if (!error.hasLocus() || disableLocus(error.status())) { |
82 escapeStringForJSON(value.string(), &builder); | 82 escapeStringForJSON(value.getString(), &builder); |
83 } else { | 83 } else { |
84 // Emit a string on the form: '"[...]<before><after>[...]"' | 84 // Emit a string on the form: '"[...]<before><after>[...]"' |
85 unsigned locus = error.locus(); | 85 unsigned locus = error.locus(); |
86 ASSERT(locus <= value.length()); | 86 ASSERT(locus <= value.length()); |
87 | 87 |
88 // Amount of context to show before/after the error. | 88 // Amount of context to show before/after the error. |
89 const unsigned kContext = 16; | 89 const unsigned kContext = 16; |
90 | 90 |
91 unsigned contextStart = std::max(locus, kContext) - kContext; | 91 unsigned contextStart = std::max(locus, kContext) - kContext; |
92 unsigned contextEnd = std::min(locus + kContext, value.length()); | 92 unsigned contextEnd = std::min(locus + kContext, value.length()); |
93 ASSERT(contextStart <= contextEnd); | 93 ASSERT(contextStart <= contextEnd); |
94 ASSERT(contextEnd <= value.length()); | 94 ASSERT(contextEnd <= value.length()); |
95 if (contextStart != 0) | 95 if (contextStart != 0) |
96 builder.append(horizontalEllipsisCharacter); | 96 builder.append(horizontalEllipsisCharacter); |
97 escapeStringForJSON(value.string().substring(contextStart, contextEnd -
contextStart), &builder); | 97 escapeStringForJSON(value.getString().substring(contextStart, contextEnd
- contextStart), &builder); |
98 if (contextEnd != value.length()) | 98 if (contextEnd != value.length()) |
99 builder.append(horizontalEllipsisCharacter); | 99 builder.append(horizontalEllipsisCharacter); |
100 } | 100 } |
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.appendLiteral(": "); |
112 | 112 |
113 if (hasLocus() && locus() == value.length()) | 113 if (hasLocus() && locus() == value.length()) |
114 builder.appendLiteral("Unexpected end of attribute. "); | 114 builder.appendLiteral("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 |