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

Unified Diff: src/pdf/SkPDFTypes.cpp

Issue 1152283014: SkPDF: fix name escape code (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: 2015-06-08 (Monday) 11:53:55 EDT Created 5 years, 6 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 | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/pdf/SkPDFTypes.cpp
diff --git a/src/pdf/SkPDFTypes.cpp b/src/pdf/SkPDFTypes.cpp
index 2b2921d3fd6b6df144de4464c6dc689ed3b89c4f..2041aad7e761b5a15565f9637676d59a92296044 100644
--- a/src/pdf/SkPDFTypes.cpp
+++ b/src/pdf/SkPDFTypes.cpp
@@ -99,35 +99,22 @@ bool is_valid_name(const char* n) {
}
#endif // SK_DEBUG
-// Given an arbitrary string, convert it to a valid name.
-static SkString escape_name(const char* name, size_t len) {
+// Given an arbitrary string, write it as a valid name (not includeing
bungeman-skia 2015/06/08 17:18:23 s/includeing/including
hal.canary 2015/06/08 17:48:33 Done.
+// leading slash).
+static void write_name_escaped(SkWStream* o, const char* name) {
static const char kToEscape[] = "#/%()<>[]{}";
- int count = 0;
- const char* const end = &name[len];
- for (const char* n = name; n != end; ++n) {
- if (*n < '!' || *n > '~' || strchr(kToEscape, *n)) {
- count += 2;
- }
- ++count;
- }
- SkString result(count);
- char* s = result.writable_str();
static const char kHex[] = "0123456789ABCDEF";
- for (const char* n = name; n != end; ++n) {
+ for (const uint8_t* n = reinterpret_cast<const uint8_t*>(name);
+ *n; ++n) {
bungeman-skia 2015/06/08 17:18:23 We have 100 chars, this should go on the previous
hal.canary 2015/06/08 17:48:33 Done.
if (*n < '!' || *n > '~' || strchr(kToEscape, *n)) {
- *s++ = '#';
- *s++ = kHex[(*n >> 4) & 0xF];
- *s++ = kHex[*n & 0xF];
+ char buffer[3] = {'#', '\0', '\0'};
+ buffer[1] = kHex[(*n >> 4) & 0xF];
+ buffer[2] = kHex[*n & 0xF];
+ o->write(buffer, sizeof(buffer));
} else {
- *s++ = *n;
+ o->write(n, 1);
}
}
- SkASSERT(&result.writable_str()[count] == s); // don't over-write
- return result; // allocated space
-}
-
-static SkString escape_name(const SkString& name) {
- return escape_name(name.c_str(), name.size());
}
static void write_string(SkWStream* o, const SkString& s) {
@@ -166,7 +153,7 @@ void SkPDFUnion::emitObject(SkWStream* stream,
return;
case Type::kNameSkS:
stream->writeText("/");
- write_string(stream, escape_name(*pun(fSkString)));
+ write_name_escaped(stream, pun(fSkString)->c_str());
return;
case Type::kStringSkS:
write_string(stream, format_string(*pun(fSkString)));
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698