void reserve(size_t size) noexcept;
void clear() noexcept;
+ void resize(size_t size) noexcept; // Note: New bytes will be uninitialized.
+
void insert(const uint8_t* pos,
const uint8_t* first,
const uint8_t* last) noexcept;
- void resize(size_t size) noexcept; // Note: New bytes will be uninitialized.
+ void
+ insert(const uint8_t* pos, const uint8_t* data, const size_t size) noexcept;
+ void insert(const uint8_t* pos, const char* first, const char* last) noexcept;
+ void insert(const uint8_t* pos, const char* data, size_t size) noexcept;
private:
uint8_t* m_data = nullptr;
m_size = 0;
}
+inline void
+Bytes::insert(const uint8_t* pos,
+ const uint8_t* data,
+ const size_t size) noexcept
+{
+ return insert(pos, data, data + size);
+}
+
+inline void
+Bytes::insert(const uint8_t* pos, const char* first, const char* last) noexcept
+{
+ return insert(pos,
+ reinterpret_cast<const uint8_t*>(first),
+ reinterpret_cast<const uint8_t*>(last));
+}
+
+inline void
+Bytes::insert(const uint8_t* pos, const char* data, size_t size) noexcept
+{
+ return insert(pos, data, data + size);
+}
+
} // namespace util
CHECK(bytes2[12] == 'a');
CHECK(bytes2[13] == 'x');
}
+
+ SUBCASE("Insert util::Bytes data and size")
+ {
+ Bytes bytes2;
+
+ bytes2.insert(bytes2.end(), bytes1.data(), bytes1.size());
+ CHECK(bytes2.size() == 3);
+ CHECK(bytes2.capacity() == 3);
+ CHECK(bytes2[0] == 'a');
+ CHECK(bytes2[1] == 'b');
+ CHECK(bytes2[2] == 'c');
+ }
+
+ SUBCASE("Insert const char* first and last")
+ {
+ Bytes bytes2;
+ std::string data("abc");
+
+ bytes2.insert(bytes2.end(), data.data(), data.data() + data.size());
+ CHECK(bytes2.size() == 3);
+ CHECK(bytes2.capacity() == 3);
+ CHECK(bytes2[0] == 'a');
+ CHECK(bytes2[1] == 'b');
+ CHECK(bytes2[2] == 'c');
+ }
+
+ SUBCASE("Insert const char* data and size")
+ {
+ Bytes bytes2;
+ std::string data("abc");
+
+ bytes2.insert(bytes2.end(), data.data(), data.size());
+ CHECK(bytes2.size() == 3);
+ CHECK(bytes2.capacity() == 3);
+ CHECK(bytes2[0] == 'a');
+ CHECK(bytes2[1] == 'b');
+ CHECK(bytes2[2] == 'c');
+ }
}
TEST_CASE("Conversion to span")