aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPiotr Pawliczek <pawliczek@google.com>2024-02-14 22:38:16 +0000
committerAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>2024-02-14 22:38:16 +0000
commit74b1ec3457a8c6ebcecfa8daf7a0e7583bdf475d (patch)
treebe7d8757485a9617fc87c400bf63e92722adec65
parentbe97bdaaebb7eb6181b73d116f9532415bd5c93f (diff)
parent0e5be4109701ac0af3aad29cf840eb91695ec493 (diff)
downloadlibcppbor-74b1ec3457a8c6ebcecfa8daf7a0e7583bdf475d.tar.gz
Revert "ViewBstr: replace std::string_view<uint8_t> with std::span" am: 0e5be41097
Original change: https://android-review.googlesource.com/c/platform/system/libcppbor/+/2962680 Change-Id: I14180b5f66cd550270a5737392997058940c300d Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
-rw-r--r--include/cppbor/cppbor.h16
-rw-r--r--tests/cppbor_test.cpp11
2 files changed, 10 insertions, 17 deletions
diff --git a/include/cppbor/cppbor.h b/include/cppbor/cppbor.h
index 995392d..f7a2af0 100644
--- a/include/cppbor/cppbor.h
+++ b/include/cppbor/cppbor.h
@@ -18,12 +18,10 @@
#include <cassert>
#include <cstdint>
-#include <cstring>
#include <functional>
#include <iterator>
#include <memory>
#include <numeric>
-#include <span>
#include <string>
#include <string_view>
#include <vector>
@@ -442,7 +440,7 @@ class Bstr : public Item {
};
/**
- * ViewBstr is a read-only version of Bstr backed by std::span
+ * ViewBstr is a read-only version of Bstr backed by std::string_view
*/
class ViewBstr : public Item {
public:
@@ -451,8 +449,8 @@ class ViewBstr : public Item {
// Construct an empty ViewBstr
explicit ViewBstr() {}
- // Construct from a span of uint8_t values
- explicit ViewBstr(std::span<const uint8_t> v) : mView(std::move(v)) {}
+ // Construct from a string_view of uint8_t values
+ explicit ViewBstr(std::basic_string_view<uint8_t> v) : mView(std::move(v)) {}
// Construct from a string_view
explicit ViewBstr(std::string_view v)
@@ -468,9 +466,7 @@ class ViewBstr : public Item {
ViewBstr(const uint8_t* begin, const uint8_t* end)
: mView(begin, std::distance(begin, end)) {}
- bool operator==(const ViewBstr& other) const& {
- return std::equal(mView.begin(), mView.end(), other.mView.begin(), other.mView.end());
- }
+ bool operator==(const ViewBstr& other) const& { return mView == other.mView; }
MajorType type() const override { return kMajorType; }
using Item::asViewBstr;
@@ -483,14 +479,14 @@ class ViewBstr : public Item {
encodeValue(encodeCallback);
}
- const std::span<const uint8_t>& view() const { return mView; }
+ const std::basic_string_view<uint8_t>& view() const { return mView; }
std::unique_ptr<Item> clone() const override { return std::make_unique<ViewBstr>(mView); }
private:
void encodeValue(EncodeCallback encodeCallback) const;
- std::span<const uint8_t> mView;
+ std::basic_string_view<uint8_t> mView;
};
/**
diff --git a/tests/cppbor_test.cpp b/tests/cppbor_test.cpp
index a75acc8..aaa8bc5 100644
--- a/tests/cppbor_test.cpp
+++ b/tests/cppbor_test.cpp
@@ -969,8 +969,8 @@ TEST(ConvertTest, ViewTstr) {
TEST(ConvertTest, ViewBstr) {
array<uint8_t, 3> vec{0x23, 0x24, 0x22};
- span<const uint8_t> view(vec.data(), vec.size());
- unique_ptr<Item> item = details::makeItem(ViewBstr(view));
+ basic_string_view<uint8_t> sv(vec.data(), vec.size());
+ unique_ptr<Item> item = details::makeItem(ViewBstr(sv));
EXPECT_EQ(BSTR, item->type());
EXPECT_EQ(nullptr, item->asInt());
@@ -986,10 +986,7 @@ TEST(ConvertTest, ViewBstr) {
EXPECT_EQ(nullptr, item->asViewTstr());
EXPECT_NE(nullptr, item->asViewBstr());
- auto toVec = [](span<const uint8_t> view) {
- return std::vector<uint8_t>(view.begin(), view.end());
- };
- EXPECT_EQ(toVec(view), toVec(item->asViewBstr()->view()));
+ EXPECT_EQ(sv, item->asViewBstr()->view());
}
TEST(CloningTest, Uint) {
@@ -1114,7 +1111,7 @@ TEST(CloningTest, ViewTstr) {
TEST(CloningTest, ViewBstr) {
array<uint8_t, 5> vec{1, 2, 3, 255, 0};
- span<const uint8_t> sv(vec.data(), vec.size());
+ basic_string_view<uint8_t> sv(vec.data(), vec.size());
ViewBstr item(sv);
auto clone = item.clone();
EXPECT_EQ(clone->type(), BSTR);