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

Unified Diff: src/pdf/SkPDFTypes.cpp

Issue 1064013003: SkPDF: SkPDFString is no longer aware of wide strings. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: optimize SkPDFString::FormatString, stop appending everywhere Created 5 years, 8 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 | « src/pdf/SkPDFTypes.h ('k') | 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 e80d1186c38dc3e507604dd239e8570eec3653b0..89d6a0bc48dd7674ff3d3ed7fe11bc83db7b8099 100644
--- a/src/pdf/SkPDFTypes.cpp
+++ b/src/pdf/SkPDFTypes.cpp
@@ -133,10 +133,6 @@ SkPDFString::SkPDFString(const SkString& value)
: fValue(FormatString(value.c_str(), value.size())) {
}
-SkPDFString::SkPDFString(const uint16_t* value, size_t len, bool wideChars)
- : fValue(FormatString(value, len, wideChars)) {
-}
-
SkPDFString::~SkPDFString() {}
void SkPDFString::emitObject(SkWStream* stream,
@@ -146,67 +142,46 @@ void SkPDFString::emitObject(SkWStream* stream,
}
// static
-SkString SkPDFString::FormatString(const char* input, size_t len) {
- return DoFormatString(input, len, false, false);
-}
-
-SkString SkPDFString::FormatString(const uint16_t* input, size_t len,
- bool wideChars) {
- return DoFormatString(input, len, true, wideChars);
-}
-
-// static
-SkString SkPDFString::DoFormatString(const void* input, size_t len,
- bool wideInput, bool wideOutput) {
+SkString SkPDFString::FormatString(const char* cin, size_t len) {
SkASSERT(len <= kMaxLen);
- const uint16_t* win = (const uint16_t*) input;
- const char* cin = (const char*) input;
-
- if (wideOutput) {
- SkASSERT(wideInput);
- SkString result;
- result.append("<");
- for (size_t i = 0; i < len; i++) {
- result.appendHex(win[i], 4);
- }
- result.append(">");
- return result;
- }
// 7-bit clean is a heuristic to decide what string format to use;
// a 7-bit clean string should require little escaping.
bool sevenBitClean = true;
+ size_t characterCount = 2 + len;
for (size_t i = 0; i < len; i++) {
- SkASSERT(!wideInput || !(win[i] & ~0xFF));
- char val = wideInput ? win[i] : cin[i];
- if (val > '~' || val < ' ') {
+ if (cin[i] > '~' || cin[i] < ' ') {
sevenBitClean = false;
break;
}
+ if (cin[i] == '\\' || cin[i] == '(' || cin[i] == ')') {
+ ++characterCount;
+ }
}
-
SkString result;
if (sevenBitClean) {
- result.append("(");
+ result.resize(characterCount);
+ char* str = result.writable_str();
+ *str++ = '(';
for (size_t i = 0; i < len; i++) {
- SkASSERT(!wideInput || !(win[i] & ~0xFF));
- char val = wideInput ? win[i] : cin[i];
- if (val == '\\' || val == '(' || val == ')') {
- result.append("\\");
+ if (cin[i] == '\\' || cin[i] == '(' || cin[i] == ')') {
+ *str++ = '\\';
}
- result.append(&val, 1);
+ *str++ = cin[i];
}
- result.append(")");
+ *str++ = ')';
} else {
- result.append("<");
+ result.resize(2 * len + 2);
+ char* str = result.writable_str();
+ *str++ = '<';
for (size_t i = 0; i < len; i++) {
- SkASSERT(!wideInput || !(win[i] & ~0xFF));
- unsigned char val = wideInput ? win[i] : cin[i];
- result.appendHex(val, 2);
+ uint8_t c = static_cast<uint8_t>(cin[i]);
+ static const char gHex[] = "0123456789ABCDEF";
+ *str++ = gHex[(c >> 4) & 0xF];
+ *str++ = gHex[(c ) & 0xF];
}
- result.append(">");
+ *str++ = '>';
}
-
return result;
}
« no previous file with comments | « src/pdf/SkPDFTypes.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698