for (std::size_t i = 0; i < len; i++) {
const unsigned char c = src[i];
out[i * 2 + 0] = lut[c >> 4];
- out[i + 2 + 1] = lut[c & 15];
+ out[i * 2 + 1] = lut[c & 15];
}
return out;
}
IPAddressFormatException);
}
+TEST(IPAddressSource, ToHex) {
+ vector<std::uint8_t> data = {{0xff, 0x20, 0x45}};
+ EXPECT_EQ(detail::Bytes::toHex(data.data(), 0), "");
+ EXPECT_EQ(detail::Bytes::toHex(data.data(), 1), "ff");
+ EXPECT_EQ(detail::Bytes::toHex(data.data(), 2), "ff20");
+ EXPECT_EQ(detail::Bytes::toHex(data.data(), 3), "ff2045");
+}
+
// Test toFullyQualified()
TEST(IPAddress, ToFullyQualifiedFb) {
IPAddress ip("2620:0:1cfe:face:b00c::3");