summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authorDan Sinclair <dsinclair@chromium.org>2017-08-30 15:46:58 -0400
committerChromium commit bot <commit-bot@chromium.org>2017-08-30 20:09:37 +0000
commitc2f0789bf90d8f3656abde8da8371e8975f7084e (patch)
treee5812a23a7c59d52ad161a40b6d886449509f5b9 /core
parentfd70d79ca67ac87dd95ab23d548b1fcb879ad259 (diff)
downloadpdfium-c2f0789bf90d8f3656abde8da8371e8975f7084e.tar.xz
Move CFX_UTF8Encoder out of fx_basic
The CFX_UTF8Encoder is only used in FX_UTF8Encode(). This CL moves the class to the anonymous namespace with that method. The unused AppendStr method has been removed. Change-Id: Ie514686c4b4489bb0b0df83b7eeec14bb1876fcd Reviewed-on: https://pdfium-review.googlesource.com/12410 Reviewed-by: Tom Sepez <tsepez@chromium.org> Commit-Queue: dsinclair <dsinclair@chromium.org>
Diffstat (limited to 'core')
-rw-r--r--core/fxcrt/fx_basic.h16
-rw-r--r--core/fxcrt/fx_basic_utf.cpp97
2 files changed, 53 insertions, 60 deletions
diff --git a/core/fxcrt/fx_basic.h b/core/fxcrt/fx_basic.h
index 8e3312d365..dcbb846196 100644
--- a/core/fxcrt/fx_basic.h
+++ b/core/fxcrt/fx_basic.h
@@ -103,22 +103,6 @@ class CFX_UTF8Decoder {
CFX_WideTextBuf m_Buffer;
};
-class CFX_UTF8Encoder {
- public:
- CFX_UTF8Encoder();
- ~CFX_UTF8Encoder();
-
- void Input(wchar_t unicode);
- void AppendStr(const CFX_ByteStringC& str);
-
- // The data returned by GetResult() is invalidated when this is modified by
- // appending any data.
- CFX_ByteStringC GetResult() const;
-
- private:
- std::vector<uint8_t> 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 084553b671..1bcae61fe9 100644
--- a/core/fxcrt/fx_basic_utf.cpp
+++ b/core/fxcrt/fx_basic_utf.cpp
@@ -6,6 +6,59 @@
#include "core/fxcrt/fx_basic.h"
+#include <vector>
+
+namespace {
+
+class CFX_UTF8Encoder {
+ public:
+ CFX_UTF8Encoder() {}
+ ~CFX_UTF8Encoder() {}
+
+ void Input(wchar_t unicodeAsWchar) {
+ uint32_t unicode = static_cast<uint32_t>(unicodeAsWchar);
+ if (unicode < 0x80) {
+ m_Buffer.push_back(unicode);
+ } else {
+ if (unicode >= 0x80000000)
+ return;
+
+ int nbytes = 0;
+ if (unicode < 0x800)
+ nbytes = 2;
+ else if (unicode < 0x10000)
+ nbytes = 3;
+ else if (unicode < 0x200000)
+ nbytes = 4;
+ else if (unicode < 0x4000000)
+ nbytes = 5;
+ else
+ nbytes = 6;
+
+ static uint8_t prefix[] = {0xc0, 0xe0, 0xf0, 0xf8, 0xfc};
+ int order = 1 << ((nbytes - 1) * 6);
+ int code = unicodeAsWchar;
+ m_Buffer.push_back(prefix[nbytes - 2] | (code / order));
+ for (int i = 0; i < nbytes - 1; i++) {
+ code = code % order;
+ order >>= 6;
+ m_Buffer.push_back(0x80 | (code / order));
+ }
+ }
+ }
+
+ // The data returned by GetResult() is invalidated when this is modified by
+ // appending any data.
+ CFX_ByteStringC GetResult() const {
+ return CFX_ByteStringC(m_Buffer.data(), m_Buffer.size());
+ }
+
+ private:
+ std::vector<uint8_t> m_Buffer;
+};
+
+} // namespace
+
void CFX_UTF8Decoder::Clear() {
m_Buffer.Clear();
m_PendingBytes = 0;
@@ -46,50 +99,6 @@ void CFX_UTF8Decoder::Input(uint8_t byte) {
}
}
-CFX_UTF8Encoder::CFX_UTF8Encoder() {}
-
-CFX_UTF8Encoder::~CFX_UTF8Encoder() {}
-
-void CFX_UTF8Encoder::Input(wchar_t unicodeAsWchar) {
- uint32_t unicode = static_cast<uint32_t>(unicodeAsWchar);
- if (unicode < 0x80) {
- m_Buffer.push_back(unicode);
- } else {
- if (unicode >= 0x80000000) {
- return;
- }
- int nbytes = 0;
- if (unicode < 0x800) {
- nbytes = 2;
- } else if (unicode < 0x10000) {
- nbytes = 3;
- } else if (unicode < 0x200000) {
- nbytes = 4;
- } else if (unicode < 0x4000000) {
- nbytes = 5;
- } else {
- nbytes = 6;
- }
- static uint8_t prefix[] = {0xc0, 0xe0, 0xf0, 0xf8, 0xfc};
- int order = 1 << ((nbytes - 1) * 6);
- int code = unicodeAsWchar;
- m_Buffer.push_back(prefix[nbytes - 2] | (code / order));
- for (int i = 0; i < nbytes - 1; i++) {
- code = code % order;
- order >>= 6;
- m_Buffer.push_back(0x80 | (code / order));
- }
- }
-}
-
-void CFX_UTF8Encoder::AppendStr(const CFX_ByteStringC& str) {
- m_Buffer.insert(m_Buffer.end(), str.begin(), str.end());
-}
-
-CFX_ByteStringC CFX_UTF8Encoder::GetResult() const {
- return CFX_ByteStringC(m_Buffer.data(), m_Buffer.size());
-}
-
CFX_ByteString FX_UTF8Encode(const CFX_WideStringC& wsStr) {
FX_STRSIZE len = wsStr.GetLength();
const wchar_t* pStr = wsStr.unterminated_c_str();