本文整理汇总了C++中stdx::string_view::data方法的典型用法代码示例。如果您正苦于以下问题:C++ string_view::data方法的具体用法?C++ string_view::data怎么用?C++ string_view::data使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类stdx::string_view
的用法示例。
在下文中一共展示了string_view::data方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: find
view::const_iterator view::find(stdx::string_view key) const {
bson_t b;
if (!bson_init_static(&b, _data, _length)) {
return cend();
}
bson_iter_t iter;
// Logically, a default constructed string_view represents the
// empty string just as does string_view(""), but they have,
// potentially, different represntations, the former having .data
// returning nullptr though the latter probably does not. But the
// C functions like strncmp below can't be called with nullptr. If
// we were called with a string_data such that its .data() member
// returns nullptr, then, barring undefined behavior, its length
// is known to be zero, and it is equivalent to the empty string,
// an instance of which we reset it to.
if (key.data() == nullptr) {
key = "";
}
if (!bson_iter_init_find_w_len(&iter, &b, key.data(), static_cast<int>(key.size()))) {
return cend();
}
return const_iterator(element(
_data, static_cast<uint32_t>(_length), bson_iter_offset(&iter), bson_iter_key_len(&iter)));
}
示例2: memcpy
oid::oid(stdx::string_view str) : _is_valid(bson_oid_is_valid(str.data(), str.length())) {
if (_is_valid) {
bson_oid_t oid;
bson_oid_init_from_string(&oid, str.data());
memcpy(_bytes, oid.bytes, sizeof(_bytes));
}
}
示例3: find
view::const_iterator view::find(stdx::string_view key) const {
bson_t b;
bson_iter_t iter;
if (!bson_init_static(&b, _data, _length)) {
return cend();
}
if (!bson_iter_init(&iter, &b)) {
return cend();
}
if (key.empty()) {
return cend();
}
while (bson_iter_next(&iter)) {
const char* ikey = bson_iter_key(&iter);
if (0 == strncmp(key.data(), ikey, key.size())) {
return const_iterator(element(iter.raw, iter.len, iter.off));
}
}
return cend();
}
示例4: rename
void collection::rename(stdx::string_view new_name, bool drop_target_before_rename) {
bson_error_t error;
auto result = libmongoc::collection_rename(_get_impl().collection_t, _get_impl().database_name.c_str(),
new_name.data(), drop_target_before_rename, &error);
if (!result) {
throw_exception<operation_exception>(error);
}
}
示例5: from_json
document::value from_json(stdx::string_view json) {
bson_error_t error;
bson_t* result =
bson_new_from_json(reinterpret_cast<const uint8_t*>(json.data()), json.size(), &error);
if (!result) throw exception(error_code::k_json_parse_failure, error.message);
std::uint32_t length;
std::uint8_t* buf = bson_destroy_with_steal(result, true, &length);
return document::value{buf, length, bson_free_deleter};
}
示例6:
stdx::optional<document::value> from_json(stdx::string_view json) {
bson_error_t error;
bson_t* result =
bson_new_from_json(reinterpret_cast<const uint8_t*>(json.data()), json.size(), &error);
if (!result) return stdx::nullopt;
std::uint32_t length;
std::uint8_t* buf = bson_destroy_with_steal(result, true, &length);
return document::value{buf, length, bson_free_deleter};
}
示例7: find
view::iterator view::find(stdx::string_view key) const {
bson_t b;
bson_iter_t iter;
if (!bson_init_static(&b, _data, _length)) {
return end();
}
if (bson_iter_init_find(&iter, &b, key.data())) {
return iterator(element(iter.raw, iter.len, iter.off));
} else {
return end();
}
}
示例8: create_collection
class collection database::create_collection(stdx::string_view name,
const options::create_collection& options) {
bson_error_t error;
libbson::scoped_bson_t opts_bson{options.to_document()};
auto result = libmongoc::database_create_collection(_get_impl().database_t, name.data(),
opts_bson.bson(), &error);
if (!result) {
throw_exception<operation_exception>(error);
}
return mongocxx::collection(*this, static_cast<void*>(result));
}
示例9:
collection::collection(const database& database, stdx::string_view collection_name,
void* collection)
: _impl(stdx::make_unique<impl>(static_cast<mongoc_collection_t*>(collection), database.name(),
database._impl->client_impl, collection_name.data())) {
}
示例10:
oid::oid(stdx::string_view str) : _is_valid(bson_oid_is_valid(str.data(), str.length())) {
if (_is_valid) {
bson_oid_t oid;
bson_oid_init_from_string(&oid, str.data());
}
}
示例11: has_collection
bool database::has_collection(stdx::string_view name) const {
bson_error_t error;
return libmongoc::database_has_collection(_get_impl().database_t, name.data(), &error);
}
示例12: tag
void write_concern::tag(stdx::string_view confirm_from) {
libmongoc::write_concern_set_wtag(_impl->write_concern_t, confirm_from.data());
}