本文整理汇总了C++中string_view::end方法的典型用法代码示例。如果您正苦于以下问题:C++ string_view::end方法的具体用法?C++ string_view::end怎么用?C++ string_view::end使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类string_view
的用法示例。
在下文中一共展示了string_view::end方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: test_strview_basics
void test_strview_basics(const string_view& sv, const char *p, size_t n) {
ASSERT_EQ(p, sv.data());
ASSERT_EQ(n, sv.size());
ASSERT_EQ(n, sv.length());
ASSERT_EQ((n == 0), sv.empty());
ASSERT_EQ(p, sv.cbegin());
ASSERT_EQ(p, sv.begin());
ASSERT_EQ(p + n, sv.cend());
ASSERT_EQ(p + n, sv.end());
using reviter_t = std::reverse_iterator<string_view::const_iterator>;
ASSERT_EQ(reviter_t(sv.end()), sv.rbegin());
ASSERT_EQ(reviter_t(sv.begin()), sv.rend());
ASSERT_EQ(reviter_t(sv.cend()), sv.crbegin());
ASSERT_EQ(reviter_t(sv.cbegin()), sv.crend());
for (size_t i = 0; i < n; ++i) {
ASSERT_EQ(p[i], sv[i]);
ASSERT_EQ(p[i], sv.at(i));
}
ASSERT_THROW(sv.at(n), std::out_of_range);
ASSERT_THROW(sv.at(string_view::npos), std::out_of_range);
if (n > 0) {
ASSERT_EQ(p, &(sv.front()));
ASSERT_EQ(p + (n-1), &(sv.back()));
ASSERT_EQ(p[0], sv.front());
ASSERT_EQ(p[n-1], sv.back());
}
}
示例2: to_rna
string transcription::to_rna(string_view strand)
{
string result;
transform(strand.begin(), strand.end(), back_inserter(result),
static_cast<char (*)(char)>(to_rna));
return result;
}
示例3: main
int main()
{
using string_view = std::experimental::string_view;
using u16string_view = std::experimental::u16string_view;
using u32string_view = std::experimental::u32string_view;
using wstring_view = std::experimental::wstring_view;
test(string_view {});
test(string_view { "123"});
test(u16string_view{});
test(u16string_view{u"123"});
test(u32string_view{});
test(u32string_view{U"123"});
test(wstring_view {});
test(wstring_view {L"123"});
{
constexpr string_view sv { "123", 3 };
constexpr u16string_view u16sv {u"123", 3 };
constexpr u32string_view u32sv {U"123", 3 };
constexpr wstring_view wsv {L"123", 3 };
static_assert ( sv.begin() != sv.end(), "" );
static_assert ( u16sv.begin() != u16sv.end(), "" );
static_assert ( u32sv.begin() != u32sv.end(), "" );
static_assert ( wsv.begin() != wsv.end(), "" );
static_assert ( sv.begin() != sv.cend(), "" );
static_assert ( u16sv.begin() != u16sv.cend(), "" );
static_assert ( u32sv.begin() != u32sv.cend(), "" );
static_assert ( wsv.begin() != wsv.cend(), "" );
}
}
示例4: add_line_to_multiline_header
void Request::add_line_to_multiline_header(const string_view& line,
const string_view& header)
{
auto non_whitespace_pos = line.find_first_not_of("\t ");
if (non_whitespace_pos != line.end())
if (!header.empty())
headers_[header.str()] += line.substr(non_whitespace_pos).str();
}
示例5: getDeckName
string_view ParserKeyword::getDeckName( const string_view& str ) {
auto first_sep = std::find_if( str.begin(), str.end(), RawConsts::is_separator() );
// only look at the first 8 characters (at most)
if( std::distance( str.begin(), first_sep ) < 9 )
return { str.begin(), first_sep };
return { str.begin(), str.begin() + 9 };
}
示例6: return
config_option::config_option(string_view category, string_view name,
string_view description, const meta_state* meta,
void* value)
: meta_(meta),
value_(value) {
using std::copy;
using std::accumulate;
auto comma = name.find(',');
auto long_name = name.substr(0, comma);
auto short_names = comma == string_view::npos ? string_view{}
: name.substr(comma + 1);
auto total_size = [](std::initializer_list<string_view> xs) {
return (xs.size() - 1) // one separator between all fields
+ accumulate(xs.begin(), xs.end(), size_t{0},
[](size_t x, string_view sv) { return x + sv.size(); });
};
auto ts = total_size({category, long_name, short_names, description});
CAF_ASSERT(ts <= std::numeric_limits<uint16_t>::max());
buf_size_ = static_cast<uint16_t>(ts);
buf_.reset(new char[ts]);
// fille the buffer with "<category>.<long-name>,<short-name>,<descriptions>"
auto first = buf_.get();
auto i = first;
auto pos = [&] {
return static_cast<uint16_t>(std::distance(first, i));
};
// <category>.
i = copy(category.begin(), category.end(), i);
category_separator_ = pos();
*i++ = '.';
// <long-name>,
i = copy(long_name.begin(), long_name.end(), i);
long_name_separator_ = pos();
*i++ = ',';
// <short-names>,
i = copy(short_names.begin(), short_names.end(), i);
short_names_separator_ = pos();
*i++ = ',';
// <description>
i = copy(description.begin(), description.end(), i);
CAF_ASSERT(pos() == buf_size_);
}
示例7: validDeckName
bool ParserKeyword::validDeckName( const string_view& name) {
if( !validNameStart( name ) )
return false;
const auto valid = []( char c ) {
return std::isalnum( c ) || c == '-' || c == '_' || c == '+';
};
return std::all_of( name.begin() + 1, name.end(), valid );
}
示例8: matches
bool ParserKeyword::matches(const string_view& name ) const {
if (!validDeckName(name ))
return false;
else if( m_deckNames.count( name.string() ) )
return true;
else if (hasMatchRegex()) {
return boost::regex_match( name.begin(), name.end(), m_matchRegex);
}
return false;
}
示例9: ProcessBrackets
static int ProcessBrackets(string_view const Str, wchar_t const EndMark, brackets& Brackets)
{
for (auto Iterator = Str.begin(); Iterator != Str.end(); ++Iterator)
{
if (*Iterator == L'(')
{
if (!Brackets.Bracket)
{
Brackets.Bracket = true;
Brackets.BeginBracket = &*Iterator;
}
++Brackets.BracketsCount;
}
else if (*Iterator == L')')
{
if (!Brackets.BracketsCount)
return 0;
--Brackets.BracketsCount;
if (!Brackets.BracketsCount)
{
if (!Brackets.EndBracket)
Brackets.EndBracket = &*Iterator;
}
}
else if (*Iterator == EndMark && !!Brackets.BeginBracket == !!Brackets.EndBracket)
{
if (Brackets.BracketsCount)
return 0;
return Iterator - Str.begin() + 1;
}
}
return 0;
};
示例10: main
int main()
{
typedef std::string_view string_view;
typedef std::u16string_view u16string_view;
typedef std::u32string_view u32string_view;
typedef std::wstring_view wstring_view;
test(string_view ());
test(u16string_view());
test(u32string_view());
test(wstring_view ());
test(string_view ( "123"));
test(wstring_view (L"123"));
#if TEST_STD_VER >= 11
test(u16string_view{u"123"});
test(u32string_view{U"123"});
#endif
#if TEST_STD_VER > 11
{
constexpr string_view sv { "123", 3 };
constexpr u16string_view u16sv {u"123", 3 };
constexpr u32string_view u32sv {U"123", 3 };
constexpr wstring_view wsv {L"123", 3 };
static_assert ( sv.begin() != sv.end(), "" );
static_assert ( u16sv.begin() != u16sv.end(), "" );
static_assert ( u32sv.begin() != u32sv.end(), "" );
static_assert ( wsv.begin() != wsv.end(), "" );
static_assert ( sv.begin() != sv.cend(), "" );
static_assert ( u16sv.begin() != u16sv.cend(), "" );
static_assert ( u32sv.begin() != u32sv.cend(), "" );
static_assert ( wsv.begin() != wsv.cend(), "" );
}
#endif
}
示例11: is_dot_dot
inline bool is_dot_dot(const string_view &s)
{ return (s.end()-s.begin()==2) && (*(s.begin())=='.') && (*(s.begin()+1)=='.'); }
示例12: ConvertString
static string ConvertString(const string_view Src)
{
string Result;
Result.reserve(Src.size());
for (auto i = Src.begin(); i != Src.end(); ++i)
{
switch (*i)
{
case L'\\':
if (++i == Src.end())
{
Result.push_back(L'\\');
return Result;
}
switch (*i)
{
case L'\\':
Result.push_back(L'\\');
break;
case L'"':
Result.push_back(L'"');
break;
case L'n':
Result.push_back(L'\n');
break;
case L'r':
Result.push_back(L'\r');
break;
case L'b':
Result.push_back(L'\b');
break;
case L't':
Result.push_back('\t');
break;
default:
Result.push_back(L'\\');
--i;
break;
}
break;
case L'"':
Result.push_back(L'"');
if (++i == Src.end())
return Result;
if (*i != L'"')
--i;
break;
default:
Result.push_back(*i);
break;
}
}
return Result;
}