Skip to content

CXX-3101 Remove workarounds for core::string_view #1268

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@ void example(bsoncxx::array::view arr) {

std::copy_if(
arr.begin(), arr.end(), std::back_inserter(elements), [](const bsoncxx::array::element& e) {
return e.key().compare("0") == 0 || e.type() == bsoncxx::type::k_string;
return e.key() == "0" || e.type() == bsoncxx::type::k_string;
});

EXPECT(elements.size() == 2u);
EXPECT(elements[0].key().compare("0") == 0);
EXPECT(elements[1].key().compare("2") == 0);
EXPECT(elements[0].key() == "0");
EXPECT(elements[1].key() == "2");
}
// [Example]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,16 @@ void example(bsoncxx::array::view arr) {
for (bsoncxx::array::element e : arr) {
switch (e.type()) {
case bsoncxx::type::k_int32:
EXPECT(e.key().compare("0") == 0);
EXPECT(e.key() == "0");
EXPECT(e.get_int32().value == 1);
break;
case bsoncxx::type::k_double:
EXPECT(e.key().compare("1") == 0);
EXPECT(e.key() == "1");
EXPECT(e.get_double().value == 2.0);
break;
case bsoncxx::type::k_string:
EXPECT(e.key().compare("2") == 0);
EXPECT(e.get_string().value.compare("three") == 0);
EXPECT(e.key() == "2");
EXPECT(e.get_string().value == "three");
break;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ void example(bsoncxx::array::view arr) {
auto iter = arr.find(1);

EXPECT(iter != arr.end());
EXPECT(iter->key().compare("1") == 0);
EXPECT(iter->key() == "1");
EXPECT(iter->get_int32().value == 2);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,20 +33,20 @@ void example(bsoncxx::array::view arr) {
{
bsoncxx::array::element e = *iter;

EXPECT(e.key().compare("0") == 0);
EXPECT(e.key() == "0");
EXPECT(e.get_int32().value == 1);
}

++iter;

EXPECT(iter->key().compare("1") == 0);
EXPECT(iter->key() == "1");
EXPECT(iter->get_int32().value == 2);

{
auto iter_copy = iter++;

EXPECT(iter_copy != iter);
EXPECT(iter_copy->key().compare("1") == 0);
EXPECT(iter_copy->key() == "1");
EXPECT(iter_copy->get_int32() == 2);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ void example(bsoncxx::array::view arr) {
{
bsoncxx::array::element e = arr[1];

EXPECT(e.key().compare("1") == 0);
EXPECT(e.key() == "1");
EXPECT(e.get_int32().value == 2);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@ void example(bsoncxx::document::view doc) {
doc.end(),
std::back_inserter(elements),
[](const bsoncxx::document::element& e) {
return e.key().compare("a") == 0 || e.type() == bsoncxx::type::k_string;
return e.key() == "a" || e.type() == bsoncxx::type::k_string;
});

EXPECT(elements.size() == 2u);
EXPECT(elements[0].key().compare("a") == 0);
EXPECT(elements[1].key().compare("c") == 0);
EXPECT(elements[0].key() == "a");
EXPECT(elements[1].key() == "c");
}
// [Example]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,16 @@ void example(bsoncxx::document::view doc) {
for (bsoncxx::document::element e : doc) {
switch (e.type()) {
case bsoncxx::type::k_int32:
EXPECT(e.key().compare("a") == 0);
EXPECT(e.key() == "a");
EXPECT(e.get_int32().value == 1);
break;
case bsoncxx::type::k_double:
EXPECT(e.key().compare("b") == 0);
EXPECT(e.key() == "b");
EXPECT(e.get_double().value == 2.0);
break;
case bsoncxx::type::k_string:
EXPECT(e.key().compare("c") == 0);
EXPECT(e.get_string().value.compare("three") == 0);
EXPECT(e.key() == "c");
EXPECT(e.get_string().value == "three");
break;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ void example(bsoncxx::document::view doc) {
auto iter = doc.find("b");

EXPECT(iter != doc.end());
EXPECT(iter->key().compare("b") == 0);
EXPECT(iter->key() == "b");
EXPECT(iter->get_int32().value == 2);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,20 +33,20 @@ void example(bsoncxx::document::view doc) {
{
bsoncxx::document::element e = *iter;

EXPECT(e.key().compare("a") == 0);
EXPECT(e.key() == "a");
EXPECT(e.get_int32().value == 1);
}

++iter;

EXPECT(iter->key().compare("b") == 0);
EXPECT(iter->key() == "b");
EXPECT(iter->get_int32().value == 2);

{
auto iter_copy = iter++;

EXPECT(iter_copy != iter);
EXPECT(iter_copy->key().compare("b") == 0);
EXPECT(iter_copy->key() == "b");
EXPECT(iter_copy->get_int32() == 2);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ void example(bsoncxx::document::view doc) {
{
bsoncxx::document::element e = doc["b"];

EXPECT(e.key().compare("b") == 0);
EXPECT(e.key() == "b");
EXPECT(e.get_int32().value == 2);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ void example() {

EXPECT(arr[0].get_int32().value == 1);
EXPECT(arr[1].get_double().value == 2.0);
EXPECT(arr[2].get_string().value.compare("three") == 0);
EXPECT(arr[2].get_string().value == "three");
}
// [Example]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ void example() {

EXPECT(arr[0].get_int32().value == 1);
EXPECT(arr[1].get_double().value == 2.0);
EXPECT(arr[2].get_string().value.compare("three") == 0);
EXPECT(arr[2].get_string().value == "three");
}
// [Example]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ void example() {

EXPECT(doc["0"].get_int32().value == 1);
EXPECT(doc["1"].get_double().value == 2.0);
EXPECT(doc["2"].get_string().value.compare("three") == 0);
EXPECT(doc["2"].get_string().value == "three");
}
// [Example]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ void example() {

EXPECT(doc["a"].get_int32().value == 1);
EXPECT(doc["b"].get_double().value == 2.0);
EXPECT(doc["c"].get_string().value.compare("three") == 0);
EXPECT(doc["c"].get_string().value == "three");
}
// [Example]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ namespace {
void example(bsoncxx::array::element e) {
switch (e.type()) {
case bsoncxx::type::k_int32: {
EXPECT(e.key().compare("0") == 0);
EXPECT(e.key() == "0");

bsoncxx::types::b_int32 v = e.get_int32();

Expand All @@ -36,7 +36,7 @@ void example(bsoncxx::array::element e) {
break;
}
case bsoncxx::type::k_double: {
EXPECT(e.key().compare("1") == 0);
EXPECT(e.key() == "1");

bsoncxx::types::b_double v = e.get_double();

Expand All @@ -46,12 +46,12 @@ void example(bsoncxx::array::element e) {
break;
}
case bsoncxx::type::k_string: {
EXPECT(e.key().compare("2") == 0);
EXPECT(e.key() == "2");

bsoncxx::types::b_string v = e.get_string();

EXPECT(v.type_id == bsoncxx::type::k_string);
EXPECT(v.value.compare("three") == 0);
EXPECT(v.value == "three");

break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ namespace {
// [1, 2.0, "three"]
void example(bsoncxx::array::element e) {
if (e.type() == bsoncxx::type::k_int32) {
EXPECT(e.key().compare("0") == 0);
EXPECT(e.key() == "0");

bsoncxx::types::b_int32 v = e.get_int32();

EXPECT(v.type_id == bsoncxx::type::k_int32);
EXPECT(v.value == 1);
} else {
EXPECT(e.key().compare("0") != 0);
EXPECT(e.key() != "0");
}
}
// [Example]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,18 @@ void example(bsoncxx::document::element e) {
bsoncxx::types::b_int64 b{2};

if (e.get_value() == a) {
EXPECT(e.key().compare("a") == 0);
EXPECT(e.key() == "a");
} else if (e.get_value() == b) {
EXPECT(e.key().compare("b") == 0);
EXPECT(e.key() == "b");
}

bsoncxx::types::bson_value::view va{a};
bsoncxx::types::bson_value::view vb{b};

if (e == va) {
EXPECT(e.key().compare("a") == 0);
EXPECT(e.key() == "a");
} else if (e == vb) {
EXPECT(e.key().compare("b") == 0);
EXPECT(e.key() == "b");
}
}
// [Example]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ void example(bsoncxx::document::element e) {
std::int64_t b{2};

if (e.type() == bsoncxx::type::k_int32) {
EXPECT(e.key().compare("a") == 0);
EXPECT(e.key() == "a");
EXPECT(e.get_int32().value == a);
} else if (e.type() == bsoncxx::type::k_int64) {
EXPECT(e.key().compare("b") == 0);
EXPECT(e.key() == "b");
EXPECT(e.get_int64().value == b);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ namespace {
void example(bsoncxx::document::element e) {
switch (e.type()) {
case bsoncxx::type::k_int32: {
EXPECT(e.key().compare("a") == 0);
EXPECT(e.key() == "a");

bsoncxx::types::b_int32 v = e.get_int32();

Expand All @@ -36,7 +36,7 @@ void example(bsoncxx::document::element e) {
break;
}
case bsoncxx::type::k_double: {
EXPECT(e.key().compare("b") == 0);
EXPECT(e.key() == "b");

bsoncxx::types::b_double v = e.get_double();

Expand All @@ -46,12 +46,12 @@ void example(bsoncxx::document::element e) {
break;
}
case bsoncxx::type::k_string: {
EXPECT(e.key().compare("c") == 0);
EXPECT(e.key() == "c");

bsoncxx::types::b_string v = e.get_string();

EXPECT(v.type_id == bsoncxx::type::k_string);
EXPECT(v.value.compare("three") == 0);
EXPECT(v.value == "three");

break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ namespace {
// {"a": 1, "b": 2.0, "c": "three"}
void example(bsoncxx::document::element e) {
if (e.type() == bsoncxx::type::k_int32) {
EXPECT(e.key().compare("a") == 0);
EXPECT(e.key() == "a");

bsoncxx::types::b_int32 v = e.get_int32();

EXPECT(v.type_id == bsoncxx::type::k_int32);
EXPECT(v.value == 1);
} else {
EXPECT(e.key().compare("a") != 0);
EXPECT(e.key() != "a");
}
}
// [Example]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ void example() {
v = v.view().get_array().value[0].get_string(); // Copy: no dangling.

EXPECT(v.view().type() == bsoncxx::type::k_string);
EXPECT(v.view().get_string().value.compare("value") == 0);
EXPECT(v.view().get_string().value == "value");
}
// [Example]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@ void example(bsoncxx::array::element e) {

switch (v.type()) {
case bsoncxx::type::k_int32:
EXPECT(e.key().compare("0") == 0);
EXPECT(e.key() == "0");
EXPECT(v.get_int32() == e.get_int32());
break;
case bsoncxx::type::k_double:
EXPECT(e.key().compare("1") == 0);
EXPECT(e.key() == "1");
EXPECT(v.get_double() == e.get_double());
break;
case bsoncxx::type::k_string:
EXPECT(e.key().compare("2") == 0);
EXPECT(e.key() == "2");
EXPECT(v.get_string() == e.get_string());
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ void example() {

v = bsoncxx::types::b_string{"three"};
EXPECT(v.view().type() == bsoncxx::type::k_string);
EXPECT(v.view().get_string().value.compare("three") == 0);
EXPECT(v.view().get_string().value == "three");
}
// [Example]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ void example() {
v = v.view().get_document().value["key"].get_string(); // Copy: no dangling.

EXPECT(v.view().type() == bsoncxx::type::k_string);
EXPECT(v.view().get_string().value.compare("value") == 0);
EXPECT(v.view().get_string().value == "value");
}
// [Example]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@ void example(bsoncxx::document::element e) {

switch (v.type()) {
case bsoncxx::type::k_int32:
EXPECT(e.key().compare("a") == 0);
EXPECT(e.key() == "a");
EXPECT(v.get_int32() == e.get_int32());
break;
case bsoncxx::type::k_double:
EXPECT(e.key().compare("b") == 0);
EXPECT(e.key() == "b");
EXPECT(v.get_double() == e.get_double());
break;
case bsoncxx::type::k_string:
EXPECT(e.key().compare("c") == 0);
EXPECT(e.key() == "c");
EXPECT(v.get_string() == e.get_string());
break;
}
Expand Down
Loading