Format code

This commit is contained in:
Jay Berkenbilt 2024-02-24 10:29:41 -05:00
parent 54d8e920f1
commit 2d402e451c
2 changed files with 4 additions and 5 deletions

View File

@ -1,9 +1,9 @@
#include <qpdf/QPDFObjectHandle.hh> #include <qpdf/QPDFObjectHandle.hh>
#include <qpdf/BufferInputSource.hh> #include <qpdf/BufferInputSource.hh>
#include <qpdf/JSON_writer.hh>
#include <qpdf/Pl_Buffer.hh> #include <qpdf/Pl_Buffer.hh>
#include <qpdf/Pl_QPDFTokenizer.hh> #include <qpdf/Pl_QPDFTokenizer.hh>
#include <qpdf/JSON_writer.hh>
#include <qpdf/QPDF.hh> #include <qpdf/QPDF.hh>
#include <qpdf/QPDFExc.hh> #include <qpdf/QPDFExc.hh>
#include <qpdf/QPDFLogger.hh> #include <qpdf/QPDFLogger.hh>

View File

@ -51,22 +51,21 @@ QPDF_String::writeJSON(int json_version, JSON::Writer& p)
{ {
auto candidate = getUTF8Val(); auto candidate = getUTF8Val();
if (json_version == 1) { if (json_version == 1) {
p << "\"" << JSON::Writer::encode_string(candidate) << "\""; p << "\"" << JSON::Writer::encode_string(candidate) << "\"";
} else { } else {
// See if we can unambiguously represent as Unicode. // See if we can unambiguously represent as Unicode.
if (QUtil::is_utf16(this->val) || QUtil::is_explicit_utf8(this->val)) { if (QUtil::is_utf16(this->val) || QUtil::is_explicit_utf8(this->val)) {
p << "\"u:" << JSON::Writer::encode_string(candidate) <<"\""; p << "\"u:" << JSON::Writer::encode_string(candidate) << "\"";
return; return;
} else if (!useHexString()) { } else if (!useHexString()) {
std::string test; std::string test;
if (QUtil::utf8_to_pdf_doc(candidate, test, '?') && (test == this->val)) { if (QUtil::utf8_to_pdf_doc(candidate, test, '?') && (test == this->val)) {
// This is a PDF-doc string that can be losslessly encoded as Unicode. // This is a PDF-doc string that can be losslessly encoded as Unicode.
p << "\"u:" << JSON::Writer::encode_string(candidate) <<"\""; p << "\"u:" << JSON::Writer::encode_string(candidate) << "\"";
return; return;
} }
} }
p << "\"b:" << QUtil::hex_encode(val) <<"\""; p << "\"b:" << QUtil::hex_encode(val) << "\"";
} }
} }