本文整理汇总了C++中std::experimental::string_view::size方法的典型用法代码示例。如果您正苦于以下问题:C++ string_view::size方法的具体用法?C++ string_view::size怎么用?C++ string_view::size使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类std::experimental::string_view
的用法示例。
在下文中一共展示了string_view::size方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main () {
test ( "ABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDE" );
test ( "ABCDE");
test ( "a" );
test ( "" );
test ( L"ABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDE" );
test ( L"ABCDE" );
test ( L"a" );
test ( L"" );
#if __cplusplus >= 201103L
test ( u"ABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDE" );
test ( u"ABCDE" );
test ( u"a" );
test ( u"" );
test ( U"ABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDE" );
test ( U"ABCDE" );
test ( U"a" );
test ( U"" );
#endif
#if _LIBCPP_STD_VER > 11
{
constexpr std::experimental::string_view sv1 { "ABCDE", 5 };
{
constexpr std::experimental::string_view sv2 = sv1.substr ( 0, 3 );
static_assert ( sv2.size() == 3, "" );
static_assert ( sv2[0] == 'A', "" );
static_assert ( sv2[1] == 'B', "" );
static_assert ( sv2[2] == 'C', "" );
}
{
constexpr std::experimental::string_view sv2 = sv1.substr ( 3, 0 );
static_assert ( sv2.size() == 0, "" );
}
{
constexpr std::experimental::string_view sv2 = sv1.substr ( 3, 3 );
static_assert ( sv2.size() == 2, "" );
static_assert ( sv2[0] == 'D', "" );
static_assert ( sv2[1] == 'E', "" );
}
}
#endif
}
示例2: main
int main () {
test ( "ABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDE" );
test ( "ABCDE");
test ( "a" );
test ( "" );
test ( L"ABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDE" );
test ( L"ABCDE" );
test ( L"a" );
test ( L"" );
test ( u"ABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDE" );
test ( u"ABCDE" );
test ( u"a" );
test ( u"" );
test ( U"ABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDE" );
test ( U"ABCDE" );
test ( U"a" );
test ( U"" );
{
constexpr std::experimental::string_view sv1 { "ABCDE", 5 };
{
constexpr std::experimental::string_view sv2 = sv1.substr ( 0, 3 );
static_assert ( sv2.size() == 3, "" );
static_assert ( sv2[0] == 'A', "" );
static_assert ( sv2[1] == 'B', "" );
static_assert ( sv2[2] == 'C', "" );
}
{
constexpr std::experimental::string_view sv2 = sv1.substr ( 3, 0 );
static_assert ( sv2.size() == 0, "" );
}
{
constexpr std::experimental::string_view sv2 = sv1.substr ( 3, 3 );
static_assert ( sv2.size() == 2, "" );
static_assert ( sv2[0] == 'D', "" );
static_assert ( sv2[1] == 'E', "" );
}
}
}
示例3: splitted
static OutputContainer splitted(const std::experimental::string_view &collection, const Element &element) {
OutputContainer output;
if(!collection.empty()) {
unsigned int start = 0, i = 0;
for(; i != collection.size();) {
if(collection[i] == element) {
output.push_back(collection.substr(start, i-start));
++i;
start = i;
} else
++i;
}
output.push_back(collection.substr(start, i));
}
return output;
}
示例4: encode
std::string uri::encode(const std::experimental::string_view input) {
static const std::array<char,16> hex =
{{ '0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f' }};
std::string res;
res.reserve(input.size());
for (const auto chr : input)
if (is_unreserved(chr)) {
res += chr;
} else {
res += '%';
res += hex[ chr >> 4 ];
res += hex[ chr & 0xf ];
}
return res;
}
示例5: decode
std::string uri::decode(const std::experimental::string_view input) {
std::string res;
res.reserve(input.size());
for (auto it = input.cbegin(), e = input.cend(); it not_eq e; ++it) {
if (*it == '%') {
if (++it >= e) return decode_error(std::move(res));
const uint8_t nibble1 = (*it);
if (++it >= e) return decode_error(std::move(res));
const uint8_t nibble2 = (*it);
res += static_cast<char>(from_hex(nibble1, nibble2));
} else {
if (is_reserved(*it) or is_unreserved(*it))
res += *it;
else
return decode_error(std::move(res));
}
}
return res;
}