OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright 2016 Google Inc. | 2 * Copyright 2016 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "SkCanvas.h" | 8 #include "SkCanvas.h" |
9 #include "SkDOM.h" | 9 #include "SkDOM.h" |
10 #include "SkParse.h" | 10 #include "SkParse.h" |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
119 | 119 |
120 std::tuple<SkString, SkString> next() { | 120 std::tuple<SkString, SkString> next() { |
121 SkString name, value; | 121 SkString name, value; |
122 | 122 |
123 if (fPos) { | 123 if (fPos) { |
124 const char* sep = this->nextSeparator(); | 124 const char* sep = this->nextSeparator(); |
125 SkASSERT(*sep == ';' || *sep == '\0'); | 125 SkASSERT(*sep == ';' || *sep == '\0'); |
126 | 126 |
127 const char* valueSep = strchr(fPos, ':'); | 127 const char* valueSep = strchr(fPos, ':'); |
128 if (valueSep && valueSep < sep) { | 128 if (valueSep && valueSep < sep) { |
129 name.set(fPos, valueSep - fPos); | 129 name = TrimmedString(fPos, valueSep - 1); |
130 value.set(valueSep + 1, sep - valueSep - 1); | 130 value = TrimmedString(valueSep + 1, sep - 1); |
131 } | 131 } |
132 | 132 |
133 fPos = *sep ? sep + 1 : nullptr; | 133 fPos = *sep ? sep + 1 : nullptr; |
134 } | 134 } |
135 | 135 |
136 return std::make_tuple(name, value); | 136 return std::make_tuple(name, value); |
137 } | 137 } |
138 | 138 |
139 private: | 139 private: |
140 const char* nextSeparator() const { | 140 const char* nextSeparator() const { |
141 const char* sep = fPos; | 141 const char* sep = fPos; |
142 while (*sep != ';' && *sep != '\0') { | 142 while (*sep != ';' && *sep != '\0') { |
143 sep++; | 143 sep++; |
144 } | 144 } |
145 return sep; | 145 return sep; |
146 } | 146 } |
147 | 147 |
robertphillips
2016/08/08 12:39:30
Does this need to be class-scoped? It seems like t
f(malita)
2016/08/08 13:00:02
Done/moved out of the class.
| |
148 static SkString TrimmedString(const char* first, const char* last) { | |
149 SkASSERT(first); | |
150 SkASSERT(last); | |
151 SkASSERT(first <= last); | |
152 | |
153 while (first <= last && *first <= ' ') { first++; } | |
154 while (first <= last && *last <= ' ') { last--; } | |
155 | |
156 SkASSERT(last - first + 1 >= 0); | |
157 return SkString(first, SkTo<size_t>(last - first + 1)); | |
158 } | |
159 | |
148 const char* fPos; | 160 const char* fPos; |
149 }; | 161 }; |
150 | 162 |
151 void set_string_attribute(const sk_sp<SkSVGNode>& node, const char* name, const char* value); | 163 void set_string_attribute(const sk_sp<SkSVGNode>& node, const char* name, const char* value); |
152 | 164 |
153 bool SetStyleAttributes(const sk_sp<SkSVGNode>& node, SkSVGAttribute, | 165 bool SetStyleAttributes(const sk_sp<SkSVGNode>& node, SkSVGAttribute, |
154 const char* stringValue) { | 166 const char* stringValue) { |
155 | 167 |
156 SkString name, value; | 168 SkString name, value; |
157 StyleIterator iter(stringValue); | 169 StyleIterator iter(stringValue); |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
294 if (fRoot) { | 306 if (fRoot) { |
295 SkSVGRenderContext ctx(fContainerSize); | 307 SkSVGRenderContext ctx(fContainerSize); |
296 fRoot->render(canvas, ctx); | 308 fRoot->render(canvas, ctx); |
297 } | 309 } |
298 } | 310 } |
299 | 311 |
300 void SkSVGDOM::setContainerSize(const SkSize& containerSize) { | 312 void SkSVGDOM::setContainerSize(const SkSize& containerSize) { |
301 // TODO: inval | 313 // TODO: inval |
302 fContainerSize = containerSize; | 314 fContainerSize = containerSize; |
303 } | 315 } |
OLD | NEW |