summaryrefslogtreecommitdiff
path: root/core/src/fpdfdoc
diff options
context:
space:
mode:
authorLei Zhang <thestig@chromium.org>2016-02-19 10:53:24 -0800
committerLei Zhang <thestig@chromium.org>2016-02-19 10:53:24 -0800
commit31c7b73b71bd7352f96a82716b5e81d7fa24f37f (patch)
tree292a068fb657e97cd0d11dc78a7528915f8a78e0 /core/src/fpdfdoc
parent490543247e07ce1c92f609bcc2fa484652a86e1f (diff)
downloadpdfium-31c7b73b71bd7352f96a82716b5e81d7fa24f37f.tar.xz
Remove CFX_{Byte,Wide}String::ConvertFrom().
Use/add CFX_{Byte,Wide}String::FromFoo() instead. R=tsepez@chromium.org Review URL: https://codereview.chromium.org/1711893003 .
Diffstat (limited to 'core/src/fpdfdoc')
-rw-r--r--core/src/fpdfdoc/doc_basic_unittest.cpp3
-rw-r--r--core/src/fpdfdoc/doc_form.cpp65
2 files changed, 31 insertions, 37 deletions
diff --git a/core/src/fpdfdoc/doc_basic_unittest.cpp b/core/src/fpdfdoc/doc_basic_unittest.cpp
index ecc603aa9e..c2fd3ff2b2 100644
--- a/core/src/fpdfdoc/doc_basic_unittest.cpp
+++ b/core/src/fpdfdoc/doc_basic_unittest.cpp
@@ -145,8 +145,7 @@ TEST(doc_basic_filespec, SetFileName) {
CPDF_FileSpec file_spec1(str_obj.get());
file_spec1.SetFileName(test_data.input);
// Check internal object value.
- CFX_ByteString str;
- str.ConvertFrom(test_data.expected);
+ CFX_ByteString str = CFX_ByteString::FromUnicode(test_data.expected);
EXPECT_TRUE(str == str_obj->GetString());
// Check we can get the file name back.
CFX_WideString file_name;
diff --git a/core/src/fpdfdoc/doc_form.cpp b/core/src/fpdfdoc/doc_form.cpp
index 460a44a7df..9252e073e0 100644
--- a/core/src/fpdfdoc/doc_form.cpp
+++ b/core/src/fpdfdoc/doc_form.cpp
@@ -8,8 +8,35 @@
#include "core/src/fpdfdoc/doc_utils.h"
#include "third_party/base/stl_util.h"
+namespace {
+
const int nMaxRecursion = 32;
+const struct SupportFieldEncoding {
+ const FX_CHAR* m_name;
+ FX_WORD m_codePage;
+} g_fieldEncoding[] = {
+ {"BigFive", 950},
+ {"GBK", 936},
+ {"Shift-JIS", 932},
+ {"UHC", 949},
+};
+
+CFX_WideString FPDFDOC_FDF_GetFieldValue(const CPDF_Dictionary& pFieldDict,
+ const CFX_ByteString& bsEncoding) {
+ const CFX_ByteString csBValue = pFieldDict.GetStringBy("V");
+ for (const auto& encoding : g_fieldEncoding) {
+ if (bsEncoding == encoding.m_name)
+ return CFX_WideString::FromCodePage(csBValue, encoding.m_codePage);
+ }
+ CFX_ByteString csTemp = csBValue.Left(2);
+ if (csTemp == "\xFF\xFE" || csTemp == "\xFE\xFF")
+ return PDF_DecodeText(csBValue);
+ return CFX_WideString::FromLocal(csBValue);
+}
+
+} // namespace
+
class CFieldNameExtractor {
public:
explicit CFieldNameExtractor(const CFX_WideString& full_name) {
@@ -1088,39 +1115,7 @@ CFDF_Document* CPDF_InterForm::ExportToFDF(
}
return pDoc;
}
-const struct _SupportFieldEncoding {
- const FX_CHAR* m_name;
- int32_t m_codePage;
-} g_fieldEncoding[] = {
- {"BigFive", 950},
- {"GBK", 936},
- {"Shift-JIS", 932},
- {"UHC", 949},
-};
-static void FPDFDOC_FDF_GetFieldValue(CPDF_Dictionary* pFieldDict,
- CFX_WideString& csValue,
- CFX_ByteString& bsEncoding) {
- CFX_ByteString csBValue = pFieldDict->GetStringBy("V");
- int32_t iCount = sizeof(g_fieldEncoding) / sizeof(g_fieldEncoding[0]);
- int32_t i = 0;
- for (; i < iCount; ++i)
- if (bsEncoding == g_fieldEncoding[i].m_name) {
- break;
- }
- if (i < iCount) {
- CFX_CharMap* pCharMap =
- CFX_CharMap::GetDefaultMapper(g_fieldEncoding[i].m_codePage);
- FXSYS_assert(pCharMap);
- csValue.ConvertFrom(csBValue, pCharMap);
- return;
- }
- CFX_ByteString csTemp = csBValue.Left(2);
- if (csTemp == "\xFF\xFE" || csTemp == "\xFE\xFF") {
- csValue = PDF_DecodeText(csBValue);
- } else {
- csValue = CFX_WideString::FromLocal(csBValue);
- }
-}
+
void CPDF_InterForm::FDF_ImportField(CPDF_Dictionary* pFieldDict,
const CFX_WideString& parent_name,
FX_BOOL bNotify,
@@ -1150,8 +1145,8 @@ void CPDF_InterForm::FDF_ImportField(CPDF_Dictionary* pFieldDict,
if (!pField) {
return;
}
- CFX_WideString csWValue;
- FPDFDOC_FDF_GetFieldValue(pFieldDict, csWValue, m_bsEncoding);
+ CFX_WideString csWValue =
+ FPDFDOC_FDF_GetFieldValue(*pFieldDict, m_bsEncoding);
int iType = pField->GetFieldType();
if (bNotify && m_pFormNotify) {
int iRet = 0;