From a99de0ec3cda8ff5b0d6383a059dd39c8626e504 Mon Sep 17 00:00:00 2001 From: Lei Zhang Date: Mon, 27 Feb 2017 14:45:56 -0800 Subject: Clean up CXML_Element. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Set more members in the ctor - Remove dead code - Use more unique_ptrs Change-Id: Idfe85d07c784a57862f9314bc85f407f817b8f2f Reviewed-on: https://pdfium-review.googlesource.com/2844 Commit-Queue: Lei Zhang Reviewed-by: Nicolás Peña Reviewed-by: dsinclair --- fpdfsdk/pdfwindow/PWL_Edit.cpp | 63 +++++++++++++++++++++++------------------- 1 file changed, 35 insertions(+), 28 deletions(-) (limited to 'fpdfsdk/pdfwindow') diff --git a/fpdfsdk/pdfwindow/PWL_Edit.cpp b/fpdfsdk/pdfwindow/PWL_Edit.cpp index 1ba8e7d72f..b77aad9ab0 100644 --- a/fpdfsdk/pdfwindow/PWL_Edit.cpp +++ b/fpdfsdk/pdfwindow/PWL_Edit.cpp @@ -6,6 +6,7 @@ #include "fpdfsdk/pdfwindow/PWL_Edit.h" +#include #include #include "core/fpdfapi/font/cpdf_font.h" @@ -41,35 +42,41 @@ void CPWL_Edit::OnDestroy() {} void CPWL_Edit::SetText(const CFX_WideString& csText) { CFX_WideString swText = csText; - if (HasFlag(PES_RICH)) { - CFX_ByteString sValue = CFX_ByteString::FromUnicode(swText); - if (CXML_Element* pXML = - CXML_Element::Parse(sValue.c_str(), sValue.GetLength())) { - int32_t nCount = pXML->CountChildren(); - bool bFirst = true; - - swText.clear(); - - for (int32_t i = 0; i < nCount; i++) { - if (CXML_Element* pSubElement = pXML->GetElement(i)) { - CFX_ByteString tag = pSubElement->GetTagName(); - if (tag.EqualNoCase("p")) { - int nChild = pSubElement->CountChildren(); - CFX_WideString swSection; - for (int32_t j = 0; j < nChild; j++) { - swSection += pSubElement->GetContent(j); - } - - if (bFirst) - bFirst = false; - else - swText += FWL_VKEY_Return; - swText += swSection; - } - } - } + if (!HasFlag(PES_RICH)) { + m_pEdit->SetText(swText); + return; + } + + CFX_ByteString sValue = CFX_ByteString::FromUnicode(swText); + std::unique_ptr pXML( + CXML_Element::Parse(sValue.c_str(), sValue.GetLength())); + if (!pXML) { + m_pEdit->SetText(swText); + return; + } + + int32_t nCount = pXML->CountChildren(); + bool bFirst = true; + + swText.clear(); + + for (int32_t i = 0; i < nCount; i++) { + CXML_Element* pSubElement = pXML->GetElement(i); + if (!pSubElement) + continue; + + CFX_ByteString tag = pSubElement->GetTagName(); + if (tag.EqualNoCase("p")) { + int nChild = pSubElement->CountChildren(); + CFX_WideString swSection; + for (int32_t j = 0; j < nChild; j++) + swSection += pSubElement->GetContent(j); - delete pXML; + if (bFirst) + bFirst = false; + else + swText += FWL_VKEY_Return; + swText += swSection; } } -- cgit v1.2.3