Skip to content

Commit a9c728c

Browse files
committed
CXX-2109 Deprecate all references to utf8
1 parent 43fb119 commit a9c728c

34 files changed

+113
-122
lines changed

docs/content/mongocxx-v3/tutorial.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ value is a string:
202202

203203
```c++
204204
bsoncxx::document::element element = view["name"];
205-
if(element.type() != bsoncxx::type::k_utf8) {
205+
if(element.type() != bsoncxx::type::k_string) {
206206
// Error
207207
}
208208
std::string name = element.get_string().value.to_string();

examples/bsoncxx/builder_basic.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ int main(int, char**) {
3535
using bsoncxx::builder::basic::kvp;
3636

3737
doc.append(
38-
kvp("foo", "bar")); // string literal value will be converted to b_utf8 automatically
38+
kvp("foo", "bar")); // string literal value will be converted to b_string automatically
3939
doc.append(kvp("baz", types::b_bool{false}));
4040
doc.append(kvp("garply", types::b_double{3.14159}));
4141

examples/bsoncxx/builder_core.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ int main(int, char**) {
6161
// Just call append() and pass a value wrapped in the corresponding BSON type.
6262
auto array = builder::core{true}; // we are building an array
6363

64-
array.append(types::b_utf8{"hello"}); // append a UTF-8 string
65-
array.append(types::b_double{1.234}); // append a double
66-
array.append(types::b_int32{1234}); // append an int32
64+
array.append(types::b_string{"hello"}); // append a UTF-8 string
65+
array.append(types::b_double{1.234}); // append a double
66+
array.append(types::b_int32{1234}); // append an int32
6767
// ... etc.
6868
}

examples/bsoncxx/view_and_value.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ int main(int, char**) {
6969

7070
// we can use type() to get the type of the value.
7171
switch (ele.type()) {
72-
case type::k_utf8:
72+
case type::k_string:
7373
std::cout << "Got String!" << std::endl;
7474
break;
7575
case type::k_oid:

examples/mongocxx/get_values_from_documents.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ void iterate_messagelist(const bsoncxx::document::element& ele) {
7575
if (status && status.type() == type::k_int32) {
7676
std::cout << "status: " << status.get_int32().value << std::endl;
7777
}
78-
if (msg && msg.type() == type::k_utf8) {
78+
if (msg && msg.type() == type::k_string) {
7979
std::cout << "msg: " << msg.get_string().value << std::endl;
8080
}
8181
} else {

src/bsoncxx/builder/core.cpp

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -288,15 +288,15 @@ core& core::append(const types::b_double& value) {
288288
return *this;
289289
}
290290

291-
core& core::append(const types::b_utf8& value) {
291+
core& core::append(const types::b_string& value) {
292292
stdx::string_view key = _impl->next_key();
293293

294294
if (!bson_append_utf8(_impl->back(),
295295
key.data(),
296296
static_cast<std::int32_t>(key.length()),
297297
value.value.data(),
298298
static_cast<std::int32_t>(value.value.length()))) {
299-
throw bsoncxx::exception{error_code::k_cannot_append_utf8};
299+
throw bsoncxx::exception{error_code::k_cannot_append_string};
300300
}
301301

302302
return *this;
@@ -545,13 +545,13 @@ core& core::append(const types::b_maxkey&) {
545545
}
546546

547547
core& core::append(std::string str) {
548-
append(types::b_utf8{std::move(str)});
548+
append(types::b_string{std::move(str)});
549549

550550
return *this;
551551
}
552552

553553
core& core::append(stdx::string_view str) {
554-
append(types::b_utf8{std::move(str)});
554+
append(types::b_string{std::move(str)});
555555

556556
return *this;
557557
}
@@ -647,15 +647,12 @@ core& core::concatenate(const bsoncxx::document::view& view) {
647647

648648
core& core::append(const bsoncxx::types::bson_value::view& value) {
649649
switch (static_cast<int>(value.type())) {
650-
// CXX-1817; deprecation warning suppressed for get_utf8()
651-
BSONCXX_SUPPRESS_DEPRECATION_WARNINGS_BEGIN
652650
#define BSONCXX_ENUM(type, val) \
653651
case val: \
654652
append(value.get_##type()); \
655653
break;
656654
#include <bsoncxx/enums/type.hpp>
657655
#undef BSONCXX_ENUM
658-
BSONCXX_SUPPRESS_DEPRECATION_WARNINGS_END
659656
}
660657

661658
return *this;

src/bsoncxx/builder/core.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -184,9 +184,9 @@ class BSONCXX_API core {
184184
/// @throws
185185
/// bsoncxx::exception if the current BSON datum is a document that is waiting for a key to be
186186
/// appended to start a new key/value pair.
187-
/// bsoncxx::exception if the utf8 fails to append.
187+
/// bsoncxx::exception if the string fails to append.
188188
///
189-
core& append(const types::b_utf8& value);
189+
core& append(const types::b_string& value);
190190

191191
///
192192
/// Appends a BSON document.
@@ -510,7 +510,7 @@ class BSONCXX_API core {
510510
BSONCXX_INLINE core& append(T* v) {
511511
static_assert(std::is_same<typename std::remove_const<T>::type, char>::value,
512512
"append is disabled for non-char pointer types");
513-
append(types::b_utf8{v});
513+
append(types::b_string{v});
514514

515515
return *this;
516516
}

src/bsoncxx/document/element.cpp

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -78,32 +78,26 @@ stdx::string_view element::key() const {
7878
return stdx::string_view{key};
7979
}
8080

81-
// CXX-1817; deprecation warning suppressed for get_utf8()
82-
BSONCXX_SUPPRESS_DEPRECATION_WARNINGS_BEGIN
8381
#define BSONCXX_ENUM(name, val) \
8482
types::b_##name element::get_##name() const { \
8583
types::bson_value::view v{_raw, _length, _offset, _keylen}; \
8684
return v.get_##name(); \
8785
}
8886
#include <bsoncxx/enums/type.hpp>
8987
#undef BSONCXX_ENUM
90-
BSONCXX_SUPPRESS_DEPRECATION_WARNINGS_END
9188

92-
types::b_utf8 element::get_string() const {
89+
types::b_string element::get_utf8() const {
9390
types::bson_value::view v{_raw, _length, _offset, _keylen};
9491
return v.get_string();
9592
}
9693

9794
types::bson_value::view element::get_value() const {
9895
switch (static_cast<int>(type())) {
99-
// CXX-1817; deprecation warning suppressed for get_utf8()
100-
BSONCXX_SUPPRESS_DEPRECATION_WARNINGS_BEGIN
10196
#define BSONCXX_ENUM(type, val) \
10297
case val: \
10398
return types::bson_value::view{get_##type()};
10499
#include <bsoncxx/enums/type.hpp>
105100
#undef BSONCXX_ENUM
106-
BSONCXX_SUPPRESS_DEPRECATION_WARNINGS_END
107101
}
108102

109103
BSONCXX_UNREACHABLE;

src/bsoncxx/document/element.hpp

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ enum class binary_sub_type : std::uint8_t;
3030
namespace types {
3131
struct b_eod;
3232
struct b_double;
33-
struct b_utf8;
33+
struct b_string;
3434
struct b_document;
3535
struct b_array;
3636
struct b_binary;
@@ -145,25 +145,24 @@ class BSONCXX_API element {
145145
types::b_double get_double() const;
146146

147147
///
148-
/// Getter for elements of the b_utf8 type.
148+
/// Getter for elements of the b_string type.
149149
///
150150
/// @deprecated use document::element::get_string() instead.
151151
///
152-
/// @throws bsoncxx::exception if this element is not a b_utf8.
152+
/// @throws bsoncxx::exception if this element is not a b_string.
153153
///
154154
/// @return the element's value.
155155
///
156-
BSONCXX_DEPRECATED types::b_utf8 get_utf8() const;
156+
BSONCXX_DEPRECATED types::b_string get_utf8() const;
157157

158158
///
159-
/// Getter for elements of the b_utf8, or string, type. This function acts as a
160-
/// wrapper for get_utf8().
159+
/// Getter for elements of the b_string type.
161160
///
162-
/// @throws bsoncxx::exception if this element is not a b_utf8.
161+
/// @throws bsoncxx::exception if this element is not a b_string.
163162
///
164163
/// @return the element's value.
165164
///
166-
types::b_utf8 get_string() const;
165+
types::b_string get_string() const;
167166

168167
///
169168
/// Getter for elements of the b_document type.

src/bsoncxx/enums/type.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
#endif
1818

1919
BSONCXX_ENUM(double, 0x01)
20-
BSONCXX_ENUM(utf8, 0x02)
20+
BSONCXX_ENUM(string, 0x02)
2121
BSONCXX_ENUM(document, 0x03)
2222
BSONCXX_ENUM(array, 0x04)
2323
BSONCXX_ENUM(binary, 0x05)

src/bsoncxx/exception/error_code.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@ enum class error_code : std::int32_t {
9595
#define BSONCXX_ENUM(name, value) k_cannot_append_##name,
9696
#include <bsoncxx/enums/type.hpp>
9797
#undef BSONCXX_ENUM
98+
k_cannot_append_utf8 = k_cannot_append_string,
99+
k_need_element_type_k_utf8 = k_need_element_type_k_string,
98100
// Add new constant string message to error_code.cpp as well!
99101
};
100102

src/bsoncxx/test/bson_builder.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ void viewable_eq_viewable(const T& stream, const U& basic) {
5252
REQUIRE(std::memcmp(expected.data(), test.data(), expected.length()) == 0);
5353
}
5454

55-
TEST_CASE("builder appends utf8", "[bsoncxx::builder::stream]") {
55+
TEST_CASE("builder appends string", "[bsoncxx::builder::stream]") {
5656
bson_t expected;
5757
bson_init(&expected);
5858

@@ -73,8 +73,8 @@ TEST_CASE("builder appends utf8", "[bsoncxx::builder::stream]") {
7373
bson_eq_stream(&expected, b);
7474
}
7575

76-
SECTION("works with b_utf8") {
77-
b << "hello" << types::b_utf8{"world"};
76+
SECTION("works with b_string") {
77+
b << "hello" << types::b_string{"world"};
7878

7979
bson_eq_stream(&expected, b);
8080
}
@@ -812,7 +812,7 @@ TEST_CASE("core method chaining to build array works", "[bsoncxx::builder::core]
812812
auto array_view = array.view();
813813

814814
REQUIRE(std::distance(array_view.begin(), array_view.end()) == 3);
815-
REQUIRE(array_view[0].type() == type::k_utf8);
815+
REQUIRE(array_view[0].type() == type::k_string);
816816
REQUIRE(string::to_string(array_view[0].get_string().value) == "foo");
817817
REQUIRE(array_view[1].type() == type::k_int32);
818818
REQUIRE(array_view[1].get_int32().value == 1);
@@ -1197,7 +1197,7 @@ TEST_CASE("builder::basic::make_array works", "[bsoncxx::builder::basic::make_ar
11971197
auto array_view = array.view();
11981198

11991199
REQUIRE(std::distance(array_view.begin(), array_view.end()) == 3);
1200-
REQUIRE(array_view[0].type() == type::k_utf8);
1200+
REQUIRE(array_view[0].type() == type::k_string);
12011201
REQUIRE(string::to_string(array_view[0].get_string().value) == "foo");
12021202
REQUIRE(array_view[1].type() == type::k_int32);
12031203
REQUIRE(array_view[1].get_int32().value == 1);

src/bsoncxx/test/bson_types.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,10 @@ TEST_CASE("b_double", "[bsoncxx::type::b_double]") {
4545
REQUIRE(!(a == c));
4646
}
4747

48-
TEST_CASE("b_utf8", "[bsoncxx::type::b_utf8]") {
49-
b_utf8 a{"hello"};
50-
b_utf8 b{a};
51-
b_utf8 c{"world"};
48+
TEST_CASE("b_string", "[bsoncxx::type::b_string]") {
49+
b_string a{"hello"};
50+
b_string b{a};
51+
b_string c{"world"};
5252
REQUIRE(a == b);
5353
REQUIRE(!(a == c));
5454
}
@@ -196,9 +196,9 @@ TEST_CASE("bson_value::view with b_double", "[bsoncxx::types::bson_value::view]"
196196
REQUIRE(bson_value::view{double_val}.get_double() == double_val);
197197
}
198198

199-
TEST_CASE("bson_value::view with b_utf8", "[bsoncxx::types::bson_value::view]") {
200-
b_utf8 utf8_val{"hello"};
201-
REQUIRE(bson_value::view{utf8_val}.get_string() == utf8_val);
199+
TEST_CASE("bson_value::view with b_string", "[bsoncxx::types::bson_value::view]") {
200+
b_string string_val{"hello"};
201+
REQUIRE(bson_value::view{string_val}.get_string() == string_val);
202202
}
203203

204204
TEST_CASE("bson_value::view with b_document", "[bsoncxx::types::bson_value::view]") {

src/bsoncxx/test/bson_value.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,15 +65,15 @@ TEST_CASE("types::bson_value::value", "[bsoncxx::types::bson_value::value]") {
6565
coverting_construction_test(b_bool{true}, test_value);
6666
}
6767

68-
SECTION("utf8") {
68+
SECTION("string") {
6969
std::string value = "super duper";
7070

7171
auto test_doc = bson_value::make_value(value);
7272
value_construction_test(test_doc.view());
7373

7474
coverting_construction_test(value, test_doc);
7575
coverting_construction_test(value.c_str(), test_doc);
76-
coverting_construction_test(b_utf8{value}, test_doc);
76+
coverting_construction_test(b_string{value}, test_doc);
7777
coverting_construction_test(stdx::string_view{value}, test_doc);
7878

7979
const char raw_data[]{'s', 'u', 'p', 'e', 'r', ' ', 'd', 'u', 'p', 'e', 'r'};

src/bsoncxx/types.hpp

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,15 @@ BSONCXX_INLINE_NAMESPACE_BEGIN
3232
/// An enumeration of each BSON type.
3333
/// These x-macros will expand to be of the form:
3434
/// k_double = 0x01,
35-
/// k_utf8 = 0x02,
35+
/// k_string = 0x02,
3636
/// k_document = 0x03,
3737
/// k_array = 0x04 ...
3838
///
3939
enum class type : std::uint8_t {
4040
#define BSONCXX_ENUM(name, val) k_##name = val,
4141
#include <bsoncxx/enums/type.hpp>
4242
#undef BSONCXX_ENUM
43+
k_utf8 = 0x02,
4344
};
4445

4546
///
@@ -110,19 +111,19 @@ BSONCXX_INLINE bool operator==(const b_double& lhs, const b_double& rhs) {
110111
///
111112
/// A BSON UTF-8 encoded string value.
112113
///
113-
struct BSONCXX_API b_utf8 {
114-
static constexpr auto type_id = type::k_utf8;
114+
struct BSONCXX_API b_string {
115+
static constexpr auto type_id = type::k_string;
115116

116117
///
117-
/// Constructor for b_utf8.
118+
/// Constructor for b_string.
118119
///
119120
/// @param t
120121
/// The value to wrap.
121122
///
122123
template <typename T,
123-
typename std::enable_if<!std::is_same<b_utf8, typename std::decay<T>::type>::value,
124+
typename std::enable_if<!std::is_same<b_string, typename std::decay<T>::type>::value,
124125
int>::type = 0>
125-
BSONCXX_INLINE explicit b_utf8(T&& t) : value(std::forward<T>(t)) {}
126+
BSONCXX_INLINE explicit b_string(T&& t) : value(std::forward<T>(t)) {}
126127

127128
stdx::string_view value;
128129

@@ -135,14 +136,21 @@ struct BSONCXX_API b_utf8 {
135136
};
136137

137138
///
138-
/// free function comparator for b_utf8
139+
/// free function comparator for b_string
139140
///
140-
/// @relatesalso b_utf8
141+
/// @relatesalso b_string
141142
///
142-
BSONCXX_INLINE bool operator==(const b_utf8& lhs, const b_utf8& rhs) {
143+
BSONCXX_INLINE bool operator==(const b_string& lhs, const b_string& rhs) {
143144
return lhs.value == rhs.value;
144145
}
145146

147+
///
148+
/// This class has been renamed to b_string
149+
///
150+
/// @deprecated use b_string instead.
151+
///
152+
BSONCXX_DEPRECATED typedef b_string b_utf8;
153+
146154
///
147155
/// A BSON document value.
148156
///

src/bsoncxx/types/bson_value/value.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ value::value(int64_t v) : _impl{stdx::make_unique<impl>()} {
4747

4848
value::value(const char* v) : value(stdx::string_view{v}) {}
4949
value::value(std::string v) : value(stdx::string_view{v}) {}
50-
value::value(b_utf8 v) : value(v.value) {}
50+
value::value(b_string v) : value(v.value) {}
5151
value::value(stdx::string_view v) : _impl{stdx::make_unique<impl>()} {
5252
_impl->_value.value_type = BSON_TYPE_UTF8;
5353
_impl->_value.value.v_utf8.str = make_copy_for_libbson(v);

src/bsoncxx/types/bson_value/value.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ class BSONCXX_API value {
4848
///
4949
/// These x-macros will expand to:
5050
/// value(b_double v);
51-
/// value(b_utf8 v);
51+
/// value(b_string v);
5252
/// value(b_document v);
5353
/// value(b_array v); ...
5454
///

0 commit comments

Comments
 (0)