| 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/json/JSONValues.h" | 8 #include "platform/json/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 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 | 76 |
| 77 void appendValue(StringBuilder& builder, | 77 void appendValue(StringBuilder& builder, |
| 78 SVGParsingError error, | 78 SVGParsingError error, |
| 79 const AtomicString& value) { | 79 const AtomicString& value) { |
| 80 builder.append('"'); | 80 builder.append('"'); |
| 81 if (!error.hasLocus() || disableLocus(error.status())) { | 81 if (!error.hasLocus() || disableLocus(error.status())) { |
| 82 escapeStringForJSON(value.getString(), &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 DCHECK_LE(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 DCHECK_LE(contextStart, contextEnd); |
| 94 ASSERT(contextEnd <= value.length()); | 94 DCHECK_LE(contextEnd, value.length()); |
| 95 if (contextStart != 0) | 95 if (contextStart != 0) |
| 96 builder.append(horizontalEllipsisCharacter); | 96 builder.append(horizontalEllipsisCharacter); |
| 97 escapeStringForJSON( | 97 escapeStringForJSON( |
| 98 value.getString().substring(contextStart, contextEnd - contextStart), | 98 value.getString().substring(contextStart, contextEnd - contextStart), |
| 99 &builder); | 99 &builder); |
| 100 if (contextEnd != value.length()) | 100 if (contextEnd != value.length()) |
| 101 builder.append(horizontalEllipsisCharacter); | 101 builder.append(horizontalEllipsisCharacter); |
| 102 } | 102 } |
| 103 builder.append('"'); | 103 builder.append('"'); |
| 104 } | 104 } |
| (...skipping 12 matching lines...) Expand all Loading... |
| 117 builder.append("Unexpected end of attribute. "); | 117 builder.append("Unexpected end of attribute. "); |
| 118 | 118 |
| 119 auto message = messageForStatus(status()); | 119 auto message = messageForStatus(status()); |
| 120 builder.append(message.first); | 120 builder.append(message.first); |
| 121 appendValue(builder, *this, value); | 121 appendValue(builder, *this, value); |
| 122 builder.append(message.second); | 122 builder.append(message.second); |
| 123 return builder.toString(); | 123 return builder.toString(); |
| 124 } | 124 } |
| 125 | 125 |
| 126 } // namespace blink | 126 } // namespace blink |
| OLD | NEW |