From 4f1aa69662adf8e7038ed3abd6a36fc338119487 Mon Sep 17 00:00:00 2001 From: Lei Zhang Date: Mon, 13 Aug 2018 21:31:18 +0000 Subject: Move FDFToURLEncodedData() into an anonymous namespace. Change-Id: Iac581765f343f464f73a892b300ae20923c3bb32 Reviewed-on: https://pdfium-review.googlesource.com/39971 Reviewed-by: Tom Sepez Commit-Queue: Lei Zhang --- fpdfsdk/cpdfsdk_interform.cpp | 78 +++++++++++++++++++++---------------------- fpdfsdk/cpdfsdk_interform.h | 1 - 2 files changed, 39 insertions(+), 40 deletions(-) diff --git a/fpdfsdk/cpdfsdk_interform.cpp b/fpdfsdk/cpdfsdk_interform.cpp index 6a4b591ed0..3cd1b67b26 100644 --- a/fpdfsdk/cpdfsdk_interform.cpp +++ b/fpdfsdk/cpdfsdk_interform.cpp @@ -78,6 +78,45 @@ bool IsFormFieldTypeXFA(FormFieldType fieldType) { } #endif // PDF_ENABLE_XFA +bool FDFToURLEncodedData(uint8_t*& pBuf, size_t& nBufSize) { + std::unique_ptr pFDF = + CFDF_Document::ParseMemory(pBuf, nBufSize); + if (!pFDF) + return true; + + CPDF_Dictionary* pMainDict = pFDF->GetRoot()->GetDictFor("FDF"); + if (!pMainDict) + return false; + + CPDF_Array* pFields = pMainDict->GetArrayFor("Fields"); + if (!pFields) + return false; + + std::ostringstream fdfEncodedData; + for (uint32_t i = 0; i < pFields->GetCount(); i++) { + CPDF_Dictionary* pField = pFields->GetDictAt(i); + if (!pField) + continue; + WideString name; + name = pField->GetUnicodeTextFor("T"); + ByteString name_b = name.ToDefANSI(); + ByteString csBValue = pField->GetStringFor("V"); + WideString csWValue = PDF_DecodeText(csBValue); + ByteString csValue_b = csWValue.ToDefANSI(); + fdfEncodedData << name_b << "=" << csValue_b; + if (i != pFields->GetCount() - 1) + fdfEncodedData << "&"; + } + + nBufSize = fdfEncodedData.tellp(); + if (nBufSize <= 0) + return false; + + pBuf = FX_Alloc(uint8_t, nBufSize); + memcpy(pBuf, fdfEncodedData.str().c_str(), nBufSize); + return true; +} + } // namespace CPDFSDK_InterForm::CPDFSDK_InterForm(CPDFSDK_FormFillEnvironment* pFormFillEnv) @@ -485,45 +524,6 @@ bool CPDFSDK_InterForm::SubmitFields(const WideString& csDestination, return true; } -bool CPDFSDK_InterForm::FDFToURLEncodedData(uint8_t*& pBuf, size_t& nBufSize) { - std::unique_ptr pFDF = - CFDF_Document::ParseMemory(pBuf, nBufSize); - if (!pFDF) - return true; - - CPDF_Dictionary* pMainDict = pFDF->GetRoot()->GetDictFor("FDF"); - if (!pMainDict) - return false; - - CPDF_Array* pFields = pMainDict->GetArrayFor("Fields"); - if (!pFields) - return false; - - std::ostringstream fdfEncodedData; - for (uint32_t i = 0; i < pFields->GetCount(); i++) { - CPDF_Dictionary* pField = pFields->GetDictAt(i); - if (!pField) - continue; - WideString name; - name = pField->GetUnicodeTextFor("T"); - ByteString name_b = name.ToDefANSI(); - ByteString csBValue = pField->GetStringFor("V"); - WideString csWValue = PDF_DecodeText(csBValue); - ByteString csValue_b = csWValue.ToDefANSI(); - fdfEncodedData << name_b << "=" << csValue_b; - if (i != pFields->GetCount() - 1) - fdfEncodedData << "&"; - } - - nBufSize = fdfEncodedData.tellp(); - if (nBufSize <= 0) - return false; - - pBuf = FX_Alloc(uint8_t, nBufSize); - memcpy(pBuf, fdfEncodedData.str().c_str(), nBufSize); - return true; -} - ByteString CPDFSDK_InterForm::ExportFieldsToFDFTextBuf( const std::vector& fields, bool bIncludeOrExclude) { diff --git a/fpdfsdk/cpdfsdk_interform.h b/fpdfsdk/cpdfsdk_interform.h index bb6d7fc260..14772efe8f 100644 --- a/fpdfsdk/cpdfsdk_interform.h +++ b/fpdfsdk/cpdfsdk_interform.h @@ -111,7 +111,6 @@ class CPDFSDK_InterForm : public IPDF_FormNotify { void AfterCheckedStatusChange(CPDF_FormField* pField) override; void AfterFormReset(CPDF_InterForm* pForm) override; - bool FDFToURLEncodedData(uint8_t*& pBuf, size_t& nBufSize); int GetPageIndexByAnnotDict(CPDF_Document* pDocument, CPDF_Dictionary* pAnnotDict) const; -- cgit v1.2.3