diff options
author | Dan Sinclair <dsinclair@chromium.org> | 2017-08-30 16:13:01 -0400 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2017-08-30 20:47:28 +0000 |
commit | 5624fe39db570f5ad0fab80cf6314e95e4397698 (patch) | |
tree | fd662cadd3d77d7fb286abe33d0ff653773a5136 /core/fxcrt/cfx_utf8decoder.cpp | |
parent | c2f0789bf90d8f3656abde8da8371e8975f7084e (diff) | |
download | pdfium-5624fe39db570f5ad0fab80cf6314e95e4397698.tar.xz |
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 <tsepez@chromium.org>
Commit-Queue: dsinclair <dsinclair@chromium.org>
Diffstat (limited to 'core/fxcrt/cfx_utf8decoder.cpp')
-rw-r--r-- | core/fxcrt/cfx_utf8decoder.cpp | 47 |
1 files changed, 47 insertions, 0 deletions
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; + } +} |