summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--BUILD.gn3
-rw-r--r--core/fxcrt/fx_basic_util.cpp40
-rw-r--r--core/fxcrt/fx_extension.cpp32
-rw-r--r--core/fxcrt/fx_extension_unittest.cpp23
-rw-r--r--core/fxcrt/fx_string_unittest.cpp (renamed from core/fxcrt/fx_basic_util_unittest.cpp)27
5 files changed, 58 insertions, 67 deletions
diff --git a/BUILD.gn b/BUILD.gn
index 969a5ff414..97a8fc15b4 100644
--- a/BUILD.gn
+++ b/BUILD.gn
@@ -831,7 +831,6 @@ static_library("fxcrt") {
"core/fxcrt/cfx_widetextbuf.cpp",
"core/fxcrt/cfx_widetextbuf.h",
"core/fxcrt/fx_basic_gcc.cpp",
- "core/fxcrt/fx_basic_util.cpp",
"core/fxcrt/fx_bidi.cpp",
"core/fxcrt/fx_bidi.h",
"core/fxcrt/fx_codepage.h",
@@ -1928,11 +1927,11 @@ test("pdfium_unittests") {
"core/fxcrt/cfx_weak_ptr_unittest.cpp",
"core/fxcrt/cfx_widestring_unittest.cpp",
"core/fxcrt/fx_basic_gcc_unittest.cpp",
- "core/fxcrt/fx_basic_util_unittest.cpp",
"core/fxcrt/fx_bidi_unittest.cpp",
"core/fxcrt/fx_coordinates_unittest.cpp",
"core/fxcrt/fx_extension_unittest.cpp",
"core/fxcrt/fx_memory_unittest.cpp",
+ "core/fxcrt/fx_string_unittest.cpp",
"core/fxcrt/fx_system_unittest.cpp",
"core/fxge/dib/cstretchengine_unittest.cpp",
"fpdfsdk/fpdfdoc_unittest.cpp",
diff --git a/core/fxcrt/fx_basic_util.cpp b/core/fxcrt/fx_basic_util.cpp
deleted file mode 100644
index 704fd18418..0000000000
--- a/core/fxcrt/fx_basic_util.cpp
+++ /dev/null
@@ -1,40 +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 <algorithm>
-
-#include "core/fxcrt/fx_system.h"
-
-uint32_t GetBits32(const uint8_t* pData, int bitpos, int nbits) {
- ASSERT(0 < nbits && nbits <= 32);
- const uint8_t* dataPtr = &pData[bitpos / 8];
- int bitShift;
- int bitMask;
- int dstShift;
- int bitCount = bitpos & 0x07;
- if (nbits < 8 && nbits + bitCount <= 8) {
- bitShift = 8 - nbits - bitCount;
- bitMask = (1 << nbits) - 1;
- dstShift = 0;
- } else {
- bitShift = 0;
- int bitOffset = 8 - bitCount;
- bitMask = (1 << std::min(bitOffset, nbits)) - 1;
- dstShift = nbits - bitOffset;
- }
- uint32_t result =
- static_cast<uint32_t>((*dataPtr++ >> bitShift & bitMask) << dstShift);
- while (dstShift >= 8) {
- dstShift -= 8;
- result |= *dataPtr++ << dstShift;
- }
- if (dstShift > 0) {
- bitShift = 8 - dstShift;
- bitMask = (1 << dstShift) - 1;
- result |= *dataPtr++ >> bitShift & bitMask;
- }
- return result;
-}
diff --git a/core/fxcrt/fx_extension.cpp b/core/fxcrt/fx_extension.cpp
index 10b568ec9e..2d485490ca 100644
--- a/core/fxcrt/fx_extension.cpp
+++ b/core/fxcrt/fx_extension.cpp
@@ -6,6 +6,7 @@
#include "core/fxcrt/fx_extension.h"
+#include <algorithm>
#include <cwctype>
#if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_
@@ -271,3 +272,34 @@ CFX_ByteString FX_GUID_ToString(const FX_GUID* pGUID, bool bSeparator) {
return bsStr;
}
#endif // PDF_ENABLE_XFA
+
+uint32_t GetBits32(const uint8_t* pData, int bitpos, int nbits) {
+ ASSERT(0 < nbits && nbits <= 32);
+ const uint8_t* dataPtr = &pData[bitpos / 8];
+ int bitShift;
+ int bitMask;
+ int dstShift;
+ int bitCount = bitpos & 0x07;
+ if (nbits < 8 && nbits + bitCount <= 8) {
+ bitShift = 8 - nbits - bitCount;
+ bitMask = (1 << nbits) - 1;
+ dstShift = 0;
+ } else {
+ bitShift = 0;
+ int bitOffset = 8 - bitCount;
+ bitMask = (1 << std::min(bitOffset, nbits)) - 1;
+ dstShift = nbits - bitOffset;
+ }
+ uint32_t result =
+ static_cast<uint32_t>((*dataPtr++ >> bitShift & bitMask) << dstShift);
+ while (dstShift >= 8) {
+ dstShift -= 8;
+ result |= *dataPtr++ << dstShift;
+ }
+ if (dstShift > 0) {
+ bitShift = 8 - dstShift;
+ bitMask = (1 << dstShift) - 1;
+ result |= *dataPtr++ >> bitShift & bitMask;
+ }
+ return result;
+}
diff --git a/core/fxcrt/fx_extension_unittest.cpp b/core/fxcrt/fx_extension_unittest.cpp
index 38b66ba2d2..0500a14b6f 100644
--- a/core/fxcrt/fx_extension_unittest.cpp
+++ b/core/fxcrt/fx_extension_unittest.cpp
@@ -5,6 +5,19 @@
#include "core/fxcrt/fx_extension.h"
#include "testing/gtest/include/gtest/gtest.h"
+namespace {
+
+uint32_t ReferenceGetBits32(const uint8_t* pData, int bitpos, int nbits) {
+ int result = 0;
+ for (int i = 0; i < nbits; i++) {
+ if (pData[(bitpos + i) / 8] & (1 << (7 - (bitpos + i) % 8)))
+ result |= 1 << (nbits - i - 1);
+ }
+ return result;
+}
+
+} // namespace
+
TEST(fxcrt, FXSYS_HexCharToInt) {
EXPECT_EQ(10, FXSYS_HexCharToInt('a'));
EXPECT_EQ(10, FXSYS_HexCharToInt('A'));
@@ -89,3 +102,13 @@ TEST(fxcrt, FXSYS_ToUTF16BE) {
EXPECT_EQ(8U, FXSYS_ToUTF16BE(0x2003E, buf));
EXPECT_STREQ("D840DC3E", buf);
}
+
+TEST(fxcrt, GetBits32) {
+ unsigned char data[] = {0xDE, 0x3F, 0xB1, 0x7C, 0x12, 0x9A, 0x04, 0x56};
+ for (int nbits = 1; nbits <= 32; ++nbits) {
+ for (int bitpos = 0; bitpos < (int)sizeof(data) * 8 - nbits; ++bitpos) {
+ EXPECT_EQ(ReferenceGetBits32(data, bitpos, nbits),
+ GetBits32(data, bitpos, nbits));
+ }
+ }
+}
diff --git a/core/fxcrt/fx_basic_util_unittest.cpp b/core/fxcrt/fx_string_unittest.cpp
index 9a130bece4..b311165638 100644
--- a/core/fxcrt/fx_basic_util_unittest.cpp
+++ b/core/fxcrt/fx_string_unittest.cpp
@@ -4,33 +4,10 @@
#include <limits>
-#include "core/fxcrt/fx_extension.h"
+#include "core/fxcrt/fx_string.h"
#include "testing/gtest/include/gtest/gtest.h"
-namespace {
-
-uint32_t ReferenceGetBits32(const uint8_t* pData, int bitpos, int nbits) {
- int result = 0;
- for (int i = 0; i < nbits; i++) {
- if (pData[(bitpos + i) / 8] & (1 << (7 - (bitpos + i) % 8)))
- result |= 1 << (nbits - i - 1);
- }
- return result;
-}
-
-} // namespace
-
-TEST(fxge, GetBits32) {
- unsigned char data[] = {0xDE, 0x3F, 0xB1, 0x7C, 0x12, 0x9A, 0x04, 0x56};
- for (int nbits = 1; nbits <= 32; ++nbits) {
- for (int bitpos = 0; bitpos < (int)sizeof(data) * 8 - nbits; ++bitpos) {
- EXPECT_EQ(ReferenceGetBits32(data, bitpos, nbits),
- GetBits32(data, bitpos, nbits));
- }
- }
-}
-
-TEST(fxcrt, FX_atonum) {
+TEST(fxstring, FX_atonum) {
int i;
EXPECT_TRUE(FX_atonum("10", &i));
EXPECT_EQ(10, i);