diff options
-rw-r--r-- | BUILD.gn | 2 | ||||
-rw-r--r-- | core/fxcrt/cfx_bytestring.cpp | 1 | ||||
-rw-r--r-- | core/fxcrt/cfx_utf8decoder.cpp | 47 | ||||
-rw-r--r-- | core/fxcrt/cfx_utf8decoder.h | 28 | ||||
-rw-r--r-- | core/fxcrt/cfx_widestring.cpp | 1 | ||||
-rw-r--r-- | core/fxcrt/fx_basic.h | 16 | ||||
-rw-r--r-- | core/fxcrt/fx_basic_utf.cpp | 40 | ||||
-rw-r--r-- | core/fxcrt/xml/cxml_parser.cpp | 1 |
8 files changed, 80 insertions, 56 deletions
@@ -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 <string> #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<wchar_t>(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 <cwctype> #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 DataType, int FixedSize> 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<wchar_t>(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 <utility> #include <vector> +#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" |