diff options
-rw-r--r-- | core/include/fxcrt/fx_string.h | 9 | ||||
-rw-r--r-- | core/src/fpdfdoc/doc_basic_unittest.cpp | 3 | ||||
-rw-r--r-- | core/src/fpdfdoc/doc_form.cpp | 65 | ||||
-rw-r--r-- | core/src/fxcrt/fx_basic_bstring.cpp | 23 | ||||
-rw-r--r-- | core/src/fxcrt/fx_basic_wstring.cpp | 28 | ||||
-rw-r--r-- | core/src/fxcrt/fx_extension.cpp | 3 | ||||
-rw-r--r-- | xfa/src/fgas/src/crt/fx_system.cpp | 4 | ||||
-rw-r--r-- | xfa/src/fgas/src/localization/fx_locale.cpp | 6 | ||||
-rw-r--r-- | xfa/src/fxbarcode/BC_UtilCodingConvert.cpp | 18 |
9 files changed, 81 insertions, 78 deletions
diff --git a/core/include/fxcrt/fx_string.h b/core/include/fxcrt/fx_string.h index 36eba8d1c1..c625bfa925 100644 --- a/core/include/fxcrt/fx_string.h +++ b/core/include/fxcrt/fx_string.h @@ -289,8 +289,6 @@ class CFX_ByteString { CFX_WideString UTF8Decode() const; - void ConvertFrom(const CFX_WideString& str, CFX_CharMap* pCharMap = NULL); - FX_DWORD GetID(FX_STRSIZE start_pos = 0) const; #define FXFORMAT_SIGNED 1 @@ -561,7 +559,10 @@ class CFX_WideString { ~CFX_WideString(); - static CFX_WideString FromLocal(const char* str, FX_STRSIZE len = -1); + static CFX_WideString FromLocal(const CFX_ByteString& str); + + static CFX_WideString FromCodePage(const CFX_ByteString& str, + FX_WORD codepage); static CFX_WideString FromUTF8(const char* str, FX_STRSIZE len); @@ -685,8 +686,6 @@ class CFX_WideString { CFX_ByteString UTF16LE_Encode() const; - void ConvertFrom(const CFX_ByteString& str, CFX_CharMap* pCharMap = NULL); - protected: class StringData { public: 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; diff --git a/core/src/fxcrt/fx_basic_bstring.cpp b/core/src/fxcrt/fx_basic_bstring.cpp index e0d1146068..85e5041095 100644 --- a/core/src/fxcrt/fx_basic_bstring.cpp +++ b/core/src/fxcrt/fx_basic_bstring.cpp @@ -910,25 +910,20 @@ CFX_WideString CFX_ByteString::UTF8Decode() const { } return decoder.GetResult(); } + +// static CFX_ByteString CFX_ByteString::FromUnicode(const FX_WCHAR* str, FX_STRSIZE len) { - if (len < 0) { - len = FXSYS_wcslen(str); - } - CFX_ByteString bstr; - bstr.ConvertFrom(CFX_WideString(str, len)); - return bstr; + FX_STRSIZE str_len = len >= 0 ? len : FXSYS_wcslen(str); + return FromUnicode(CFX_WideString(str, str_len)); } + +// static CFX_ByteString CFX_ByteString::FromUnicode(const CFX_WideString& str) { - return FromUnicode(str.c_str(), str.GetLength()); -} -void CFX_ByteString::ConvertFrom(const CFX_WideString& str, - CFX_CharMap* pCharMap) { - if (!pCharMap) { - pCharMap = CFX_CharMap::GetDefaultMapper(); - } - *this = (*pCharMap->m_GetByteString)(pCharMap, str); + CFX_CharMap* pCharMap = CFX_CharMap::GetDefaultMapper(); + return (*pCharMap->m_GetByteString)(pCharMap, str); } + int CFX_ByteString::Compare(const CFX_ByteStringC& str) const { if (!m_pData) { return str.IsEmpty() ? 0 : -1; diff --git a/core/src/fxcrt/fx_basic_wstring.cpp b/core/src/fxcrt/fx_basic_wstring.cpp index 2370c87cf1..d83aa85213 100644 --- a/core/src/fxcrt/fx_basic_wstring.cpp +++ b/core/src/fxcrt/fx_basic_wstring.cpp @@ -303,13 +303,7 @@ CFX_ByteString CFX_WideString::UTF16LE_Encode() const { result.ReleaseBuffer(len * 2 + 2); return result; } -void CFX_WideString::ConvertFrom(const CFX_ByteString& str, - CFX_CharMap* pCharMap) { - if (!pCharMap) { - pCharMap = CFX_CharMap::GetDefaultMapper(); - } - *this = pCharMap->m_GetWideString(pCharMap, str); -} + void CFX_WideString::Reserve(FX_STRSIZE len) { GetBuffer(len); ReleaseBuffer(GetLength()); @@ -346,11 +340,20 @@ FX_WCHAR* CFX_WideString::GetBuffer(FX_STRSIZE nMinBufLength) { pOldData->Release(); return m_pData->m_String; } -CFX_WideString CFX_WideString::FromLocal(const char* str, FX_STRSIZE len) { - CFX_WideString result; - result.ConvertFrom(CFX_ByteString(str, len)); - return result; + +// static +CFX_WideString CFX_WideString::FromLocal(const CFX_ByteString& str) { + return FromCodePage(str, 0); } + +// static +CFX_WideString CFX_WideString::FromCodePage(const CFX_ByteString& str, + FX_WORD codepage) { + CFX_CharMap* pCharMap = CFX_CharMap::GetDefaultMapper(codepage); + return pCharMap->m_GetWideString(pCharMap, str); +} + +// static CFX_WideString CFX_WideString::FromUTF8(const char* str, FX_STRSIZE len) { if (!str || 0 == len) { return CFX_WideString(); @@ -362,6 +365,8 @@ CFX_WideString CFX_WideString::FromUTF8(const char* str, FX_STRSIZE len) { } return decoder.GetResult(); } + +// static CFX_WideString CFX_WideString::FromUTF16LE(const unsigned short* wstr, FX_STRSIZE wlen) { if (!wstr || 0 == wlen) { @@ -376,6 +381,7 @@ CFX_WideString CFX_WideString::FromUTF16LE(const unsigned short* wstr, result.ReleaseBuffer(wlen); return result; } + FX_STRSIZE CFX_WideString::WStringLength(const unsigned short* str) { FX_STRSIZE len = 0; if (str) diff --git a/core/src/fxcrt/fx_extension.cpp b/core/src/fxcrt/fx_extension.cpp index fa6245c9d3..cae1763c7e 100644 --- a/core/src/fxcrt/fx_extension.cpp +++ b/core/src/fxcrt/fx_extension.cpp @@ -133,7 +133,8 @@ FX_FLOAT FXSYS_strtof(const FX_CHAR* pcsStr, if (iLength < 0) { iLength = (int32_t)FXSYS_strlen(pcsStr); } - CFX_WideString ws = CFX_WideString::FromLocal(pcsStr, iLength); + CFX_WideString ws = + CFX_WideString::FromLocal(CFX_ByteString(pcsStr, iLength)); return FXSYS_wcstof(ws.c_str(), iLength, pUsedLen); } FX_FLOAT FXSYS_wcstof(const FX_WCHAR* pwsStr, diff --git a/xfa/src/fgas/src/crt/fx_system.cpp b/xfa/src/fgas/src/crt/fx_system.cpp index b08236bb1d..b11fcd271e 100644 --- a/xfa/src/fgas/src/crt/fx_system.cpp +++ b/xfa/src/fgas/src/crt/fx_system.cpp @@ -86,8 +86,8 @@ FX_FLOAT FX_strtof(const FX_CHAR* pcsStr, int32_t iLength, int32_t* pUsedLen) { if (iLength < 0) { iLength = FXSYS_strlen(pcsStr); } - return FX_wcstof(CFX_WideString::FromLocal(pcsStr, iLength), iLength, - pUsedLen); + return FX_wcstof(CFX_WideString::FromLocal(CFX_ByteString(pcsStr, iLength)), + iLength, pUsedLen); } FX_FLOAT FX_wcstof(const FX_WCHAR* pwsStr, int32_t iLength, int32_t* pUsedLen) { FXSYS_assert(pwsStr != NULL); diff --git a/xfa/src/fgas/src/localization/fx_locale.cpp b/xfa/src/fgas/src/localization/fx_locale.cpp index 4b69a5bbed..072d351a3a 100644 --- a/xfa/src/fgas/src/localization/fx_locale.cpp +++ b/xfa/src/fgas/src/localization/fx_locale.cpp @@ -4828,11 +4828,11 @@ CFX_Decimal::CFX_Decimal(const CFX_WideStringC& strObj) { } m_uFlags = FXMATH_DECIMAL_MAKEFLAGS(negmet && IsNotZero(), scale); } + CFX_Decimal::CFX_Decimal(const CFX_ByteStringC& strObj) { - CFX_WideString wstrObj; - wstrObj.ConvertFrom(strObj); - *this = CFX_Decimal(wstrObj); + *this = CFX_Decimal(CFX_WideString::FromLocal(strObj)); } + CFX_Decimal::operator CFX_WideString() const { CFX_WideString retString; CFX_WideString tmpbuf; diff --git a/xfa/src/fxbarcode/BC_UtilCodingConvert.cpp b/xfa/src/fxbarcode/BC_UtilCodingConvert.cpp index 8b01512ef1..280d3a73b6 100644 --- a/xfa/src/fxbarcode/BC_UtilCodingConvert.cpp +++ b/xfa/src/fxbarcode/BC_UtilCodingConvert.cpp @@ -6,25 +6,31 @@ #include "barcode.h" #include "BC_UtilCodingConvert.h" + CBC_UtilCodingConvert::CBC_UtilCodingConvert() {} + CBC_UtilCodingConvert::~CBC_UtilCodingConvert() {} + void CBC_UtilCodingConvert::UnicodeToLocale(const CFX_WideString& src, CFX_ByteString& dst) { - dst.ConvertFrom(src); + dst = CFX_ByteString::FromUnicode(src); } + void CBC_UtilCodingConvert::LocaleToUtf8(const CFX_ByteString& src, CFX_ByteString& dst) { - CFX_WideString unicode = CFX_WideString::FromLocal(src, src.GetLength()); + CFX_WideString unicode = CFX_WideString::FromLocal(src); dst = unicode.UTF8Encode(); } + void CBC_UtilCodingConvert::LocaleToUtf8(const CFX_ByteString& src, CFX_ByteArray& dst) { - CFX_WideString unicode = CFX_WideString::FromLocal(src, src.GetLength()); + CFX_WideString unicode = CFX_WideString::FromLocal(src); CFX_ByteString utf8 = unicode.UTF8Encode(); for (int32_t i = 0; i < utf8.GetLength(); i++) { dst.Add(utf8[i]); } } + void CBC_UtilCodingConvert::Utf8ToLocale(const CFX_ByteArray& src, CFX_ByteString& dst) { CFX_ByteString utf8; @@ -32,14 +38,16 @@ void CBC_UtilCodingConvert::Utf8ToLocale(const CFX_ByteArray& src, utf8 += src[i]; } CFX_WideString unicode = CFX_WideString::FromUTF8(utf8, utf8.GetLength()); - dst.ConvertFrom(unicode); + dst = CFX_ByteString::FromUnicode(unicode); } + void CBC_UtilCodingConvert::Utf8ToLocale(const uint8_t* src, int32_t count, CFX_ByteString& dst) { CFX_WideString unicode = CFX_WideString::FromUTF8((const char*)src, count); - dst.ConvertFrom(unicode); + dst = CFX_ByteString::FromUnicode(unicode); } + void CBC_UtilCodingConvert::UnicodeToUTF8(const CFX_WideString& src, CFX_ByteString& dst) { dst = src.UTF8Encode(); |