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

Unified Diff: third_party/WebKit/Source/core/svg/SVGViewSpec.cpp

Issue 2421863002: Clean up SVGViewSpec::parseViewSpecInternal (Closed)
Patch Set: Created 4 years, 2 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/core/svg/SVGViewSpec.cpp
diff --git a/third_party/WebKit/Source/core/svg/SVGViewSpec.cpp b/third_party/WebKit/Source/core/svg/SVGViewSpec.cpp
index 5eb05c1b79d14d161d6f93af5537b16af9c1c121..69953a0b539fc0da73b4cfad1e5a0f62b2ea0454 100644
--- a/third_party/WebKit/Source/core/svg/SVGViewSpec.cpp
+++ b/third_party/WebKit/Source/core/svg/SVGViewSpec.cpp
@@ -132,22 +132,65 @@ void SVGViewSpec::setZoomAndPan(unsigned short,
ExceptionMessages::readOnly());
}
+namespace {
+
+enum ViewSpecFunctionType {
+ Unknown,
+ PreserveAspectRatio,
+ Transform,
+ ViewBox,
+ ViewTarget,
+ ZoomAndPan,
+};
+
+template <typename CharType>
+static ViewSpecFunctionType scanViewSpecFunction(const CharType*& ptr,
+ const CharType* end) {
+ DCHECK_LT(ptr, end);
+ switch (*ptr) {
+ case 'v':
+ if (skipToken(ptr, end, "viewBox"))
+ return ViewBox;
+ if (skipToken(ptr, end, "viewTarget"))
+ return ViewTarget;
+ break;
+ case 'z':
+ if (skipToken(ptr, end, "zoomAndPan"))
+ return ZoomAndPan;
+ break;
+ case 'p':
+ if (skipToken(ptr, end, "preserveAspectRatio"))
+ return PreserveAspectRatio;
+ break;
+ case 't':
+ if (skipToken(ptr, end, "transform"))
+ return Transform;
+ break;
+ }
+ return Unknown;
+}
+
+} // namespace
+
template <typename CharType>
bool SVGViewSpec::parseViewSpecInternal(const CharType* ptr,
const CharType* end) {
if (!skipToken(ptr, end, "svgView"))
return false;
- if (ptr >= end || *ptr != '(')
+ if (!skipExactly<CharType>(ptr, end, '('))
return false;
- ptr++;
while (ptr < end && *ptr != ')') {
- if (*ptr == 'v') {
- if (skipToken(ptr, end, "viewBox")) {
- if (ptr >= end || *ptr != '(')
- return false;
- ptr++;
+ ViewSpecFunctionType functionType = scanViewSpecFunction(ptr, end);
+ if (functionType == Unknown)
+ return false;
+
+ if (!skipExactly<CharType>(ptr, end, '('))
+ return false;
+
+ switch (functionType) {
+ case ViewBox: {
float x = 0.0f;
float y = 0.0f;
float width = 0.0f;
@@ -157,64 +200,38 @@ bool SVGViewSpec::parseViewSpecInternal(const CharType* ptr,
parseNumber(ptr, end, height, DisallowWhitespace)))
return false;
updateViewBox(FloatRect(x, y, width, height));
- if (ptr >= end || *ptr != ')')
+ break;
+ }
+ case ViewTarget: {
+ const CharType* viewTargetStart = ptr;
+ skipUntil<CharType>(ptr, end, ')');
+ if (ptr == viewTargetStart)
return false;
- ptr++;
- } else if (skipToken(ptr, end, "viewTarget")) {
- if (ptr >= end || *ptr != '(')
+ m_viewTargetString = String(viewTargetStart, ptr - viewTargetStart);
+ break;
+ }
+ case ZoomAndPan:
+ if (!parseZoomAndPan(ptr, end))
return false;
- const CharType* viewTargetStart = ++ptr;
- while (ptr < end && *ptr != ')')
- ptr++;
- if (ptr >= end)
+ break;
+ case PreserveAspectRatio:
+ if (!preserveAspectRatio()->baseValue()->parse(ptr, end, false))
return false;
- m_viewTargetString = String(viewTargetStart, ptr - viewTargetStart);
- ptr++;
- } else
- return false;
- } else if (*ptr == 'z') {
- if (!skipToken(ptr, end, "zoomAndPan"))
- return false;
- if (ptr >= end || *ptr != '(')
- return false;
- ptr++;
- if (!parseZoomAndPan(ptr, end))
- return false;
- if (ptr >= end || *ptr != ')')
- return false;
- ptr++;
- } else if (*ptr == 'p') {
- if (!skipToken(ptr, end, "preserveAspectRatio"))
- return false;
- if (ptr >= end || *ptr != '(')
- return false;
- ptr++;
- if (!preserveAspectRatio()->baseValue()->parse(ptr, end, false))
- return false;
- if (ptr >= end || *ptr != ')')
- return false;
- ptr++;
- } else if (*ptr == 't') {
- if (!skipToken(ptr, end, "transform"))
- return false;
- if (ptr >= end || *ptr != '(')
- return false;
- ptr++;
- m_transform->baseValue()->parse(ptr, end);
- if (ptr >= end || *ptr != ')')
- return false;
- ptr++;
- } else
+ break;
+ case Transform:
+ m_transform->baseValue()->parse(ptr, end);
+ break;
+ default:
+ NOTREACHED();
+ break;
+ }
+
+ if (!skipExactly<CharType>(ptr, end, ')'))
return false;
- if (ptr < end && *ptr == ';')
- ptr++;
+ skipExactly<CharType>(ptr, end, ';');
}
-
- if (ptr >= end || *ptr != ')')
- return false;
-
- return true;
+ return skipExactly<CharType>(ptr, end, ')');
}
} // namespace blink
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698