本文整理汇总了C++中stdx::string_view::size方法的典型用法代码示例。如果您正苦于以下问题:C++ string_view::size方法的具体用法?C++ string_view::size怎么用?C++ string_view::size使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类stdx::string_view
的用法示例。
在下文中一共展示了string_view::size方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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();
}
示例3: 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};
}
示例4:
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};
}