summaryrefslogtreecommitdiff
path: root/fpdfsdk/pdfwindow
diff options
context:
space:
mode:
authorLei Zhang <thestig@chromium.org>2017-02-27 14:45:56 -0800
committerChromium commit bot <commit-bot@chromium.org>2017-02-28 00:35:05 +0000
commita99de0ec3cda8ff5b0d6383a059dd39c8626e504 (patch)
treefea2f04aca7aca32fc85c952040cf8593f40a64e /fpdfsdk/pdfwindow
parentce32acfa15071e6cd5bcce73280857014e396dd2 (diff)
downloadpdfium-a99de0ec3cda8ff5b0d6383a059dd39c8626e504.tar.xz
Clean up CXML_Element.chromium/3026
- 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 <thestig@chromium.org> Reviewed-by: Nicolás Peña <npm@chromium.org> Reviewed-by: dsinclair <dsinclair@chromium.org>
Diffstat (limited to 'fpdfsdk/pdfwindow')
-rw-r--r--fpdfsdk/pdfwindow/PWL_Edit.cpp63
1 files changed, 35 insertions, 28 deletions
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 <memory>
#include <vector>
#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<CXML_Element> 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;
}
}