[SVGDom] Improve whitespace handling in style parsing
Handle whitespace-padded style names/values. R=stephana@google.com,robertphillips@google.com GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2225623002 Review-Url: https://codereview.chromium.org/2225623002
This commit is contained in:
parent
0adbd3e0a6
commit
61f36b3708
@ -152,13 +152,20 @@ bool SkSVGAttributeParser::parseHexColorToken(SkColor* c) {
|
|||||||
bool SkSVGAttributeParser::parseColor(SkSVGColorType* color) {
|
bool SkSVGAttributeParser::parseColor(SkSVGColorType* color) {
|
||||||
SkColor c;
|
SkColor c;
|
||||||
|
|
||||||
|
// consume preceding whitespace
|
||||||
|
this->parseWSToken();
|
||||||
|
|
||||||
// TODO: rgb(...)
|
// TODO: rgb(...)
|
||||||
|
bool parsedValue = false;
|
||||||
if (this->parseHexColorToken(&c) || this->parseNamedColorToken(&c)) {
|
if (this->parseHexColorToken(&c) || this->parseNamedColorToken(&c)) {
|
||||||
*color = SkSVGColorType(c);
|
*color = SkSVGColorType(c);
|
||||||
return true;
|
parsedValue = true;
|
||||||
|
|
||||||
|
// consume trailing whitespace
|
||||||
|
this->parseWSToken();
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return parsedValue && this->parseEOSToken();
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://www.w3.org/TR/SVG/types.html#DataTypeNumber
|
// https://www.w3.org/TR/SVG/types.html#DataTypeNumber
|
||||||
|
@ -82,6 +82,18 @@ bool SetViewBoxAttribute(const sk_sp<SkSVGNode>& node, SkSVGAttribute attr,
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SkString TrimmedString(const char* first, const char* last) {
|
||||||
|
SkASSERT(first);
|
||||||
|
SkASSERT(last);
|
||||||
|
SkASSERT(first <= last);
|
||||||
|
|
||||||
|
while (first <= last && *first <= ' ') { first++; }
|
||||||
|
while (first <= last && *last <= ' ') { last--; }
|
||||||
|
|
||||||
|
SkASSERT(last - first + 1 >= 0);
|
||||||
|
return SkString(first, SkTo<size_t>(last - first + 1));
|
||||||
|
}
|
||||||
|
|
||||||
// Breaks a "foo: bar; baz: ..." string into key:value pairs.
|
// Breaks a "foo: bar; baz: ..." string into key:value pairs.
|
||||||
class StyleIterator {
|
class StyleIterator {
|
||||||
public:
|
public:
|
||||||
@ -96,8 +108,8 @@ public:
|
|||||||
|
|
||||||
const char* valueSep = strchr(fPos, ':');
|
const char* valueSep = strchr(fPos, ':');
|
||||||
if (valueSep && valueSep < sep) {
|
if (valueSep && valueSep < sep) {
|
||||||
name.set(fPos, valueSep - fPos);
|
name = TrimmedString(fPos, valueSep - 1);
|
||||||
value.set(valueSep + 1, sep - valueSep - 1);
|
value = TrimmedString(valueSep + 1, sep - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
fPos = *sep ? sep + 1 : nullptr;
|
fPos = *sep ? sep + 1 : nullptr;
|
||||||
|
Loading…
Reference in New Issue
Block a user