OLD | NEW |
---|---|
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2011 Google Inc. | 3 * Copyright 2011 Google Inc. |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 | 8 |
9 #include "SkPDFTypes.h" | 9 #include "SkPDFTypes.h" |
10 #include "SkPDFUtils.h" | 10 #include "SkPDFUtils.h" |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
98 return true; | 98 return true; |
99 } | 99 } |
100 #endif // SK_DEBUG | 100 #endif // SK_DEBUG |
101 | 101 |
102 // Given an arbitrary string, convert it to a valid name. | 102 // Given an arbitrary string, convert it to a valid name. |
103 static SkString escape_name(const char* name, size_t len) { | 103 static SkString escape_name(const char* name, size_t len) { |
104 static const char kToEscape[] = "#/%()<>[]{}"; | 104 static const char kToEscape[] = "#/%()<>[]{}"; |
105 int count = 0; | 105 int count = 0; |
106 const char* const end = &name[len]; | 106 const char* const end = &name[len]; |
107 for (const char* n = name; n != end; ++n) { | 107 for (const char* n = name; n != end; ++n) { |
108 if ('\0' == *n) { | |
bungeman-skia
2015/06/08 15:23:48
If you're doing it this way, you should drop the '
hal.canary
2015/06/08 15:55:24
Done.
| |
109 break; // http://crbug.com/494913 | |
110 } | |
108 if (*n < '!' || *n > '~' || strchr(kToEscape, *n)) { | 111 if (*n < '!' || *n > '~' || strchr(kToEscape, *n)) { |
109 count += 2; | 112 count += 2; |
110 } | 113 } |
111 ++count; | 114 ++count; |
112 } | 115 } |
113 SkString result(count); | 116 SkString result(count); |
114 char* s = result.writable_str(); | 117 char* s = result.writable_str(); |
115 static const char kHex[] = "0123456789ABCDEF"; | 118 static const char kHex[] = "0123456789ABCDEF"; |
116 for (const char* n = name; n != end; ++n) { | 119 for (const char* n = name; n != end; ++n) { |
120 if ('\0' == *n) { | |
121 break; | |
122 } | |
117 if (*n < '!' || *n > '~' || strchr(kToEscape, *n)) { | 123 if (*n < '!' || *n > '~' || strchr(kToEscape, *n)) { |
118 *s++ = '#'; | 124 *s++ = '#'; |
119 *s++ = kHex[(*n >> 4) & 0xF]; | 125 *s++ = kHex[(*n >> 4) & 0xF]; |
120 *s++ = kHex[*n & 0xF]; | 126 *s++ = kHex[*n & 0xF]; |
121 } else { | 127 } else { |
122 *s++ = *n; | 128 *s++ = *n; |
123 } | 129 } |
124 } | 130 } |
125 SkASSERT(&result.writable_str()[count] == s); // don't over-write | 131 SkASSERT(&result.writable_str()[count] == s); // don't over-write |
126 return result; // allocated space | 132 return result; // allocated space |
(...skipping 353 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
480 fObjects.push(obj); | 486 fObjects.push(obj); |
481 return true; | 487 return true; |
482 } | 488 } |
483 | 489 |
484 int32_t SkPDFObjNumMap::getObjectNumber(SkPDFObject* obj) const { | 490 int32_t SkPDFObjNumMap::getObjectNumber(SkPDFObject* obj) const { |
485 int32_t* objectNumberFound = fObjectNumbers.find(obj); | 491 int32_t* objectNumberFound = fObjectNumbers.find(obj); |
486 SkASSERT(objectNumberFound); | 492 SkASSERT(objectNumberFound); |
487 return *objectNumberFound; | 493 return *objectNumberFound; |
488 } | 494 } |
489 | 495 |
OLD | NEW |