aboutsummaryrefslogtreecommitdiff
path: root/core/fxcrt/xml
diff options
context:
space:
mode:
Diffstat (limited to 'core/fxcrt/xml')
-rw-r--r--core/fxcrt/xml/cfx_xmlchardata.cpp4
-rw-r--r--core/fxcrt/xml/cfx_xmlchardata.h6
-rw-r--r--core/fxcrt/xml/cfx_xmlchardata_unittest.cpp2
-rw-r--r--core/fxcrt/xml/cfx_xmldocument.cpp8
-rw-r--r--core/fxcrt/xml/cfx_xmldocument.h9
-rw-r--r--core/fxcrt/xml/cfx_xmldocument_unittest.cpp2
-rw-r--r--core/fxcrt/xml/cfx_xmlelement.cpp20
-rw-r--r--core/fxcrt/xml/cfx_xmlelement.h7
-rw-r--r--core/fxcrt/xml/cfx_xmlelement_unittest.cpp2
-rw-r--r--core/fxcrt/xml/cfx_xmlinstruction.cpp6
-rw-r--r--core/fxcrt/xml/cfx_xmlinstruction.h6
-rw-r--r--core/fxcrt/xml/cfx_xmlinstruction_unittest.cpp8
-rw-r--r--core/fxcrt/xml/cfx_xmlnode.cpp12
-rw-r--r--core/fxcrt/xml/cfx_xmlnode.h8
-rw-r--r--core/fxcrt/xml/cfx_xmlnode_unittest.cpp4
-rw-r--r--core/fxcrt/xml/cfx_xmlparser.cpp68
-rw-r--r--core/fxcrt/xml/cfx_xmlparser.h13
-rw-r--r--core/fxcrt/xml/cfx_xmlparser_unittest.cpp27
-rw-r--r--core/fxcrt/xml/cfx_xmltext.cpp6
-rw-r--r--core/fxcrt/xml/cfx_xmltext.h6
-rw-r--r--core/fxcrt/xml/cfx_xmltext_unittest.cpp2
21 files changed, 113 insertions, 113 deletions
diff --git a/core/fxcrt/xml/cfx_xmlchardata.cpp b/core/fxcrt/xml/cfx_xmlchardata.cpp
index 1d42bd067..88b8920f9 100644
--- a/core/fxcrt/xml/cfx_xmlchardata.cpp
+++ b/core/fxcrt/xml/cfx_xmlchardata.cpp
@@ -1,4 +1,4 @@
-// Copyright 2017 PDFium Authors. All rights reserved.
+// Copyright 2017 The PDFium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -22,7 +22,7 @@ CFX_XMLNode* CFX_XMLCharData::Clone(CFX_XMLDocument* doc) {
}
void CFX_XMLCharData::Save(
- const RetainPtr<IFX_SeekableWriteStream>& pXMLStream) {
+ const RetainPtr<IFX_RetainableWriteStream>& pXMLStream) {
pXMLStream->WriteString("<![CDATA[");
pXMLStream->WriteString(GetText().ToUTF8().AsStringView());
pXMLStream->WriteString("]]>");
diff --git a/core/fxcrt/xml/cfx_xmlchardata.h b/core/fxcrt/xml/cfx_xmlchardata.h
index 4d3a7f01d..356d55548 100644
--- a/core/fxcrt/xml/cfx_xmlchardata.h
+++ b/core/fxcrt/xml/cfx_xmlchardata.h
@@ -1,4 +1,4 @@
-// Copyright 2017 PDFium Authors. All rights reserved.
+// Copyright 2017 The PDFium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -7,7 +7,7 @@
#ifndef CORE_FXCRT_XML_CFX_XMLCHARDATA_H_
#define CORE_FXCRT_XML_CFX_XMLCHARDATA_H_
-#include "core/fxcrt/fx_string.h"
+#include "core/fxcrt/widestring.h"
#include "core/fxcrt/xml/cfx_xmltext.h"
class CFX_XMLDocument;
@@ -20,7 +20,7 @@ class CFX_XMLCharData final : public CFX_XMLText {
// CFX_XMLNode
Type GetType() const override;
CFX_XMLNode* Clone(CFX_XMLDocument* doc) override;
- void Save(const RetainPtr<IFX_SeekableWriteStream>& pXMLStream) override;
+ void Save(const RetainPtr<IFX_RetainableWriteStream>& pXMLStream) override;
};
inline CFX_XMLCharData* ToXMLCharData(CFX_XMLNode* pNode) {
diff --git a/core/fxcrt/xml/cfx_xmlchardata_unittest.cpp b/core/fxcrt/xml/cfx_xmlchardata_unittest.cpp
index 60798bd27..8afa2ca06 100644
--- a/core/fxcrt/xml/cfx_xmlchardata_unittest.cpp
+++ b/core/fxcrt/xml/cfx_xmlchardata_unittest.cpp
@@ -1,4 +1,4 @@
-// Copyright 2018 PDFium Authors. All rights reserved.
+// Copyright 2018 The PDFium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
diff --git a/core/fxcrt/xml/cfx_xmldocument.cpp b/core/fxcrt/xml/cfx_xmldocument.cpp
index 1c6656d1c..f2c38da9e 100644
--- a/core/fxcrt/xml/cfx_xmldocument.cpp
+++ b/core/fxcrt/xml/cfx_xmldocument.cpp
@@ -1,15 +1,15 @@
-// Copyright 2018 PDFium Authors. All rights reserved.
+// Copyright 2018 The PDFium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "core/fxcrt/xml/cfx_xmldocument.h"
#include "core/fxcrt/fx_system.h"
+#include "core/fxcrt/xml/cfx_xmlelement.h"
#include "core/fxcrt/xml/cfx_xmlinstruction.h"
-CFX_XMLDocument::CFX_XMLDocument() {
- root_ = CreateNode<CFX_XMLElement>(L"root");
-}
+CFX_XMLDocument::CFX_XMLDocument()
+ : root_(CreateNode<CFX_XMLElement>(L"root")) {}
CFX_XMLDocument::~CFX_XMLDocument() = default;
diff --git a/core/fxcrt/xml/cfx_xmldocument.h b/core/fxcrt/xml/cfx_xmldocument.h
index 9931314ec..053cc610b 100644
--- a/core/fxcrt/xml/cfx_xmldocument.h
+++ b/core/fxcrt/xml/cfx_xmldocument.h
@@ -1,4 +1,4 @@
-// Copyright 2018 PDFium Authors. All rights reserved.
+// Copyright 2018 The PDFium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -10,9 +10,8 @@
#include <vector>
#include "core/fxcrt/unowned_ptr.h"
-#include "core/fxcrt/xml/cfx_xmlelement.h"
-#include "third_party/base/ptr_util.h"
+class CFX_XMLElement;
class CFX_XMLNode;
class CFX_XMLDocument {
@@ -20,11 +19,11 @@ class CFX_XMLDocument {
CFX_XMLDocument();
~CFX_XMLDocument();
- CFX_XMLElement* GetRoot() const { return root_.Get(); }
+ CFX_XMLElement* GetRoot() const { return root_; }
template <typename T, typename... Args>
T* CreateNode(Args&&... args) {
- nodes_.push_back(pdfium::MakeUnique<T>(std::forward<Args>(args)...));
+ nodes_.push_back(std::make_unique<T>(std::forward<Args>(args)...));
return static_cast<T*>(nodes_.back().get());
}
diff --git a/core/fxcrt/xml/cfx_xmldocument_unittest.cpp b/core/fxcrt/xml/cfx_xmldocument_unittest.cpp
index 8043cc69a..7faabffd0 100644
--- a/core/fxcrt/xml/cfx_xmldocument_unittest.cpp
+++ b/core/fxcrt/xml/cfx_xmldocument_unittest.cpp
@@ -1,4 +1,4 @@
-// Copyright 2018 PDFium Authors. All rights reserved.
+// Copyright 2018 The PDFium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
diff --git a/core/fxcrt/xml/cfx_xmlelement.cpp b/core/fxcrt/xml/cfx_xmlelement.cpp
index b999f5cda..81b0865f9 100644
--- a/core/fxcrt/xml/cfx_xmlelement.cpp
+++ b/core/fxcrt/xml/cfx_xmlelement.cpp
@@ -1,4 +1,4 @@
-// Copyright 2017 PDFium Authors. All rights reserved.
+// Copyright 2017 The PDFium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -6,16 +6,14 @@
#include "core/fxcrt/xml/cfx_xmlelement.h"
-#include <utility>
-
-#include "core/fxcrt/cfx_widetextbuf.h"
#include "core/fxcrt/fx_extension.h"
#include "core/fxcrt/xml/cfx_xmlchardata.h"
#include "core/fxcrt/xml/cfx_xmldocument.h"
#include "core/fxcrt/xml/cfx_xmltext.h"
+#include "third_party/base/check.h"
CFX_XMLElement::CFX_XMLElement(const WideString& wsTag) : name_(wsTag) {
- ASSERT(!name_.IsEmpty());
+ DCHECK(!name_.IsEmpty());
}
CFX_XMLElement::~CFX_XMLElement() = default;
@@ -69,24 +67,24 @@ WideString CFX_XMLElement::GetNamespaceURI() const {
}
WideString CFX_XMLElement::GetTextData() const {
- CFX_WideTextBuf buffer;
+ WideString buffer;
for (CFX_XMLNode* pChild = GetFirstChild(); pChild;
pChild = pChild->GetNextSibling()) {
CFX_XMLText* pText = ToXMLText(pChild);
if (pText)
- buffer << pText->GetText();
+ buffer += pText->GetText();
}
- return buffer.MakeString();
+ return buffer;
}
void CFX_XMLElement::Save(
- const RetainPtr<IFX_SeekableWriteStream>& pXMLStream) {
+ const RetainPtr<IFX_RetainableWriteStream>& pXMLStream) {
ByteString bsNameEncoded = name_.ToUTF8();
pXMLStream->WriteString("<");
pXMLStream->WriteString(bsNameEncoded.AsStringView());
- for (auto it : attrs_) {
+ for (const auto& it : attrs_) {
// Note, the space between attributes is added by AttributeToString which
// writes a blank as the first character.
pXMLStream->WriteString(
@@ -150,7 +148,7 @@ WideString CFX_XMLElement::AttributeToString(const WideString& name,
WideString ret = L" ";
ret += name;
ret += L"=\"";
- ret += EncodeEntities(value);
+ ret += value.EncodeEntities();
ret += L"\"";
return ret;
}
diff --git a/core/fxcrt/xml/cfx_xmlelement.h b/core/fxcrt/xml/cfx_xmlelement.h
index efc9fbb11..d48bf9fe0 100644
--- a/core/fxcrt/xml/cfx_xmlelement.h
+++ b/core/fxcrt/xml/cfx_xmlelement.h
@@ -1,4 +1,4 @@
-// Copyright 2017 PDFium Authors. All rights reserved.
+// Copyright 2017 The PDFium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -9,7 +9,7 @@
#include <map>
-#include "core/fxcrt/fx_string.h"
+#include "core/fxcrt/widestring.h"
#include "core/fxcrt/xml/cfx_xmlnode.h"
class CFX_XMLDocument;
@@ -22,7 +22,7 @@ class CFX_XMLElement final : public CFX_XMLNode {
// CFX_XMLNode
Type GetType() const override;
CFX_XMLNode* Clone(CFX_XMLDocument* doc) override;
- void Save(const RetainPtr<IFX_SeekableWriteStream>& pXMLStream) override;
+ void Save(const RetainPtr<IFX_RetainableWriteStream>& pXMLStream) override;
const WideString& GetName() const { return name_; }
@@ -32,7 +32,6 @@ class CFX_XMLElement final : public CFX_XMLNode {
bool HasAttribute(const WideString& name) const;
void SetAttribute(const WideString& name, const WideString& value);
WideString GetAttribute(const WideString& name) const;
-
void RemoveAttribute(const WideString& name);
CFX_XMLElement* GetFirstChildNamed(WideStringView name) const;
diff --git a/core/fxcrt/xml/cfx_xmlelement_unittest.cpp b/core/fxcrt/xml/cfx_xmlelement_unittest.cpp
index 0053358b0..59d4b4088 100644
--- a/core/fxcrt/xml/cfx_xmlelement_unittest.cpp
+++ b/core/fxcrt/xml/cfx_xmlelement_unittest.cpp
@@ -1,4 +1,4 @@
-// Copyright 2018 PDFium Authors. All rights reserved.
+// Copyright 2018 The PDFium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
diff --git a/core/fxcrt/xml/cfx_xmlinstruction.cpp b/core/fxcrt/xml/cfx_xmlinstruction.cpp
index ac01f4e33..74389bb3e 100644
--- a/core/fxcrt/xml/cfx_xmlinstruction.cpp
+++ b/core/fxcrt/xml/cfx_xmlinstruction.cpp
@@ -1,4 +1,4 @@
-// Copyright 2017 PDFium Authors. All rights reserved.
+// Copyright 2017 The PDFium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -6,8 +6,6 @@
#include "core/fxcrt/xml/cfx_xmlinstruction.h"
-#include <utility>
-
#include "core/fxcrt/fx_codepage.h"
#include "core/fxcrt/fx_extension.h"
#include "core/fxcrt/xml/cfx_xmldocument.h"
@@ -40,7 +38,7 @@ bool CFX_XMLInstruction::IsAcrobat() const {
}
void CFX_XMLInstruction::Save(
- const RetainPtr<IFX_SeekableWriteStream>& pXMLStream) {
+ const RetainPtr<IFX_RetainableWriteStream>& pXMLStream) {
if (name_.EqualsASCIINoCase("xml")) {
pXMLStream->WriteString("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
return;
diff --git a/core/fxcrt/xml/cfx_xmlinstruction.h b/core/fxcrt/xml/cfx_xmlinstruction.h
index f4ba112f2..72cdbdfe7 100644
--- a/core/fxcrt/xml/cfx_xmlinstruction.h
+++ b/core/fxcrt/xml/cfx_xmlinstruction.h
@@ -1,4 +1,4 @@
-// Copyright 2017 PDFium Authors. All rights reserved.
+// Copyright 2017 The PDFium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -9,7 +9,7 @@
#include <vector>
-#include "core/fxcrt/fx_string.h"
+#include "core/fxcrt/widestring.h"
#include "core/fxcrt/xml/cfx_xmlnode.h"
class CFX_XMLDocument;
@@ -22,7 +22,7 @@ class CFX_XMLInstruction final : public CFX_XMLNode {
// CFX_XMLNode
Type GetType() const override;
CFX_XMLNode* Clone(CFX_XMLDocument* doc) override;
- void Save(const RetainPtr<IFX_SeekableWriteStream>& pXMLStream) override;
+ void Save(const RetainPtr<IFX_RetainableWriteStream>& pXMLStream) override;
bool IsOriginalXFAVersion() const;
bool IsAcrobat() const;
diff --git a/core/fxcrt/xml/cfx_xmlinstruction_unittest.cpp b/core/fxcrt/xml/cfx_xmlinstruction_unittest.cpp
index 97d9ddf56..3b7f1d908 100644
--- a/core/fxcrt/xml/cfx_xmlinstruction_unittest.cpp
+++ b/core/fxcrt/xml/cfx_xmlinstruction_unittest.cpp
@@ -1,4 +1,4 @@
-// Copyright 2018 PDFium Authors. All rights reserved.
+// Copyright 2018 The PDFium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -6,7 +6,7 @@
#include <memory>
-#include "core/fxcrt/cfx_readonlymemorystream.h"
+#include "core/fxcrt/cfx_read_only_span_stream.h"
#include "core/fxcrt/xml/cfx_xmldocument.h"
#include "core/fxcrt/xml/cfx_xmlelement.h"
#include "core/fxcrt/xml/cfx_xmlparser.h"
@@ -87,7 +87,7 @@ TEST(CFX_XMLInstructionTest, ParseAndReSave) {
"<?acrobat http://www.xfa.org/schema/xfa-template/3.3/ Display:1 ?>\n"
"<node></node>";
- auto in_stream = pdfium::MakeRetain<CFX_ReadOnlyMemoryStream>(
+ auto in_stream = pdfium::MakeRetain<CFX_ReadOnlySpanStream>(
pdfium::as_bytes(pdfium::make_span(input)));
CFX_XMLParser parser(in_stream);
@@ -120,7 +120,7 @@ TEST(CFX_XMLInstructionTest, ParseAndReSaveInnerInstruction) {
"<?acrobat http://www.xfa.org/schema/xfa-template/3.3/ Display:1 ?>\n"
"</node>";
- auto in_stream = pdfium::MakeRetain<CFX_ReadOnlyMemoryStream>(
+ auto in_stream = pdfium::MakeRetain<CFX_ReadOnlySpanStream>(
pdfium::as_bytes(pdfium::make_span(input)));
CFX_XMLParser parser(in_stream);
diff --git a/core/fxcrt/xml/cfx_xmlnode.cpp b/core/fxcrt/xml/cfx_xmlnode.cpp
index 94b035b11..4ce2a60a9 100644
--- a/core/fxcrt/xml/cfx_xmlnode.cpp
+++ b/core/fxcrt/xml/cfx_xmlnode.cpp
@@ -1,4 +1,4 @@
-// Copyright 2017 PDFium Authors. All rights reserved.
+// Copyright 2017 The PDFium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -21,13 +21,3 @@ CFX_XMLNode* CFX_XMLNode::GetRoot() {
return pParent;
}
-
-WideString CFX_XMLNode::EncodeEntities(const WideString& value) {
- WideString ret = value;
- ret.Replace(L"&", L"&amp;");
- ret.Replace(L"<", L"&lt;");
- ret.Replace(L">", L"&gt;");
- ret.Replace(L"\'", L"&apos;");
- ret.Replace(L"\"", L"&quot;");
- return ret;
-}
diff --git a/core/fxcrt/xml/cfx_xmlnode.h b/core/fxcrt/xml/cfx_xmlnode.h
index d4d48b1a2..5934bc703 100644
--- a/core/fxcrt/xml/cfx_xmlnode.h
+++ b/core/fxcrt/xml/cfx_xmlnode.h
@@ -1,4 +1,4 @@
-// Copyright 2017 PDFium Authors. All rights reserved.
+// Copyright 2017 The PDFium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -8,7 +8,6 @@
#define CORE_FXCRT_XML_CFX_XMLNODE_H_
#include "core/fxcrt/fx_stream.h"
-#include "core/fxcrt/fx_string.h"
#include "core/fxcrt/retain_ptr.h"
#include "core/fxcrt/tree_node.h"
@@ -28,13 +27,10 @@ class CFX_XMLNode : public TreeNode<CFX_XMLNode> {
virtual Type GetType() const = 0;
virtual CFX_XMLNode* Clone(CFX_XMLDocument* doc) = 0;
- virtual void Save(const RetainPtr<IFX_SeekableWriteStream>& pXMLStream) = 0;
+ virtual void Save(const RetainPtr<IFX_RetainableWriteStream>& pXMLStream) = 0;
CFX_XMLNode* GetRoot();
void InsertChildNode(CFX_XMLNode* pNode, int32_t index);
-
- protected:
- WideString EncodeEntities(const WideString& value);
};
#endif // CORE_FXCRT_XML_CFX_XMLNODE_H_
diff --git a/core/fxcrt/xml/cfx_xmlnode_unittest.cpp b/core/fxcrt/xml/cfx_xmlnode_unittest.cpp
index c879cfd73..ad075793d 100644
--- a/core/fxcrt/xml/cfx_xmlnode_unittest.cpp
+++ b/core/fxcrt/xml/cfx_xmlnode_unittest.cpp
@@ -1,4 +1,4 @@
-// Copyright 2018 PDFium Authors. All rights reserved.
+// Copyright 2018 The PDFium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -36,7 +36,7 @@ TEST(CFX_XMLNodeTest, GetParent) {
node1.AppendLastChild(&node2);
node2.AppendLastChild(&node3);
- EXPECT_EQ(nullptr, node1.GetParent());
+ EXPECT_FALSE(node1.GetParent());
EXPECT_EQ(&node1, node2.GetParent());
EXPECT_EQ(&node2, node3.GetParent());
}
diff --git a/core/fxcrt/xml/cfx_xmlparser.cpp b/core/fxcrt/xml/cfx_xmlparser.cpp
index 9393bbdc9..a6f371f3b 100644
--- a/core/fxcrt/xml/cfx_xmlparser.cpp
+++ b/core/fxcrt/xml/cfx_xmlparser.cpp
@@ -1,4 +1,4 @@
-// Copyright 2016 PDFium Authors. All rights reserved.
+// Copyright 2016 The PDFium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -6,13 +6,15 @@
#include "core/fxcrt/xml/cfx_xmlparser.h"
+#include <stdint.h>
+
#include <algorithm>
-#include <cwctype>
#include <iterator>
#include <stack>
#include <utility>
#include "core/fxcrt/cfx_seekablestreamproxy.h"
+#include "core/fxcrt/data_vector.h"
#include "core/fxcrt/fx_codepage.h"
#include "core/fxcrt/fx_extension.h"
#include "core/fxcrt/fx_safe_types.h"
@@ -22,7 +24,8 @@
#include "core/fxcrt/xml/cfx_xmlinstruction.h"
#include "core/fxcrt/xml/cfx_xmlnode.h"
#include "core/fxcrt/xml/cfx_xmltext.h"
-#include "third_party/base/ptr_util.h"
+#include "third_party/base/check.h"
+#include "third_party/base/notreached.h"
namespace {
@@ -39,7 +42,7 @@ struct FX_XMLNAMECHAR {
bool bStartChar;
};
-const FX_XMLNAMECHAR g_XMLNameChars[] = {
+constexpr FX_XMLNAMECHAR kXMLNameChars[] = {
{L'-', L'.', false}, {L'0', L'9', false}, {L':', L':', false},
{L'A', L'Z', true}, {L'_', L'_', true}, {L'a', L'z', true},
{0xB7, 0xB7, false}, {0xC0, 0xD6, true}, {0xD8, 0xF6, true},
@@ -54,20 +57,20 @@ const FX_XMLNAMECHAR g_XMLNameChars[] = {
// static
bool CFX_XMLParser::IsXMLNameChar(wchar_t ch, bool bFirstChar) {
auto* it = std::lower_bound(
- std::begin(g_XMLNameChars), std::end(g_XMLNameChars), ch,
+ std::begin(kXMLNameChars), std::end(kXMLNameChars), ch,
[](const FX_XMLNAMECHAR& arg, wchar_t ch) { return arg.wEnd < ch; });
- return it != std::end(g_XMLNameChars) && ch >= it->wStart &&
+ return it != std::end(kXMLNameChars) && ch >= it->wStart &&
(!bFirstChar || it->bStartChar);
}
CFX_XMLParser::CFX_XMLParser(const RetainPtr<IFX_SeekableReadStream>& pStream) {
- ASSERT(pStream);
+ DCHECK(pStream);
auto proxy = pdfium::MakeRetain<CFX_SeekableStreamProxy>(pStream);
- uint16_t wCodePage = proxy->GetCodePage();
- if (wCodePage != FX_CODEPAGE_UTF16LE && wCodePage != FX_CODEPAGE_UTF16BE &&
- wCodePage != FX_CODEPAGE_UTF8) {
- proxy->SetCodePage(FX_CODEPAGE_UTF8);
+ FX_CodePage wCodePage = proxy->GetCodePage();
+ if (wCodePage != FX_CodePage::kUTF16LE &&
+ wCodePage != FX_CodePage::kUTF16BE && wCodePage != FX_CodePage::kUTF8) {
+ proxy->SetCodePage(FX_CodePage::kUTF8);
}
stream_ = proxy;
@@ -80,7 +83,7 @@ CFX_XMLParser::CFX_XMLParser(const RetainPtr<IFX_SeekableReadStream>& pStream) {
CFX_XMLParser::~CFX_XMLParser() = default;
std::unique_ptr<CFX_XMLDocument> CFX_XMLParser::Parse() {
- auto doc = pdfium::MakeUnique<CFX_XMLDocument>();
+ auto doc = std::make_unique<CFX_XMLDocument>();
current_node_ = doc->GetRoot();
return DoSyntaxParse(doc.get()) ? std::move(doc) : nullptr;
@@ -95,17 +98,16 @@ bool CFX_XMLParser::DoSyntaxParse(CFX_XMLDocument* doc) {
if (!alloc_size_safe.IsValid())
return false;
- FX_FILESIZE current_buffer_idx = 0;
- FX_FILESIZE buffer_size = 0;
+ size_t current_buffer_idx = 0;
+ size_t buffer_size = 0;
- std::vector<wchar_t, FxAllocAllocator<wchar_t>> buffer;
+ DataVector<wchar_t> buffer;
buffer.resize(alloc_size_safe.ValueOrDie());
std::stack<wchar_t> character_to_skip_too_stack;
std::stack<CFX_XMLNode::Type> node_type_stack;
WideString current_attribute_name;
FDE_XmlSyntaxState current_parser_state = FDE_XmlSyntaxState::Text;
- int32_t iCount = 0;
wchar_t current_quote_character = 0;
wchar_t current_character_to_skip_to = 0;
@@ -262,7 +264,7 @@ bool CFX_XMLParser::DoSyntaxParse(CFX_XMLDocument* doc) {
break;
case FDE_XmlSyntaxState::AttriValue:
if (ch == current_quote_character) {
- if (entity_start_ > -1)
+ if (entity_start_.has_value())
return false;
current_quote_character = 0;
@@ -328,7 +330,6 @@ bool CFX_XMLParser::DoSyntaxParse(CFX_XMLDocument* doc) {
}
current_node_ = current_node_->GetParent();
- iCount++;
} else if (!IsXMLWhiteSpace(ch)) {
return false;
}
@@ -470,27 +471,27 @@ bool CFX_XMLParser::DoSyntaxParse(CFX_XMLDocument* doc) {
void CFX_XMLParser::ProcessTextChar(wchar_t character) {
current_text_.push_back(character);
- if (entity_start_ > -1 && character == L';') {
+ if (entity_start_.has_value() && character == L';') {
// Copy the entity out into a string and remove from the vector. When we
// copy the entity we don't want to copy out the & or the ; so we start
// shifted by one and want to copy 2 less characters in total.
- WideString csEntity(current_text_.data() + entity_start_ + 1,
- current_text_.size() - entity_start_ - 2);
- current_text_.erase(current_text_.begin() + entity_start_,
+ WideString csEntity(current_text_.data() + entity_start_.value() + 1,
+ current_text_.size() - entity_start_.value() - 2);
+ current_text_.erase(current_text_.begin() + entity_start_.value(),
current_text_.end());
- int32_t iLen = csEntity.GetLength();
+ size_t iLen = csEntity.GetLength();
if (iLen > 0) {
if (csEntity[0] == L'#') {
uint32_t ch = 0;
if (iLen > 1 && csEntity[1] == L'x') {
- for (int32_t i = 2; i < iLen; i++) {
+ for (size_t i = 2; i < iLen; i++) {
if (!FXSYS_IsHexDigit(csEntity[i]))
break;
ch = (ch << 4) + FXSYS_HexCharToInt(csEntity[i]);
}
} else {
- for (int32_t i = 1; i < iLen; i++) {
+ for (size_t i = 1; i < iLen; i++) {
if (!FXSYS_IsDecimalDigit(csEntity[i]))
break;
ch = ch * 10 + FXSYS_DecimalCharToInt(csEntity[i]);
@@ -503,22 +504,21 @@ void CFX_XMLParser::ProcessTextChar(wchar_t character) {
if (character != 0)
current_text_.push_back(character);
} else {
- if (csEntity.Compare(L"amp") == 0) {
+ if (csEntity == L"amp") {
current_text_.push_back(L'&');
- } else if (csEntity.Compare(L"lt") == 0) {
+ } else if (csEntity == L"lt") {
current_text_.push_back(L'<');
- } else if (csEntity.Compare(L"gt") == 0) {
+ } else if (csEntity == L"gt") {
current_text_.push_back(L'>');
- } else if (csEntity.Compare(L"apos") == 0) {
+ } else if (csEntity == L"apos") {
current_text_.push_back(L'\'');
- } else if (csEntity.Compare(L"quot") == 0) {
+ } else if (csEntity == L"quot") {
current_text_.push_back(L'"');
}
}
}
-
- entity_start_ = -1;
- } else if (entity_start_ < 0 && character == L'&') {
+ entity_start_ = absl::nullopt;
+ } else if (!entity_start_.has_value() && character == L'&') {
entity_start_ = current_text_.size() - 1;
}
}
@@ -535,7 +535,7 @@ void CFX_XMLParser::ProcessTargetData() {
WideString CFX_XMLParser::GetTextData() {
WideString ret(current_text_.data(), current_text_.size());
- entity_start_ = -1;
+ entity_start_ = absl::nullopt;
current_text_.clear();
current_text_.reserve(kCurrentTextReserve);
return ret;
diff --git a/core/fxcrt/xml/cfx_xmlparser.h b/core/fxcrt/xml/cfx_xmlparser.h
index ef171c663..7a30b7c7f 100644
--- a/core/fxcrt/xml/cfx_xmlparser.h
+++ b/core/fxcrt/xml/cfx_xmlparser.h
@@ -1,4 +1,4 @@
-// Copyright 2016 PDFium Authors. All rights reserved.
+// Copyright 2016 The PDFium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -8,15 +8,14 @@
#define CORE_FXCRT_XML_CFX_XMLPARSER_H_
#include <memory>
-#include <vector>
-#include "core/fxcrt/fx_memory_wrappers.h"
-#include "core/fxcrt/fx_string.h"
+#include "core/fxcrt/data_vector.h"
#include "core/fxcrt/retain_ptr.h"
+#include "core/fxcrt/widestring.h"
+#include "third_party/abseil-cpp/absl/types/optional.h"
class CFX_SeekableStreamProxy;
class CFX_XMLDocument;
-class CFX_XMLElement;
class CFX_XMLNode;
class IFX_SeekableReadStream;
@@ -56,9 +55,9 @@ class CFX_XMLParser final {
CFX_XMLNode* current_node_ = nullptr;
RetainPtr<CFX_SeekableStreamProxy> stream_;
- std::vector<wchar_t, FxAllocAllocator<wchar_t>> current_text_;
+ DataVector<wchar_t> current_text_;
size_t xml_plane_size_ = 1024;
- int32_t entity_start_ = -1;
+ absl::optional<size_t> entity_start_;
};
#endif // CORE_FXCRT_XML_CFX_XMLPARSER_H_
diff --git a/core/fxcrt/xml/cfx_xmlparser_unittest.cpp b/core/fxcrt/xml/cfx_xmlparser_unittest.cpp
index a1fa8f30a..c692a0b9d 100644
--- a/core/fxcrt/xml/cfx_xmlparser_unittest.cpp
+++ b/core/fxcrt/xml/cfx_xmlparser_unittest.cpp
@@ -1,4 +1,4 @@
-// Copyright 2016 PDFium Authors. All rights reserved.
+// Copyright 2016 The PDFium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -6,7 +6,7 @@
#include <memory>
-#include "core/fxcrt/cfx_readonlymemorystream.h"
+#include "core/fxcrt/cfx_read_only_span_stream.h"
#include "core/fxcrt/fx_codepage.h"
#include "core/fxcrt/xml/cfx_xmldocument.h"
#include "core/fxcrt/xml/cfx_xmlelement.h"
@@ -17,7 +17,7 @@ class CFX_XMLParserTest : public testing::Test {
public:
std::unique_ptr<CFX_XMLDocument> Parse(pdfium::span<const char> input) {
CFX_XMLParser parser(
- pdfium::MakeRetain<CFX_ReadOnlyMemoryStream>(pdfium::as_bytes(input)));
+ pdfium::MakeRetain<CFX_ReadOnlySpanStream>(pdfium::as_bytes(input)));
return parser.Parse();
}
};
@@ -290,6 +290,27 @@ TEST_F(CFX_XMLParserTest, IsXMLNameChar) {
EXPECT_FALSE(CFX_XMLParser::IsXMLNameChar(L'-', true));
EXPECT_TRUE(CFX_XMLParser::IsXMLNameChar(L'-', false));
+ EXPECT_FALSE(CFX_XMLParser::IsXMLNameChar(L'.', true));
+ EXPECT_TRUE(CFX_XMLParser::IsXMLNameChar(L'.', false));
+
+ EXPECT_FALSE(CFX_XMLParser::IsXMLNameChar(L'0', true));
+ EXPECT_TRUE(CFX_XMLParser::IsXMLNameChar(L'0', false));
+
+ EXPECT_TRUE(CFX_XMLParser::IsXMLNameChar(L'a', true));
+ EXPECT_TRUE(CFX_XMLParser::IsXMLNameChar(L'a', false));
+
+ EXPECT_TRUE(CFX_XMLParser::IsXMLNameChar(L'A', true));
+ EXPECT_TRUE(CFX_XMLParser::IsXMLNameChar(L'A', false));
+
+ EXPECT_FALSE(CFX_XMLParser::IsXMLNameChar(L'(', false));
+ EXPECT_FALSE(CFX_XMLParser::IsXMLNameChar(L'(', true));
+ EXPECT_FALSE(CFX_XMLParser::IsXMLNameChar(L')', false));
+ EXPECT_FALSE(CFX_XMLParser::IsXMLNameChar(L')', true));
+ EXPECT_FALSE(CFX_XMLParser::IsXMLNameChar(L'[', false));
+ EXPECT_FALSE(CFX_XMLParser::IsXMLNameChar(L'[', true));
+ EXPECT_FALSE(CFX_XMLParser::IsXMLNameChar(L']', false));
+ EXPECT_FALSE(CFX_XMLParser::IsXMLNameChar(L']', true));
+
EXPECT_FALSE(CFX_XMLParser::IsXMLNameChar(0x2069, true));
EXPECT_TRUE(CFX_XMLParser::IsXMLNameChar(0x2070, true));
EXPECT_TRUE(CFX_XMLParser::IsXMLNameChar(0x2073, true));
diff --git a/core/fxcrt/xml/cfx_xmltext.cpp b/core/fxcrt/xml/cfx_xmltext.cpp
index 67c35a56f..bfcf36884 100644
--- a/core/fxcrt/xml/cfx_xmltext.cpp
+++ b/core/fxcrt/xml/cfx_xmltext.cpp
@@ -1,4 +1,4 @@
-// Copyright 2017 PDFium Authors. All rights reserved.
+// Copyright 2017 The PDFium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -20,6 +20,6 @@ CFX_XMLNode* CFX_XMLText::Clone(CFX_XMLDocument* doc) {
return doc->CreateNode<CFX_XMLText>(text_);
}
-void CFX_XMLText::Save(const RetainPtr<IFX_SeekableWriteStream>& pXMLStream) {
- pXMLStream->WriteString(EncodeEntities(GetText()).ToUTF8().AsStringView());
+void CFX_XMLText::Save(const RetainPtr<IFX_RetainableWriteStream>& pXMLStream) {
+ pXMLStream->WriteString(GetText().EncodeEntities().ToUTF8().AsStringView());
}
diff --git a/core/fxcrt/xml/cfx_xmltext.h b/core/fxcrt/xml/cfx_xmltext.h
index 72ca24238..096801a0a 100644
--- a/core/fxcrt/xml/cfx_xmltext.h
+++ b/core/fxcrt/xml/cfx_xmltext.h
@@ -1,4 +1,4 @@
-// Copyright 2017 PDFium Authors. All rights reserved.
+// Copyright 2017 The PDFium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -7,7 +7,7 @@
#ifndef CORE_FXCRT_XML_CFX_XMLTEXT_H_
#define CORE_FXCRT_XML_CFX_XMLTEXT_H_
-#include "core/fxcrt/fx_string.h"
+#include "core/fxcrt/widestring.h"
#include "core/fxcrt/xml/cfx_xmlnode.h"
class CFX_XMLDocument;
@@ -20,7 +20,7 @@ class CFX_XMLText : public CFX_XMLNode {
// CFX_XMLNode
Type GetType() const override;
CFX_XMLNode* Clone(CFX_XMLDocument* doc) override;
- void Save(const RetainPtr<IFX_SeekableWriteStream>& pXMLStream) override;
+ void Save(const RetainPtr<IFX_RetainableWriteStream>& pXMLStream) override;
const WideString& GetText() const { return text_; }
void SetText(const WideString& wsText) { text_ = wsText; }
diff --git a/core/fxcrt/xml/cfx_xmltext_unittest.cpp b/core/fxcrt/xml/cfx_xmltext_unittest.cpp
index 0df003a30..55e879c7d 100644
--- a/core/fxcrt/xml/cfx_xmltext_unittest.cpp
+++ b/core/fxcrt/xml/cfx_xmltext_unittest.cpp
@@ -1,4 +1,4 @@
-// Copyright 2018 PDFium Authors. All rights reserved.
+// Copyright 2018 The PDFium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.