Skip to content

Commit 30cf5e5

Browse files
authored
CXX-3101 Remove workarounds for core::string_view (#1268)
1 parent abdc6ed commit 30cf5e5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+217
-217
lines changed

examples/api/bsoncxx/examples/bson_documents/access_array/algorithms.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,12 @@ void example(bsoncxx::array::view arr) {
3434

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

4040
EXPECT(elements.size() == 2u);
41-
EXPECT(elements[0].key().compare("0") == 0);
42-
EXPECT(elements[1].key().compare("2") == 0);
41+
EXPECT(elements[0].key() == "0");
42+
EXPECT(elements[1].key() == "2");
4343
}
4444
// [Example]
4545

examples/api/bsoncxx/examples/bson_documents/access_array/basic.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,16 @@ void example(bsoncxx::array::view arr) {
2828
for (bsoncxx::array::element e : arr) {
2929
switch (e.type()) {
3030
case bsoncxx::type::k_int32:
31-
EXPECT(e.key().compare("0") == 0);
31+
EXPECT(e.key() == "0");
3232
EXPECT(e.get_int32().value == 1);
3333
break;
3434
case bsoncxx::type::k_double:
35-
EXPECT(e.key().compare("1") == 0);
35+
EXPECT(e.key() == "1");
3636
EXPECT(e.get_double().value == 2.0);
3737
break;
3838
case bsoncxx::type::k_string:
39-
EXPECT(e.key().compare("2") == 0);
40-
EXPECT(e.get_string().value.compare("three") == 0);
39+
EXPECT(e.key() == "2");
40+
EXPECT(e.get_string().value == "three");
4141
break;
4242
}
4343
}

examples/api/bsoncxx/examples/bson_documents/access_array/find.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ void example(bsoncxx::array::view arr) {
3030
auto iter = arr.find(1);
3131

3232
EXPECT(iter != arr.end());
33-
EXPECT(iter->key().compare("1") == 0);
33+
EXPECT(iter->key() == "1");
3434
EXPECT(iter->get_int32().value == 2);
3535
}
3636

examples/api/bsoncxx/examples/bson_documents/access_array/iterators.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,20 +33,20 @@ void example(bsoncxx::array::view arr) {
3333
{
3434
bsoncxx::array::element e = *iter;
3535

36-
EXPECT(e.key().compare("0") == 0);
36+
EXPECT(e.key() == "0");
3737
EXPECT(e.get_int32().value == 1);
3838
}
3939

4040
++iter;
4141

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

4545
{
4646
auto iter_copy = iter++;
4747

4848
EXPECT(iter_copy != iter);
49-
EXPECT(iter_copy->key().compare("1") == 0);
49+
EXPECT(iter_copy->key() == "1");
5050
EXPECT(iter_copy->get_int32() == 2);
5151
}
5252

examples/api/bsoncxx/examples/bson_documents/access_array/subscript.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ void example(bsoncxx::array::view arr) {
3030
{
3131
bsoncxx::array::element e = arr[1];
3232

33-
EXPECT(e.key().compare("1") == 0);
33+
EXPECT(e.key() == "1");
3434
EXPECT(e.get_int32().value == 2);
3535
}
3636

examples/api/bsoncxx/examples/bson_documents/access_doc/algorithms.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,12 @@ void example(bsoncxx::document::view doc) {
3737
doc.end(),
3838
std::back_inserter(elements),
3939
[](const bsoncxx::document::element& e) {
40-
return e.key().compare("a") == 0 || e.type() == bsoncxx::type::k_string;
40+
return e.key() == "a" || e.type() == bsoncxx::type::k_string;
4141
});
4242

4343
EXPECT(elements.size() == 2u);
44-
EXPECT(elements[0].key().compare("a") == 0);
45-
EXPECT(elements[1].key().compare("c") == 0);
44+
EXPECT(elements[0].key() == "a");
45+
EXPECT(elements[1].key() == "c");
4646
}
4747
// [Example]
4848

examples/api/bsoncxx/examples/bson_documents/access_doc/basic.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,16 @@ void example(bsoncxx::document::view doc) {
2828
for (bsoncxx::document::element e : doc) {
2929
switch (e.type()) {
3030
case bsoncxx::type::k_int32:
31-
EXPECT(e.key().compare("a") == 0);
31+
EXPECT(e.key() == "a");
3232
EXPECT(e.get_int32().value == 1);
3333
break;
3434
case bsoncxx::type::k_double:
35-
EXPECT(e.key().compare("b") == 0);
35+
EXPECT(e.key() == "b");
3636
EXPECT(e.get_double().value == 2.0);
3737
break;
3838
case bsoncxx::type::k_string:
39-
EXPECT(e.key().compare("c") == 0);
40-
EXPECT(e.get_string().value.compare("three") == 0);
39+
EXPECT(e.key() == "c");
40+
EXPECT(e.get_string().value == "three");
4141
break;
4242
}
4343
}

examples/api/bsoncxx/examples/bson_documents/access_doc/find.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ void example(bsoncxx::document::view doc) {
3030
auto iter = doc.find("b");
3131

3232
EXPECT(iter != doc.end());
33-
EXPECT(iter->key().compare("b") == 0);
33+
EXPECT(iter->key() == "b");
3434
EXPECT(iter->get_int32().value == 2);
3535
}
3636

examples/api/bsoncxx/examples/bson_documents/access_doc/iterators.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,20 +33,20 @@ void example(bsoncxx::document::view doc) {
3333
{
3434
bsoncxx::document::element e = *iter;
3535

36-
EXPECT(e.key().compare("a") == 0);
36+
EXPECT(e.key() == "a");
3737
EXPECT(e.get_int32().value == 1);
3838
}
3939

4040
++iter;
4141

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

4545
{
4646
auto iter_copy = iter++;
4747

4848
EXPECT(iter_copy != iter);
49-
EXPECT(iter_copy->key().compare("b") == 0);
49+
EXPECT(iter_copy->key() == "b");
5050
EXPECT(iter_copy->get_int32() == 2);
5151
}
5252

examples/api/bsoncxx/examples/bson_documents/access_doc/subscript.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ void example(bsoncxx::document::view doc) {
3030
{
3131
bsoncxx::document::element e = doc["b"];
3232

33-
EXPECT(e.key().compare("b") == 0);
33+
EXPECT(e.key() == "b");
3434
EXPECT(e.get_int32().value == 2);
3535
}
3636

examples/api/bsoncxx/examples/bson_documents/create_array/builder_make_document.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ void example() {
3232

3333
EXPECT(arr[0].get_int32().value == 1);
3434
EXPECT(arr[1].get_double().value == 2.0);
35-
EXPECT(arr[2].get_string().value.compare("three") == 0);
35+
EXPECT(arr[2].get_string().value == "three");
3636
}
3737
// [Example]
3838

examples/api/bsoncxx/examples/bson_documents/create_array/builder_value_type.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ void example() {
3636

3737
EXPECT(arr[0].get_int32().value == 1);
3838
EXPECT(arr[1].get_double().value == 2.0);
39-
EXPECT(arr[2].get_string().value.compare("three") == 0);
39+
EXPECT(arr[2].get_string().value == "three");
4040
}
4141
// [Example]
4242

examples/api/bsoncxx/examples/bson_documents/create_array/json_basic.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ void example() {
3131

3232
EXPECT(doc["0"].get_int32().value == 1);
3333
EXPECT(doc["1"].get_double().value == 2.0);
34-
EXPECT(doc["2"].get_string().value.compare("three") == 0);
34+
EXPECT(doc["2"].get_string().value == "three");
3535
}
3636
// [Example]
3737

examples/api/bsoncxx/examples/bson_documents/create_doc/json_basic.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ void example() {
3535

3636
EXPECT(doc["a"].get_int32().value == 1);
3737
EXPECT(doc["b"].get_double().value == 2.0);
38-
EXPECT(doc["c"].get_string().value.compare("three") == 0);
38+
EXPECT(doc["c"].get_string().value == "three");
3939
}
4040
// [Example]
4141

examples/api/bsoncxx/examples/bson_documents/elements/arr_multi.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ namespace {
2626
void example(bsoncxx::array::element e) {
2727
switch (e.type()) {
2828
case bsoncxx::type::k_int32: {
29-
EXPECT(e.key().compare("0") == 0);
29+
EXPECT(e.key() == "0");
3030

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

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

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

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

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

5353
EXPECT(v.type_id == bsoncxx::type::k_string);
54-
EXPECT(v.value.compare("three") == 0);
54+
EXPECT(v.value == "three");
5555

5656
break;
5757
}

examples/api/bsoncxx/examples/bson_documents/elements/arr_single.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,14 @@ namespace {
2525
// [1, 2.0, "three"]
2626
void example(bsoncxx::array::element e) {
2727
if (e.type() == bsoncxx::type::k_int32) {
28-
EXPECT(e.key().compare("0") == 0);
28+
EXPECT(e.key() == "0");
2929

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

3232
EXPECT(v.type_id == bsoncxx::type::k_int32);
3333
EXPECT(v.value == 1);
3434
} else {
35-
EXPECT(e.key().compare("0") != 0);
35+
EXPECT(e.key() != "0");
3636
}
3737
}
3838
// [Example]

examples/api/bsoncxx/examples/bson_documents/elements/cmp_bson_value.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,18 +29,18 @@ void example(bsoncxx::document::element e) {
2929
bsoncxx::types::b_int64 b{2};
3030

3131
if (e.get_value() == a) {
32-
EXPECT(e.key().compare("a") == 0);
32+
EXPECT(e.key() == "a");
3333
} else if (e.get_value() == b) {
34-
EXPECT(e.key().compare("b") == 0);
34+
EXPECT(e.key() == "b");
3535
}
3636

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

4040
if (e == va) {
41-
EXPECT(e.key().compare("a") == 0);
41+
EXPECT(e.key() == "a");
4242
} else if (e == vb) {
43-
EXPECT(e.key().compare("b") == 0);
43+
EXPECT(e.key() == "b");
4444
}
4545
}
4646
// [Example]

examples/api/bsoncxx/examples/bson_documents/elements/cmp_type.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ void example(bsoncxx::document::element e) {
3030
std::int64_t b{2};
3131

3232
if (e.type() == bsoncxx::type::k_int32) {
33-
EXPECT(e.key().compare("a") == 0);
33+
EXPECT(e.key() == "a");
3434
EXPECT(e.get_int32().value == a);
3535
} else if (e.type() == bsoncxx::type::k_int64) {
36-
EXPECT(e.key().compare("b") == 0);
36+
EXPECT(e.key() == "b");
3737
EXPECT(e.get_int64().value == b);
3838
}
3939
}

examples/api/bsoncxx/examples/bson_documents/elements/doc_multi.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ namespace {
2626
void example(bsoncxx::document::element e) {
2727
switch (e.type()) {
2828
case bsoncxx::type::k_int32: {
29-
EXPECT(e.key().compare("a") == 0);
29+
EXPECT(e.key() == "a");
3030

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

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

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

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

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

5353
EXPECT(v.type_id == bsoncxx::type::k_string);
54-
EXPECT(v.value.compare("three") == 0);
54+
EXPECT(v.value == "three");
5555

5656
break;
5757
}

examples/api/bsoncxx/examples/bson_documents/elements/doc_single.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,14 @@ namespace {
2525
// {"a": 1, "b": 2.0, "c": "three"}
2626
void example(bsoncxx::document::element e) {
2727
if (e.type() == bsoncxx::type::k_int32) {
28-
EXPECT(e.key().compare("a") == 0);
28+
EXPECT(e.key() == "a");
2929

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

3232
EXPECT(v.type_id == bsoncxx::type::k_int32);
3333
EXPECT(v.value == 1);
3434
} else {
35-
EXPECT(e.key().compare("a") != 0);
35+
EXPECT(e.key() != "a");
3636
}
3737
}
3838
// [Example]

examples/api/bsoncxx/examples/bson_documents/values/arr_value.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ void example() {
3737
v = v.view().get_array().value[0].get_string(); // Copy: no dangling.
3838

3939
EXPECT(v.view().type() == bsoncxx::type::k_string);
40-
EXPECT(v.view().get_string().value.compare("value") == 0);
40+
EXPECT(v.view().get_string().value == "value");
4141
}
4242
// [Example]
4343

examples/api/bsoncxx/examples/bson_documents/values/arr_view.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,15 @@ void example(bsoncxx::array::element e) {
3030

3131
switch (v.type()) {
3232
case bsoncxx::type::k_int32:
33-
EXPECT(e.key().compare("0") == 0);
33+
EXPECT(e.key() == "0");
3434
EXPECT(v.get_int32() == e.get_int32());
3535
break;
3636
case bsoncxx::type::k_double:
37-
EXPECT(e.key().compare("1") == 0);
37+
EXPECT(e.key() == "1");
3838
EXPECT(v.get_double() == e.get_double());
3939
break;
4040
case bsoncxx::type::k_string:
41-
EXPECT(e.key().compare("2") == 0);
41+
EXPECT(e.key() == "2");
4242
EXPECT(v.get_string() == e.get_string());
4343
break;
4444
}

examples/api/bsoncxx/examples/bson_documents/values/bson_type_value.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ void example() {
3737

3838
v = bsoncxx::types::b_string{"three"};
3939
EXPECT(v.view().type() == bsoncxx::type::k_string);
40-
EXPECT(v.view().get_string().value.compare("three") == 0);
40+
EXPECT(v.view().get_string().value == "three");
4141
}
4242
// [Example]
4343

examples/api/bsoncxx/examples/bson_documents/values/doc_value.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ void example() {
3737
v = v.view().get_document().value["key"].get_string(); // Copy: no dangling.
3838

3939
EXPECT(v.view().type() == bsoncxx::type::k_string);
40-
EXPECT(v.view().get_string().value.compare("value") == 0);
40+
EXPECT(v.view().get_string().value == "value");
4141
}
4242
// [Example]
4343

examples/api/bsoncxx/examples/bson_documents/values/doc_view.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,15 @@ void example(bsoncxx::document::element e) {
3030

3131
switch (v.type()) {
3232
case bsoncxx::type::k_int32:
33-
EXPECT(e.key().compare("a") == 0);
33+
EXPECT(e.key() == "a");
3434
EXPECT(v.get_int32() == e.get_int32());
3535
break;
3636
case bsoncxx::type::k_double:
37-
EXPECT(e.key().compare("b") == 0);
37+
EXPECT(e.key() == "b");
3838
EXPECT(v.get_double() == e.get_double());
3939
break;
4040
case bsoncxx::type::k_string:
41-
EXPECT(e.key().compare("c") == 0);
41+
EXPECT(e.key() == "c");
4242
EXPECT(v.get_string() == e.get_string());
4343
break;
4444
}

0 commit comments

Comments
 (0)