diff --git a/include/crc32c/crc32c.h b/include/crc32c/crc32c.h index e8a7817..3e52805 100644 --- a/include/crc32c/crc32c.h +++ b/include/crc32c/crc32c.h @@ -11,7 +11,6 @@ #include #include -#include #else /* !defined(__cplusplus) */ @@ -59,30 +58,35 @@ inline uint32_t Crc32c(const char* data, size_t count) { return Extend(0, reinterpret_cast(data), count); } -// Computes the CRC32C of the string's content. -inline uint32_t Crc32c(const std::string& string) { - return Crc32c(reinterpret_cast(string.data()), - string.size()); -} - } // namespace crc32c -#if __cplusplus > 201402L -#if __has_include() -#include +#if __cplusplus > 201402L && __has_include() +#include namespace crc32c { // Computes the CRC32C of the bytes in the string_view. -inline uint32_t Crc32c(const std::string_view& string_view) { +inline uint32_t Crc32c(std::string_view string_view) { return Crc32c(reinterpret_cast(string_view.data()), string_view.size()); } } // namespace crc32c -#endif // __has_include() -#endif // __cplusplus > 201402L +#else + +#include + +namespace crc32c { + +// Computes the CRC32C of the string's content. +inline uint32_t Crc32c(const std::string& string) { + return Crc32c(reinterpret_cast(string.data()), string.size()); +} + +} // namespace crc32c + +#endif // __cplusplus > 201402L && __has_include() #endif /* defined(__cplusplus) */ diff --git a/src/crc32c_unittest.cc b/src/crc32c_unittest.cc index d6c6af6..bcdf4a0 100644 --- a/src/crc32c_unittest.cc +++ b/src/crc32c_unittest.cc @@ -119,6 +119,8 @@ TEST(CRC32CTest, Crc32cStdStringView) { for (size_t i = 0; i < 32; ++i) buf[i] = static_cast(31 - i); EXPECT_EQ(static_cast(0x113fdb5c), crc32c::Crc32c(view)); + + EXPECT_EQ(static_cast(0x691daa2f), crc32c::Crc32c("Hello World")); } #endif // __has_include()