diff options
author | Abseil Team <absl-team@google.com> | 2023-08-01 14:40:45 -0700 |
---|---|---|
committer | Copybara-Service <copybara-worker@google.com> | 2023-08-01 14:41:35 -0700 |
commit | fc1dcc0f6a6b22f4ef4a30fc2020d4c81ab1b3c5 (patch) | |
tree | b950bdb1c287662cb0a4c1c325a7727d4f740fa2 /absl/crc | |
parent | 5b3b0ed81cb514540c3b9d752d9e01efb64056d2 (diff) | |
download | abseil-fc1dcc0f6a6b22f4ef4a30fc2020d4c81ab1b3c5.tar.gz abseil-fc1dcc0f6a6b22f4ef4a30fc2020d4c81ab1b3c5.tar.bz2 abseil-fc1dcc0f6a6b22f4ef4a30fc2020d4c81ab1b3c5.zip |
Changes absl::crc32c_t insertion operator (<<) to return value as 0-padded hex instead of dec
PiperOrigin-RevId: 552927211
Change-Id: I0375d60a9df4cdfc694fe8d3b3d790f80fc614a1
Diffstat (limited to 'absl/crc')
-rw-r--r-- | absl/crc/BUILD.bazel | 1 | ||||
-rw-r--r-- | absl/crc/CMakeLists.txt | 1 | ||||
-rw-r--r-- | absl/crc/crc32c.h | 3 | ||||
-rw-r--r-- | absl/crc/crc32c_test.cc | 19 |
4 files changed, 23 insertions, 1 deletions
diff --git a/absl/crc/BUILD.bazel b/absl/crc/BUILD.bazel index 1c58f46c..29a9964f 100644 --- a/absl/crc/BUILD.bazel +++ b/absl/crc/BUILD.bazel @@ -93,6 +93,7 @@ cc_library( "//absl/base:endian", "//absl/base:prefetch", "//absl/strings", + "//absl/strings:str_format", ], ) diff --git a/absl/crc/CMakeLists.txt b/absl/crc/CMakeLists.txt index 72ea2094..f49b4b0b 100644 --- a/absl/crc/CMakeLists.txt +++ b/absl/crc/CMakeLists.txt @@ -77,6 +77,7 @@ absl_cc_library( absl::dynamic_annotations absl::endian absl::prefetch + absl::str_format absl::strings ) diff --git a/absl/crc/crc32c.h b/absl/crc/crc32c.h index 79059dc1..69799c8b 100644 --- a/absl/crc/crc32c.h +++ b/absl/crc/crc32c.h @@ -29,6 +29,7 @@ #include <ostream> #include "absl/crc/internal/crc32c_inline.h" +#include "absl/strings/str_format.h" #include "absl/strings/string_view.h" namespace absl { @@ -175,7 +176,7 @@ crc32c_t RemoveCrc32cSuffix(crc32c_t full_string_crc, crc32c_t suffix_crc, // // Streams the CRC32C value `crc` to the stream `os`. inline std::ostream& operator<<(std::ostream& os, crc32c_t crc) { - return os << static_cast<uint32_t>(crc); + return os << absl::StreamFormat("%08x", static_cast<uint32_t>(crc)); } ABSL_NAMESPACE_END diff --git a/absl/crc/crc32c_test.cc b/absl/crc/crc32c_test.cc index 72d422a1..635424aa 100644 --- a/absl/crc/crc32c_test.cc +++ b/absl/crc/crc32c_test.cc @@ -18,6 +18,7 @@ #include <cstddef> #include <cstdint> #include <cstring> +#include <sstream> #include <string> #include "gtest/gtest.h" @@ -191,4 +192,22 @@ TEST(CRC32C, RemoveSuffix) { EXPECT_EQ(absl::RemoveCrc32cSuffix(crc_ab, crc_b, world.size()), crc_a); } + +TEST(CRC32C, InsertionOperator) { + { + std::ostringstream buf; + buf << absl::crc32c_t{0xc99465aa}; + EXPECT_EQ(buf.str(), "c99465aa"); + } + { + std::ostringstream buf; + buf << absl::crc32c_t{0}; + EXPECT_EQ(buf.str(), "00000000"); + } + { + std::ostringstream buf; + buf << absl::crc32c_t{17}; + EXPECT_EQ(buf.str(), "00000011"); + } +} } // namespace |