当前位置: 首页>>代码示例>>C++>>正文


C++ string_view::substr方法代码示例

本文整理汇总了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
}
开发者ID:32bitmicro,项目名称:riscv-libcxx,代码行数:49,代码来源:substr.pass.cpp

示例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;
		}
开发者ID:mplucinski,项目名称:Tial,代码行数:16,代码来源:Algorithm.hpp

示例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', "" );
    }
    }
    
}
开发者ID:massa,项目名称:string_view,代码行数:46,代码来源:substr.pass.cpp

示例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;
}
开发者ID:mplucinski,项目名称:Tial,代码行数:11,代码来源:Logger.cpp


注:本文中的std::experimental::string_view::substr方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。