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

Unified 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: Clarify, address comments. 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « resources/android_fonts/v22/fonts.xml ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/ports/SkFontConfigParser_android.cpp
diff --git a/src/ports/SkFontConfigParser_android.cpp b/src/ports/SkFontConfigParser_android.cpp
index e60f4e4ea307a3e74e58495c4ca6f80be0f2b668..3f0ebbfc6b8f3f2e1547db559d26b778d15d4524 100644
--- a/src/ports/SkFontConfigParser_android.cpp
+++ b/src/ports/SkFontConfigParser_android.cpp
@@ -263,6 +263,25 @@ static void XMLCALL start_element_handler(void* data, const char* tag, const cha
}
}
+static bool is_whitespace(char c) {
+ return c == ' ' || c == '\n'|| c == '\r' || c == '\t';
+}
+
+static void trim_string(SkString* s) {
+ char* str = s->writable_str();
+ const char* start = str; // start is inclusive
+ const char* end = start + s->size(); // end is exclusive
+ while (is_whitespace(*start)) { ++start; }
+ if (start != end) {
+ --end; // make end inclusive
+ while (is_whitespace(*end)) { --end; }
+ ++end; // make end exclusive
+ }
+ size_t len = end - start;
+ memmove(str, start, len);
+ s->resize(len);
+}
+
static void XMLCALL end_element_handler(void* data, const char* tag) {
FamilyData* self = static_cast<FamilyData*>(data);
size_t len = strlen(tag);
@@ -270,6 +289,7 @@ static void XMLCALL end_element_handler(void* data, const char* tag) {
*self->fFamilies.append() = self->fCurrentFamily.detach();
} else if (MEMEQ("font", tag, len)) {
XML_SetCharacterDataHandler(self->fParser, NULL);
+ trim_string(&self->fCurrentFontInfo->fFileName);
}
}
« 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