本文整理汇总了C++中string_view::at方法的典型用法代码示例。如果您正苦于以下问题:C++ string_view::at方法的具体用法?C++ string_view::at怎么用?C++ string_view::at使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类string_view
的用法示例。
在下文中一共展示了string_view::at方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: parse_token
string_view parse_token(string_view line, string_view::size_type& index) {
auto initial_index = index;
while ((!eol(line, index)) && (!is_whitespace(line.at(index)))) {
++index;
}
return string_view(&line[initial_index], index - initial_index);
}
示例3: parse_string
string_view parse_string(string_view line, string_view::size_type& index, char start_delimiter, char end_delimiter) {
string_view result;
string_view::size_type initial_index;
if (line.at(index) != start_delimiter) throw runtime_error("Wrong starting delimiter");
++index;
initial_index = index;
while (true) {
if (eol(line, index)) break;
if ((index > 0) && (line[index] == end_delimiter) && (line[index - 1] != '\\')) break;
++index;
}
if (eol(line, index)) throw runtime_error("Wrong ending delimiter");
assert(line.at(index) == end_delimiter);
++index;
return string_view(&line[initial_index], index - initial_index - 1);
}
示例4: path_match
path_match_result path_match(string_view input, string_view& match_contents)
{
if (input.length() < 2)
return path_match_result::invalid;
match_result result;
token_kind kind;
std::size_t length;
switch (input.at(0))
{
case '.':
result = match_simple_string(input.data() + 1, input.data() + input.size(), kind, length);
if (result == match_result::complete)
{
match_contents = input.substr(0, length + 1);
return path_match_result::simple_object;
}
else
{
return path_match_result::invalid;
}
case '[':
result = attempt_match(input.data() + 1, input.data() + input.length(), kind, length);
if (result == match_result::complete)
{
if (input.length() == length + 1 || input.at(1 + length) != ']')
return path_match_result::invalid;
if (kind != token_kind::string && kind != token_kind::number)
return path_match_result::invalid;
match_contents = input.substr(0, length + 2);
return path_match_result::brace;
}
else
{
return path_match_result::invalid;
}
default:
return path_match_result::invalid;
}
}
示例5: skip_whitespace
void skip_whitespace(string_view line, string_view::size_type& index) {
while ((!eol(line, index)) && (is_whitespace(line.at(index)))) {
++index;
}
}