Index: experimental/svg/model/SkSVGDOM.cpp |
diff --git a/experimental/svg/model/SkSVGDOM.cpp b/experimental/svg/model/SkSVGDOM.cpp |
index 9b67484fbc571ce5a6619c4ac64cb50a20cb742b..c4fdcb172b3f1add0766b5cdf14fa562105222d0 100644 |
--- a/experimental/svg/model/SkSVGDOM.cpp |
+++ b/experimental/svg/model/SkSVGDOM.cpp |
@@ -82,6 +82,18 @@ bool SetViewBoxAttribute(const sk_sp<SkSVGNode>& node, SkSVGAttribute attr, |
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. |
class StyleIterator { |
public: |
@@ -96,8 +108,8 @@ public: |
const char* valueSep = strchr(fPos, ':'); |
if (valueSep && valueSep < sep) { |
- name.set(fPos, valueSep - fPos); |
- value.set(valueSep + 1, sep - valueSep - 1); |
+ name = TrimmedString(fPos, valueSep - 1); |
+ value = TrimmedString(valueSep + 1, sep - 1); |
} |
fPos = *sep ? sep + 1 : nullptr; |