// static
SkString SkPDFName::FormatName(const SkString& input) {
SkASSERT(input.size() <= kMaxLen);
+ // TODO(vandebo) If more escaping is needed, improve the linear scan.
+ static const char escaped[] = "#/%()<>[]{}";
SkString result("/");
for (size_t i = 0; i < input.size(); i++) {
- if (input[i] & 0x80 || input[i] < '!' || input[i] == '#') {
+ if (input[i] & 0x80 || input[i] < '!' || strchr(escaped, input[i])) {
result.append("#");
// Mask with 0xFF to avoid sign extension. i.e. #FFFFFF81
result.appendHex(input[i] & 0xFF, 2);
CheckObjectOutput(reporter, name.get(), expectedResult,
strlen(expectedResult), false, false);
+ SkRefPtr<SkPDFName> escapedName = new SkPDFName("A#/%()<>[]{}B");
+ escapedName->unref(); // SkRefPtr and new both took a reference.
+ const char escapedNameExpected[] = "/A#23#2F#25#28#29#3C#3E#5B#5D#7B#7DB";
+ CheckObjectOutput(reporter, escapedName.get(), escapedNameExpected,
+ strlen(escapedNameExpected), false, false);
+
// Test that we correctly handle characters with the high-bit set.
const unsigned char highBitCString[] = {0xDE, 0xAD, 'b', 'e', 0xEF, 0};
SkRefPtr<SkPDFName> highBitName = new SkPDFName((const char*)highBitCString);