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

Unified Diff: Source/core/svg/SVGParserUtilities.cpp

Issue 302643004: [SVG2] Allow leading and trailing whitespace in svg attributes (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@relax_todouble_wtf
Patch Set: split tests to combat slow xp trybots Created 6 years, 6 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 | « Source/core/svg/SVGParserUtilities.h ('k') | Source/core/svg/SVGPoint.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/svg/SVGParserUtilities.cpp
diff --git a/Source/core/svg/SVGParserUtilities.cpp b/Source/core/svg/SVGParserUtilities.cpp
index 8d39b657feb3f82757a49796ac139d38cd394a18..897c9e60ec0ed7555c4d7fbd82ad96c8181aa992 100644
--- a/Source/core/svg/SVGParserUtilities.cpp
+++ b/Source/core/svg/SVGParserUtilities.cpp
@@ -43,7 +43,7 @@ static inline bool isValidRange(const FloatType& x)
// at a higher precision internally, without any unnecessary runtime cost or code
// complexity.
template <typename CharType, typename FloatType>
-static bool genericParseNumber(const CharType*& ptr, const CharType* end, FloatType& number, bool skip)
+static bool genericParseNumber(const CharType*& ptr, const CharType* end, FloatType& number, WhitespaceMode mode)
{
FloatType integer, decimal, frac, exponent;
int sign, expsign;
@@ -56,6 +56,9 @@ static bool genericParseNumber(const CharType*& ptr, const CharType* end, FloatT
sign = 1;
expsign = 1;
+ if (mode & AllowLeadingWhitespace)
+ skipOptionalSVGSpaces(ptr, end);
+
// read the sign
if (ptr < end && *ptr == '+')
ptr++;
@@ -136,7 +139,7 @@ static bool genericParseNumber(const CharType*& ptr, const CharType* end, FloatT
if (start == ptr)
return false;
- if (skip)
+ if (mode & AllowTrailingWhitespace)
skipOptionalSVGSpacesOrDelimiter(ptr, end);
return true;
@@ -147,21 +150,21 @@ bool parseSVGNumber(CharType* begin, size_t length, double& number)
{
const CharType* ptr = begin;
const CharType* end = ptr + length;
- return genericParseNumber(ptr, end, number, false);
+ return genericParseNumber(ptr, end, number, AllowLeadingAndTrailingWhitespace);
}
// Explicitly instantiate the two flavors of parseSVGNumber() to satisfy external callers
template bool parseSVGNumber(LChar* begin, size_t length, double&);
template bool parseSVGNumber(UChar* begin, size_t length, double&);
-bool parseNumber(const LChar*& ptr, const LChar* end, float& number, bool skip)
+bool parseNumber(const LChar*& ptr, const LChar* end, float& number, WhitespaceMode mode)
{
- return genericParseNumber(ptr, end, number, skip);
+ return genericParseNumber(ptr, end, number, mode);
}
-bool parseNumber(const UChar*& ptr, const UChar* end, float& number, bool skip)
+bool parseNumber(const UChar*& ptr, const UChar* end, float& number, WhitespaceMode mode)
{
- return genericParseNumber(ptr, end, number, skip);
+ return genericParseNumber(ptr, end, number, mode);
}
// only used to parse largeArcFlag and sweepFlag which must be a "0" or "1"
@@ -202,7 +205,7 @@ static bool genericParseNumberOptionalNumber(const CharType*& ptr, const CharTyp
if (ptr == end)
y = x;
- else if (!parseNumber(ptr, end, y, false))
+ else if (!parseNumber(ptr, end, y, AllowLeadingAndTrailingWhitespace))
return false;
return ptr == end;
@@ -212,6 +215,7 @@ bool parseNumberOptionalNumber(const String& string, float& x, float& y)
{
if (string.isEmpty())
return false;
+
if (string.is8Bit()) {
const LChar* ptr = string.characters8();
const LChar* end = ptr + string.length();
@@ -223,6 +227,43 @@ bool parseNumberOptionalNumber(const String& string, float& x, float& y)
}
template<typename CharType>
+bool genericParseNumberOrPercentage(const CharType*& ptr, const CharType* end, float& number)
+{
+ if (genericParseNumber(ptr, end, number, AllowLeadingWhitespace)) {
+ if (ptr == end)
+ return true;
+
+ bool isPercentage = (*ptr == '%');
+ if (isPercentage)
+ ptr++;
+
+ skipOptionalSVGSpaces(ptr, end);
+
+ if (isPercentage)
+ number /= 100.f;
+
+ return ptr == end;
+ }
+
+ return false;
+}
+
+bool parseNumberOrPercentage(const String& string, float& number)
+{
+ if (string.isEmpty())
+ return false;
+
+ if (string.is8Bit()) {
+ const LChar* ptr = string.characters8();
+ const LChar* end = ptr + string.length();
+ return genericParseNumberOrPercentage(ptr, end, number);
+ }
+ const UChar* ptr = string.characters16();
+ const UChar* end = ptr + string.length();
+ return genericParseNumberOrPercentage(ptr, end, number);
+}
+
+template<typename CharType>
static bool parseGlyphName(const CharType*& ptr, const CharType* end, HashSet<String>& values)
{
skipOptionalSVGSpaces(ptr, end);
@@ -238,7 +279,7 @@ static bool parseGlyphName(const CharType*& ptr, const CharType* end, HashSet<St
// walk backwards from the ; to ignore any whitespace
const CharType* inputEnd = ptr - 1;
- while (inputStart < inputEnd && isSVGSpace(*inputEnd))
+ while (inputStart < inputEnd && isHTMLSpace<CharType>(*inputEnd))
--inputEnd;
values.add(String(inputStart, inputEnd - inputStart + 1));
@@ -390,7 +431,7 @@ static Vector<String> genericParseDelimitedString(const CharType*& ptr, const Ch
// walk backwards from the ; to ignore any whitespace
const CharType* inputEnd = ptr - 1;
- while (inputStart < inputEnd && isSVGSpace(*inputEnd))
+ while (inputStart < inputEnd && isHTMLSpace<CharType>(*inputEnd))
inputEnd--;
values.append(String(inputStart, inputEnd - inputStart + 1));
« no previous file with comments | « Source/core/svg/SVGParserUtilities.h ('k') | Source/core/svg/SVGPoint.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698