From 5624fe39db570f5ad0fab80cf6314e95e4397698 Mon Sep 17 00:00:00 2001 From: Dan Sinclair Date: Wed, 30 Aug 2017 16:13:01 -0400 Subject: Move CFX_UTF8Decoder out of fx_basic This CL moves CFX_UTF8Decoder out of fx_basic and includes where needed. Change-Id: I1a093a8a77bbefcc90fbb2f81b1da65bfc0512bf Reviewed-on: https://pdfium-review.googlesource.com/12411 Reviewed-by: Tom Sepez Commit-Queue: dsinclair --- BUILD.gn | 2 ++ core/fxcrt/cfx_bytestring.cpp | 1 + core/fxcrt/cfx_utf8decoder.cpp | 47 ++++++++++++++++++++++++++++++++++++++++++ core/fxcrt/cfx_utf8decoder.h | 28 +++++++++++++++++++++++++ core/fxcrt/cfx_widestring.cpp | 1 + core/fxcrt/fx_basic.h | 16 -------------- core/fxcrt/fx_basic_utf.cpp | 40 ----------------------------------- core/fxcrt/xml/cxml_parser.cpp | 1 + 8 files changed, 80 insertions(+), 56 deletions(-) create mode 100644 core/fxcrt/cfx_utf8decoder.cpp create mode 100644 core/fxcrt/cfx_utf8decoder.h diff --git a/BUILD.gn b/BUILD.gn index 0f8ddcd775..51480ed043 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -820,6 +820,8 @@ static_library("fxcrt") { "core/fxcrt/cfx_string_data_template.h", "core/fxcrt/cfx_string_pool_template.h", "core/fxcrt/cfx_unowned_ptr.h", + "core/fxcrt/cfx_utf8decoder.cpp", + "core/fxcrt/cfx_utf8decoder.h", "core/fxcrt/cfx_weak_ptr.h", "core/fxcrt/cfx_widestring.cpp", "core/fxcrt/cfx_widestring.h", diff --git a/core/fxcrt/cfx_bytestring.cpp b/core/fxcrt/cfx_bytestring.cpp index 13b6673c70..7a738277cf 100644 --- a/core/fxcrt/cfx_bytestring.cpp +++ b/core/fxcrt/cfx_bytestring.cpp @@ -13,6 +13,7 @@ #include #include "core/fxcrt/cfx_string_pool_template.h" +#include "core/fxcrt/cfx_utf8decoder.h" #include "core/fxcrt/fx_codepage.h" #include "core/fxcrt/fx_extension.h" #include "core/fxcrt/fx_safe_types.h" diff --git a/core/fxcrt/cfx_utf8decoder.cpp b/core/fxcrt/cfx_utf8decoder.cpp new file mode 100644 index 0000000000..bee5e16da4 --- /dev/null +++ b/core/fxcrt/cfx_utf8decoder.cpp @@ -0,0 +1,47 @@ +// Copyright 2017 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#include "core/fxcrt/cfx_utf8decoder.h" + +void CFX_UTF8Decoder::Clear() { + m_Buffer.Clear(); + m_PendingBytes = 0; +} + +void CFX_UTF8Decoder::AppendCodePoint(uint32_t ch) { + m_Buffer.AppendChar(static_cast(ch)); +} + +void CFX_UTF8Decoder::Input(uint8_t byte) { + if (byte < 0x80) { + m_PendingBytes = 0; + m_Buffer.AppendChar(byte); + } else if (byte < 0xc0) { + if (m_PendingBytes == 0) { + return; + } + m_PendingBytes--; + m_PendingChar |= (byte & 0x3f) << (m_PendingBytes * 6); + if (m_PendingBytes == 0) { + AppendCodePoint(m_PendingChar); + } + } else if (byte < 0xe0) { + m_PendingBytes = 1; + m_PendingChar = (byte & 0x1f) << 6; + } else if (byte < 0xf0) { + m_PendingBytes = 2; + m_PendingChar = (byte & 0x0f) << 12; + } else if (byte < 0xf8) { + m_PendingBytes = 3; + m_PendingChar = (byte & 0x07) << 18; + } else if (byte < 0xfc) { + m_PendingBytes = 4; + m_PendingChar = (byte & 0x03) << 24; + } else if (byte < 0xfe) { + m_PendingBytes = 5; + m_PendingChar = (byte & 0x01) << 30; + } +} diff --git a/core/fxcrt/cfx_utf8decoder.h b/core/fxcrt/cfx_utf8decoder.h new file mode 100644 index 0000000000..50c2a3966d --- /dev/null +++ b/core/fxcrt/cfx_utf8decoder.h @@ -0,0 +1,28 @@ +// Copyright 2017 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#ifndef CORE_FXCRT_CFX_UTF8DECODER_H_ +#define CORE_FXCRT_CFX_UTF8DECODER_H_ + +#include "core/fxcrt/fx_basic.h" + +class CFX_UTF8Decoder { + public: + CFX_UTF8Decoder() { m_PendingBytes = 0; } + + void Clear(); + void Input(uint8_t byte); + void AppendCodePoint(uint32_t ch); + void ClearStatus() { m_PendingBytes = 0; } + CFX_WideStringC GetResult() const { return m_Buffer.AsStringC(); } + + private: + int m_PendingBytes; + uint32_t m_PendingChar; + CFX_WideTextBuf m_Buffer; +}; + +#endif // CORE_FXCRT_CFX_UTF8DECODER_H_ diff --git a/core/fxcrt/cfx_widestring.cpp b/core/fxcrt/cfx_widestring.cpp index 6e4e82d09d..05a4fc3b5e 100644 --- a/core/fxcrt/cfx_widestring.cpp +++ b/core/fxcrt/cfx_widestring.cpp @@ -13,6 +13,7 @@ #include #include "core/fxcrt/cfx_string_pool_template.h" +#include "core/fxcrt/cfx_utf8decoder.h" #include "core/fxcrt/fx_codepage.h" #include "core/fxcrt/fx_extension.h" #include "core/fxcrt/fx_safe_types.h" diff --git a/core/fxcrt/fx_basic.h b/core/fxcrt/fx_basic.h index dcbb846196..6f676696a2 100644 --- a/core/fxcrt/fx_basic.h +++ b/core/fxcrt/fx_basic.h @@ -87,22 +87,6 @@ class CFX_WideTextBuf : public CFX_BinaryBuf { CFX_WideTextBuf& operator<<(const CFX_WideTextBuf& buf); }; -class CFX_UTF8Decoder { - public: - CFX_UTF8Decoder() { m_PendingBytes = 0; } - - void Clear(); - void Input(uint8_t byte); - void AppendCodePoint(uint32_t ch); - void ClearStatus() { m_PendingBytes = 0; } - CFX_WideStringC GetResult() const { return m_Buffer.AsStringC(); } - - private: - int m_PendingBytes; - uint32_t m_PendingChar; - CFX_WideTextBuf m_Buffer; -}; - template class CFX_FixedBufGrow { public: diff --git a/core/fxcrt/fx_basic_utf.cpp b/core/fxcrt/fx_basic_utf.cpp index 1bcae61fe9..8a5587d5c4 100644 --- a/core/fxcrt/fx_basic_utf.cpp +++ b/core/fxcrt/fx_basic_utf.cpp @@ -59,46 +59,6 @@ class CFX_UTF8Encoder { } // namespace -void CFX_UTF8Decoder::Clear() { - m_Buffer.Clear(); - m_PendingBytes = 0; -} - -void CFX_UTF8Decoder::AppendCodePoint(uint32_t ch) { - m_Buffer.AppendChar(static_cast(ch)); -} - -void CFX_UTF8Decoder::Input(uint8_t byte) { - if (byte < 0x80) { - m_PendingBytes = 0; - m_Buffer.AppendChar(byte); - } else if (byte < 0xc0) { - if (m_PendingBytes == 0) { - return; - } - m_PendingBytes--; - m_PendingChar |= (byte & 0x3f) << (m_PendingBytes * 6); - if (m_PendingBytes == 0) { - AppendCodePoint(m_PendingChar); - } - } else if (byte < 0xe0) { - m_PendingBytes = 1; - m_PendingChar = (byte & 0x1f) << 6; - } else if (byte < 0xf0) { - m_PendingBytes = 2; - m_PendingChar = (byte & 0x0f) << 12; - } else if (byte < 0xf8) { - m_PendingBytes = 3; - m_PendingChar = (byte & 0x07) << 18; - } else if (byte < 0xfc) { - m_PendingBytes = 4; - m_PendingChar = (byte & 0x03) << 24; - } else if (byte < 0xfe) { - m_PendingBytes = 5; - m_PendingChar = (byte & 0x01) << 30; - } -} - CFX_ByteString FX_UTF8Encode(const CFX_WideStringC& wsStr) { FX_STRSIZE len = wsStr.GetLength(); const wchar_t* pStr = wsStr.unterminated_c_str(); diff --git a/core/fxcrt/xml/cxml_parser.cpp b/core/fxcrt/xml/cxml_parser.cpp index 18103dfc5e..5e3fca7e79 100644 --- a/core/fxcrt/xml/cxml_parser.cpp +++ b/core/fxcrt/xml/cxml_parser.cpp @@ -11,6 +11,7 @@ #include #include +#include "core/fxcrt/cfx_utf8decoder.h" #include "core/fxcrt/fx_extension.h" #include "core/fxcrt/xml/cxml_content.h" #include "core/fxcrt/xml/cxml_element.h" -- cgit v1.2.3