summaryrefslogtreecommitdiff
path: root/core/fpdfapi/parser
diff options
context:
space:
mode:
Diffstat (limited to 'core/fpdfapi/parser')
-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
5 files changed, 34 insertions, 3 deletions
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"));
+}