本文整理汇总了C++中std::experimental::string_view::substr方法的典型用法代码示例。如果您正苦于以下问题:C++ string_view::substr方法的具体用法?C++ string_view::substr怎么用?C++ string_view::substr使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类std::experimental::string_view
的用法示例。
在下文中一共展示了string_view::substr方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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;
}
示例3: 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', "" );
}
}
}
示例4: toBeLoggedRuntime
bool Tial::Utility::Logger::toBeLoggedRuntime(Level level, const std::experimental::string_view &module) {
auto moduleLevel = levels.find(module.to_string());
if(moduleLevel == levels.end()) {
auto sep = module.rfind("::");
if(sep == module.npos)
return level >= globalLevel;
return toBeLoggedRuntime(level, module.substr(0, sep));
}
return level >= moduleLevel->second;
}