summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--BUILD.gn1
-rw-r--r--core/fpdfapi/edit/cpdf_creator.cpp1
-rw-r--r--core/fpdfapi/edit/cpdf_pagecontentgenerator.cpp1
-rw-r--r--core/fpdfapi/page/cpdf_streamcontentparser.cpp2
-rw-r--r--core/fpdfapi/parser/cpdf_dictionary.cpp2
-rw-r--r--core/fpdfapi/parser/cpdf_name.cpp1
-rw-r--r--core/fpdfapi/parser/fpdf_parser_decode.h2
-rw-r--r--core/fpdfapi/parser/fpdf_parser_utility.h5
-rw-r--r--core/fpdfapi/parser/fpdf_parser_utility_unittest.cpp27
-rw-r--r--core/fpdfdoc/cpdf_defaultappearance.cpp2
-rw-r--r--core/fpdfdoc/cpdf_interform.cpp1
-rw-r--r--core/fpdfdoc/cpvt_generateap.cpp1
-rw-r--r--fpdfsdk/formfiller/cba_fontmap.cpp2
13 files changed, 42 insertions, 6 deletions
diff --git a/BUILD.gn b/BUILD.gn
index f1a8e258ca..1598e76d49 100644
--- a/BUILD.gn
+++ b/BUILD.gn
@@ -2867,6 +2867,7 @@ test("pdfium_unittests") {
"core/fpdfapi/parser/cpdf_simple_parser_unittest.cpp",
"core/fpdfapi/parser/cpdf_syntax_parser_unittest.cpp",
"core/fpdfapi/parser/fpdf_parser_decode_unittest.cpp",
+ "core/fpdfapi/parser/fpdf_parser_utility_unittest.cpp",
"core/fpdfdoc/cpdf_defaultappearance_unittest.cpp",
"core/fpdfdoc/cpdf_dest_unittest.cpp",
"core/fpdfdoc/cpdf_filespec_unittest.cpp",
diff --git a/core/fpdfapi/edit/cpdf_creator.cpp b/core/fpdfapi/edit/cpdf_creator.cpp
index adf507f844..0ab5612654 100644
--- a/core/fpdfapi/edit/cpdf_creator.cpp
+++ b/core/fpdfapi/edit/cpdf_creator.cpp
@@ -18,6 +18,7 @@
#include "core/fpdfapi/parser/cpdf_security_handler.h"
#include "core/fpdfapi/parser/cpdf_string.h"
#include "core/fpdfapi/parser/fpdf_parser_decode.h"
+#include "core/fpdfapi/parser/fpdf_parser_utility.h"
#include "core/fxcrt/fx_extension.h"
#include "core/fxcrt/fx_random.h"
diff --git a/core/fpdfapi/edit/cpdf_pagecontentgenerator.cpp b/core/fpdfapi/edit/cpdf_pagecontentgenerator.cpp
index 2a59123344..92b92ecf01 100644
--- a/core/fpdfapi/edit/cpdf_pagecontentgenerator.cpp
+++ b/core/fpdfapi/edit/cpdf_pagecontentgenerator.cpp
@@ -25,6 +25,7 @@
#include "core/fpdfapi/parser/cpdf_reference.h"
#include "core/fpdfapi/parser/cpdf_stream.h"
#include "core/fpdfapi/parser/fpdf_parser_decode.h"
+#include "core/fpdfapi/parser/fpdf_parser_utility.h"
#include "third_party/skia_shared/SkFloatToDecimal.h"
namespace {
diff --git a/core/fpdfapi/page/cpdf_streamcontentparser.cpp b/core/fpdfapi/page/cpdf_streamcontentparser.cpp
index c369604340..3b8dac9244 100644
--- a/core/fpdfapi/page/cpdf_streamcontentparser.cpp
+++ b/core/fpdfapi/page/cpdf_streamcontentparser.cpp
@@ -33,7 +33,7 @@
#include "core/fpdfapi/parser/cpdf_number.h"
#include "core/fpdfapi/parser/cpdf_reference.h"
#include "core/fpdfapi/parser/cpdf_stream.h"
-#include "core/fpdfapi/parser/fpdf_parser_decode.h"
+#include "core/fpdfapi/parser/fpdf_parser_utility.h"
#include "core/fxcrt/fx_safe_types.h"
#include "core/fxge/cfx_graphstatedata.h"
#include "third_party/base/logging.h"
diff --git a/core/fpdfapi/parser/cpdf_dictionary.cpp b/core/fpdfapi/parser/cpdf_dictionary.cpp
index 1e7f6a9a9b..b3195b58af 100644
--- a/core/fpdfapi/parser/cpdf_dictionary.cpp
+++ b/core/fpdfapi/parser/cpdf_dictionary.cpp
@@ -17,7 +17,7 @@
#include "core/fpdfapi/parser/cpdf_reference.h"
#include "core/fpdfapi/parser/cpdf_stream.h"
#include "core/fpdfapi/parser/cpdf_string.h"
-#include "core/fpdfapi/parser/fpdf_parser_decode.h"
+#include "core/fpdfapi/parser/fpdf_parser_utility.h"
#include "core/fxcrt/fx_stream.h"
#include "third_party/base/logging.h"
#include "third_party/base/stl_util.h"
diff --git a/core/fpdfapi/parser/cpdf_name.cpp b/core/fpdfapi/parser/cpdf_name.cpp
index 0607a30342..59a014208b 100644
--- a/core/fpdfapi/parser/cpdf_name.cpp
+++ b/core/fpdfapi/parser/cpdf_name.cpp
@@ -7,6 +7,7 @@
#include "core/fpdfapi/parser/cpdf_name.h"
#include "core/fpdfapi/parser/fpdf_parser_decode.h"
+#include "core/fpdfapi/parser/fpdf_parser_utility.h"
#include "core/fxcrt/fx_stream.h"
#include "third_party/base/ptr_util.h"
diff --git a/core/fpdfapi/parser/fpdf_parser_decode.h b/core/fpdfapi/parser/fpdf_parser_decode.h
index ab819c4832..d60e551e80 100644
--- a/core/fpdfapi/parser/fpdf_parser_decode.h
+++ b/core/fpdfapi/parser/fpdf_parser_decode.h
@@ -17,8 +17,6 @@ class CPDF_Dictionary;
// Indexed by 8-bit char code, contains unicode code points.
extern const uint16_t PDFDocEncoding[256];
-ByteString PDF_NameDecode(const ByteStringView& orig);
-ByteString PDF_NameEncode(const ByteString& orig);
ByteString PDF_EncodeString(const ByteString& src, bool bHex);
WideString PDF_DecodeText(const uint8_t* pData, uint32_t size);
WideString PDF_DecodeText(const ByteString& bstr);
diff --git a/core/fpdfapi/parser/fpdf_parser_utility.h b/core/fpdfapi/parser/fpdf_parser_utility.h
index e4b922cad2..3ae8f6f13f 100644
--- a/core/fpdfapi/parser/fpdf_parser_utility.h
+++ b/core/fpdfapi/parser/fpdf_parser_utility.h
@@ -7,6 +7,8 @@
#ifndef CORE_FPDFAPI_PARSER_FPDF_PARSER_UTILITY_H_
#define CORE_FPDFAPI_PARSER_FPDF_PARSER_UTILITY_H_
+#include <ostream>
+
#include "core/fxcrt/fx_string.h"
#include "core/fxcrt/retain_ptr.h"
@@ -43,6 +45,9 @@ int32_t GetHeaderOffset(const RetainPtr<IFX_SeekableReadStream>& pFile);
int32_t GetDirectInteger(CPDF_Dictionary* pDict, const ByteString& key);
+ByteString PDF_NameDecode(const ByteStringView& orig);
+ByteString PDF_NameEncode(const ByteString& orig);
+
std::ostream& operator<<(std::ostream& buf, const CPDF_Object* pObj);
#endif // CORE_FPDFAPI_PARSER_FPDF_PARSER_UTILITY_H_
diff --git a/core/fpdfapi/parser/fpdf_parser_utility_unittest.cpp b/core/fpdfapi/parser/fpdf_parser_utility_unittest.cpp
new file mode 100644
index 0000000000..16c4b40ce6
--- /dev/null
+++ b/core/fpdfapi/parser/fpdf_parser_utility_unittest.cpp
@@ -0,0 +1,27 @@
+// Copyright 2018 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "core/fpdfapi/parser/fpdf_parser_utility.h"
+
+#include "testing/gtest/include/gtest/gtest.h"
+#include "testing/test_support.h"
+
+TEST(fpdf_parser_utility, PDF_NameDecode) {
+ EXPECT_EQ("", PDF_NameDecode(""));
+ EXPECT_EQ("A", PDF_NameDecode("A"));
+ EXPECT_EQ("#", PDF_NameDecode("#"));
+ EXPECT_EQ("#4", PDF_NameDecode("#4"));
+ EXPECT_EQ("A", PDF_NameDecode("#41"));
+ EXPECT_EQ("A1", PDF_NameDecode("#411"));
+}
+
+TEST(fpdf_parser_utility, PDF_NameEncode) {
+ EXPECT_EQ("", PDF_NameEncode(""));
+ EXPECT_EQ("A", PDF_NameEncode("A"));
+ EXPECT_EQ("#23", PDF_NameEncode("#"));
+ EXPECT_EQ("#20", PDF_NameEncode(" "));
+ EXPECT_EQ("!@#23$#25^&*#28#29#3C#3E#5B#5D", PDF_NameEncode("!@#$%^&*()<>[]"));
+ EXPECT_EQ("#C2", PDF_NameEncode("\xc2"));
+ EXPECT_EQ("f#C2#A5", PDF_NameEncode("f\xc2\xa5"));
+}
diff --git a/core/fpdfdoc/cpdf_defaultappearance.cpp b/core/fpdfdoc/cpdf_defaultappearance.cpp
index de85c9cb33..5db3ff77a8 100644
--- a/core/fpdfdoc/cpdf_defaultappearance.cpp
+++ b/core/fpdfdoc/cpdf_defaultappearance.cpp
@@ -10,7 +10,7 @@
#include <vector>
#include "core/fpdfapi/parser/cpdf_simple_parser.h"
-#include "core/fpdfapi/parser/fpdf_parser_decode.h"
+#include "core/fpdfapi/parser/fpdf_parser_utility.h"
#include "core/fxge/cfx_color.h"
namespace {
diff --git a/core/fpdfdoc/cpdf_interform.cpp b/core/fpdfdoc/cpdf_interform.cpp
index c16c36ef3d..6c53c971d8 100644
--- a/core/fpdfdoc/cpdf_interform.cpp
+++ b/core/fpdfdoc/cpdf_interform.cpp
@@ -18,6 +18,7 @@
#include "core/fpdfapi/parser/cpdf_name.h"
#include "core/fpdfapi/parser/cpdf_reference.h"
#include "core/fpdfapi/parser/cpdf_string.h"
+#include "core/fpdfapi/parser/fpdf_parser_utility.h"
#include "core/fpdfdoc/cpdf_filespec.h"
#include "core/fpdfdoc/cpdf_formcontrol.h"
#include "core/fxcrt/fx_codepage.h"
diff --git a/core/fpdfdoc/cpvt_generateap.cpp b/core/fpdfdoc/cpvt_generateap.cpp
index ef55545f9e..22f7c8f5d9 100644
--- a/core/fpdfdoc/cpvt_generateap.cpp
+++ b/core/fpdfdoc/cpvt_generateap.cpp
@@ -22,6 +22,7 @@
#include "core/fpdfapi/parser/cpdf_stream.h"
#include "core/fpdfapi/parser/cpdf_string.h"
#include "core/fpdfapi/parser/fpdf_parser_decode.h"
+#include "core/fpdfapi/parser/fpdf_parser_utility.h"
#include "core/fpdfdoc/cpdf_annot.h"
#include "core/fpdfdoc/cpdf_defaultappearance.h"
#include "core/fpdfdoc/cpdf_formfield.h"
diff --git a/fpdfsdk/formfiller/cba_fontmap.cpp b/fpdfsdk/formfiller/cba_fontmap.cpp
index 0daa0cd5ac..2e11fa8908 100644
--- a/fpdfsdk/formfiller/cba_fontmap.cpp
+++ b/fpdfsdk/formfiller/cba_fontmap.cpp
@@ -13,7 +13,7 @@
#include "core/fpdfapi/parser/cpdf_document.h"
#include "core/fpdfapi/parser/cpdf_reference.h"
#include "core/fpdfapi/parser/cpdf_stream.h"
-#include "core/fpdfapi/parser/fpdf_parser_decode.h"
+#include "core/fpdfapi/parser/fpdf_parser_utility.h"
#include "core/fpdfdoc/cpdf_defaultappearance.h"
#include "core/fpdfdoc/cpdf_formfield.h"
#include "core/fxge/cfx_substfont.h"