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

Unified Diff: third_party/WebKit/Source/core/svg/SVGParsingError.h

Issue 1588993005: Extended error reporting for SVG attribute parsing (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add PLATFORM_EXPORT 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 side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/core/svg/SVGParsingError.h
diff --git a/third_party/WebKit/Source/core/svg/SVGParsingError.h b/third_party/WebKit/Source/core/svg/SVGParsingError.h
index 5a40f9f4c101fe0bb403d1eaf80b9d6030b319c8..a5531319306ead64bc2d86f2a1cb12af6a673bd9 100644
--- a/third_party/WebKit/Source/core/svg/SVGParsingError.h
+++ b/third_party/WebKit/Source/core/svg/SVGParsingError.h
@@ -27,14 +27,71 @@
#ifndef SVGParsingError_h
#define SVGParsingError_h
+#include "wtf/MathExtras.h"
+#include "wtf/text/WTFString.h"
+
namespace blink {
-enum SVGParsingError {
+class QualifiedName;
+
+enum class SVGParseStatus {
NoError,
- ParsingAttributeFailedError,
- NegativeValueForbiddenError
+
+ // Syntax errors
+ TrailingGarbage,
+ ExpectedBoolean,
+ ExpectedEnumeration,
+
+ // Semantic errors
+ NegativeValue,
+
+ // Generic error
+ ParsingFailed,
+};
+
+class SVGParsingError {
+ STACK_ALLOCATED();
+public:
+ SVGParsingError(SVGParseStatus status = SVGParseStatus::NoError, size_t locus = 0)
+ : m_status(static_cast<unsigned>(status))
+ , m_locus(checkLocus(locus))
+ {
+ ASSERT(this->status() == status);
+ }
+
+ SVGParseStatus status() const { return static_cast<SVGParseStatus>(m_status); }
+
+ bool hasLocus() const { return m_locus != kNoLocus; }
+ unsigned locus() const { return m_locus; }
+
+ // Generates a string describing this error for |value| in the context of
+ // an <element, attribute>-name pair.
+ String format(const String& tagName, const QualifiedName&, const AtomicString& value) const;
+
+private:
+ static const int kLocusBits = 24;
+ static const unsigned kNoLocus = (1u << kLocusBits) - 1;
+
+ static unsigned checkLocus(size_t locus)
+ {
+ // Clamp to fit in the number of bits available. If the character index
+ // encoded by the locus does not fit in the number of bits allocated
+ // for it, the locus will be disabled (set to kNoLocus). This means
+ // that very long values will be output in their entirety. That should
+ // however be rather uncommon.
+ return clampTo<unsigned>(locus, 0, kNoLocus);
+ }
+
+ unsigned m_status : 8;
+ unsigned m_locus : kLocusBits; // The locus (character index) of the error within the parsed string.
};
+inline bool operator==(const SVGParsingError& error, SVGParseStatus status)
+{
+ return error.status() == status;
+}
+inline bool operator!=(const SVGParsingError& error, SVGParseStatus status) { return !(error == status); }
+
} // namespace blink
#endif // SVGParsingError_h
« no previous file with comments | « third_party/WebKit/Source/core/svg/SVGNumberOptionalNumber.cpp ('k') | third_party/WebKit/Source/core/svg/SVGParsingError.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698