summaryrefslogtreecommitdiff
path: root/core/fxcrt/fx_basic_utf.cpp
diff options
context:
space:
mode:
authorDan Sinclair <dsinclair@chromium.org>2017-08-31 15:50:25 -0400
committerChromium commit bot <commit-bot@chromium.org>2017-08-31 20:01:56 +0000
commit0872b04ea41ba6706e42b28f632ab190bc77dede (patch)
treeb6bf5114395046b79cbe4e20dab61fd05edc1239 /core/fxcrt/fx_basic_utf.cpp
parentce9ad1bee792856c2d9e940ecffff97145e18d32 (diff)
downloadpdfium-0872b04ea41ba6706e42b28f632ab190bc77dede.tar.xz
Move methods string methods to fx_string.cpp
This CL creates an fx_string.cpp and moves any methods defined in fx_string.h into the .cpp file. Change-Id: I64c310b9be6d8f4c3be633a22884023c0b16fc1b Reviewed-on: https://pdfium-review.googlesource.com/12671 Reviewed-by: Tom Sepez <tsepez@chromium.org> Commit-Queue: dsinclair <dsinclair@chromium.org>
Diffstat (limited to 'core/fxcrt/fx_basic_utf.cpp')
-rw-r--r--core/fxcrt/fx_basic_utf.cpp70
1 files changed, 0 insertions, 70 deletions
diff --git a/core/fxcrt/fx_basic_utf.cpp b/core/fxcrt/fx_basic_utf.cpp
deleted file mode 100644
index e0b87479f2..0000000000
--- a/core/fxcrt/fx_basic_utf.cpp
+++ /dev/null
@@ -1,70 +0,0 @@
-// Copyright 2014 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 <vector>
-
-#include "core/fxcrt/fx_string.h"
-
-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
-
-CFX_ByteString FX_UTF8Encode(const CFX_WideStringC& wsStr) {
- FX_STRSIZE len = wsStr.GetLength();
- const wchar_t* pStr = wsStr.unterminated_c_str();
- CFX_UTF8Encoder encoder;
- while (len-- > 0)
- encoder.Input(*pStr++);
-
- return CFX_ByteString(encoder.GetResult());
-}