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

Side by Side Diff: src/ports/SkFontConfigParser_android.cpp

Issue 1125413003: Trim whitespace from parsed filename in Android v21. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Avoid possible use after free. Created 5 years, 7 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 unified diff | Download patch
« no previous file with comments | « resources/android_fonts/v22/fonts.xml ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2011 The Android Open Source Project 2 * Copyright 2011 The Android Open Source Project
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 "SkFontConfigParser_android.h" 8 #include "SkFontConfigParser_android.h"
9 #include "SkFontMgr_android.h" 9 #include "SkFontMgr_android.h"
10 #include "SkStream.h" 10 #include "SkStream.h"
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after
256 size_t len = strlen(tag); 256 size_t len = strlen(tag);
257 if (MEMEQ("family", tag, len)) { 257 if (MEMEQ("family", tag, len)) {
258 family_element_handler(self, attributes); 258 family_element_handler(self, attributes);
259 } else if (MEMEQ("font", tag, len)) { 259 } else if (MEMEQ("font", tag, len)) {
260 font_element_handler(self, attributes); 260 font_element_handler(self, attributes);
261 } else if (MEMEQ("alias", tag, len)) { 261 } else if (MEMEQ("alias", tag, len)) {
262 alias_element_handler(self, attributes); 262 alias_element_handler(self, attributes);
263 } 263 }
264 } 264 }
265 265
266 static void trim_string(SkString* s) {
267 char* str = s->writable_str();
268 const char* start = str;
269 const char* end = start + s->size();
270 for (; *start == ' ' || *start == '\n'|| *start == '\r' || *start == '\t'; + +start) { }
djsollen 2015/05/08 13:56:13 while I can appreciate the compactness of this it
bungeman-skia 2015/05/08 15:05:04 Done.
271 if (start != end) {
272 for (--end; *end == ' ' || *end == '\n'|| *end == '\r' || *end == '\t'; --end) { }
djsollen 2015/05/08 13:56:13 comment why you need the --end at the begin and en
bungeman-skia 2015/05/08 15:05:04 Done.
273 ++end;
274 }
275 memmove(str, start, end - start);
276 s->resize(end - start);
277 }
278
266 static void XMLCALL end_element_handler(void* data, const char* tag) { 279 static void XMLCALL end_element_handler(void* data, const char* tag) {
267 FamilyData* self = static_cast<FamilyData*>(data); 280 FamilyData* self = static_cast<FamilyData*>(data);
268 size_t len = strlen(tag); 281 size_t len = strlen(tag);
269 if (MEMEQ("family", tag, len)) { 282 if (MEMEQ("family", tag, len)) {
270 *self->fFamilies.append() = self->fCurrentFamily.detach(); 283 *self->fFamilies.append() = self->fCurrentFamily.detach();
271 } else if (MEMEQ("font", tag, len)) { 284 } else if (MEMEQ("font", tag, len)) {
272 XML_SetCharacterDataHandler(self->fParser, NULL); 285 XML_SetCharacterDataHandler(self->fParser, NULL);
286 trim_string(&self->fCurrentFontInfo->fFileName);
273 } 287 }
274 } 288 }
275 289
276 } // lmpParser 290 } // lmpParser
277 291
278 namespace jbParser { 292 namespace jbParser {
279 293
280 /** 294 /**
281 * Handler for arbitrary text. This is used to parse the text inside each name 295 * Handler for arbitrary text. This is used to parse the text inside each name
282 * or file tag. The resulting strings are put into the fNames or FontFileInfo ar rays. 296 * or file tag. The resulting strings are put into the fNames or FontFileInfo ar rays.
(...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after
650 const char* tag = fTag.c_str(); 664 const char* tag = fTag.c_str();
651 665
652 // strip off the rightmost "-.*" 666 // strip off the rightmost "-.*"
653 const char* parentTagEnd = strrchr(tag, '-'); 667 const char* parentTagEnd = strrchr(tag, '-');
654 if (parentTagEnd == NULL) { 668 if (parentTagEnd == NULL) {
655 return SkLanguage(); 669 return SkLanguage();
656 } 670 }
657 size_t parentTagLen = parentTagEnd - tag; 671 size_t parentTagLen = parentTagEnd - tag;
658 return SkLanguage(tag, parentTagLen); 672 return SkLanguage(tag, parentTagLen);
659 } 673 }
OLDNEW
« no previous file with comments | « resources/android_fonts/v22/fonts.xml ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698