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


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

本文整理汇总了C++中std::string_view::substr方法的典型用法代码示例。如果您正苦于以下问题:C++ string_view::substr方法的具体用法?C++ string_view::substr怎么用?C++ string_view::substr使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在std::string_view的用法示例。


在下文中一共展示了string_view::substr方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: environment_expand

std::string environment_expand(std::string_view s) {
	std::string r;
	size_t start_pos = 0;
	size_t dollar_pos;
	while ((dollar_pos = s.find('$', start_pos)) != s.npos) {
		r += s.substr(start_pos, dollar_pos - start_pos);
		std::string varname;
		if (dollar_pos + 1 < s.length() && s[dollar_pos + 1] == '{') {
			size_t dollar_end = s.find('}', dollar_pos + 2);
			if (dollar_end == s.npos) {
				break;
			}
			varname = s.substr(dollar_pos + 2, dollar_end - (dollar_pos + 2));
			start_pos = dollar_end + 1;
		} else {
			size_t dollar_end = s.find_first_not_of("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_"sv, dollar_pos + 1);
			varname = s.substr(dollar_pos + 1, dollar_end - (dollar_pos + 1));
			start_pos = dollar_end;
		}
		if (const char *varval = getenv (varname.c_str ())) {
			r += varval;
		}
	}
	if (start_pos < s.length()) {
		r += s.substr(start_pos);
	}
	return r;
}
开发者ID:chys87,项目名称:tiary,代码行数:28,代码来源:misc.cpp

示例2: splitAt

inline std::pair<std::string_view, std::string_view> splitAt( std::string_view str, char splitter ){
	auto pos = str.find( splitter );
	if( pos == std::string_view::npos )
		return { str, {} };
	else
		return { str.substr( 0, pos ), str.substr( pos+1 ) };
}
开发者ID:spillerrec,项目名称:BooruSurfer2,代码行数:7,代码来源:StringViewUtils.hpp

示例3: make_pair

	std::pair<std::string_view, std::string_view> splitStringIn2(
		const std::string_view str, char delimiter)
	{
		auto pos = str.find(delimiter, 0);
		if (pos != std::string::npos)
		{
			return std::make_pair(str.substr(0, pos), str.substr(pos + 1, str.size() - pos));
		}
		return std::make_pair(str, "");
	}
开发者ID:dgengin,项目名称:DGEngine,代码行数:10,代码来源:Utils.cpp

示例4: splitAllOn

inline std::vector<std::string_view> splitAllOn( std::string_view str, char splitter ){
	std::vector<std::string_view> splits;
	
	size_t last=0, pos = 0;
	while( (pos = str.find(splitter, last)) != std::string_view::npos ){
		splits.push_back( str.substr( last, pos-last ) );
		last = pos+1;
	}
	splits.push_back( str.substr( last ) );
	
	return splits;
}
开发者ID:spillerrec,项目名称:BooruSurfer2,代码行数:12,代码来源:StringViewUtils.hpp

示例5: splitString

	std::vector<std::string> splitString(const std::string_view str, char delimiter)
	{
		std::vector<std::string> strings;

		std::string_view::size_type pos = 0;
		std::string_view::size_type prev = 0;
		while ((pos = str.find(delimiter, prev)) != std::string::npos)
		{
			strings.push_back(std::string(str.substr(prev, pos - prev)));
			prev = pos + 1;
		}

		strings.push_back(std::string(str.substr(prev)));

		return strings;
	}
开发者ID:dgengin,项目名称:DGEngine,代码行数:16,代码来源:Utils.cpp

示例6:

static std::string_view hash_from_url( std::string_view url ){
	size_t start = url.find_last_of( '/' ) + 1;
	size_t end = url.find_last_of( '.' );
	
	//Validate results
	if( start == string::npos || end == string::npos || start >= url.size() )
		return "";
	else
		return url.substr( start, end-start );
}
开发者ID:spillerrec,项目名称:BooruSurfer2,代码行数:10,代码来源:SanApi.cpp

示例7: StringFromHex

inline std::string StringFromHex(const std::string_view& input)
{
    assert((input.size() & 1) == 0);

    std::string result;
    result.reserve(input.size() / 2);
    for (size_t i = 0; i < input.size(); i += 2)
    {
        auto val = std::stoi(std::string(input.substr(i, 2)), 0, 16);
        result.push_back(val);
    }
    return result;
}
开发者ID:Wirlie,项目名称:OpenRCT2,代码行数:13,代码来源:StringHelpers.hpp

示例8: parseFunction

double Calculator::parseFunction(std::string_view &ref)
{
	try
	{
		std::string_view partStr = ref.substr(0, 3);

		if (partStr == std::string_view("sin"))
		{
			ref.remove_prefix(3);
			m_printStrategy->printFunctionName("sin");
			return sin(ParseArguments(ref) * M_PI / 180);
		}
		else if (partStr == std::string_view("cos"))
		{
			ref.remove_prefix(3);
			m_printStrategy->printFunctionName("cos");
			return cos(ParseArguments(ref) * M_PI / 180);
		}
		else
		{
			std::string_view partStr = ref.substr(0, 4);

			if (partStr == std::string_view("sqrt"))
			{
				ref.remove_prefix(4);
				m_printStrategy->printFunctionName("sqrt");
				return sqrt(ParseArguments(ref));
			}
		}
	}
	catch(const std::out_of_range&)
	{
		return std::numeric_limits<double>::quiet_NaN();
	}
	
	return std::numeric_limits<double>::quiet_NaN();
}
开发者ID:alisa-teplouhova,项目名称:Calc,代码行数:37,代码来源:Calculator.cpp

示例9: trim

inline std::string_view trim( std::string_view str ){
	auto first = str.find_first_not_of( ' ' );
	auto last  = str.find_last_not_of(  ' ' );
	auto chars_removed = first + (str.size()-last-1);
	return str.substr( first, str.size() - chars_removed );
}
开发者ID:spillerrec,项目名称:BooruSurfer2,代码行数:6,代码来源:StringViewUtils.hpp

示例10: logic_error

inline std::string_view removePostfix( std::string_view str, std::string_view postfix ){
	if( !ends_with( str, postfix ) )
		throw std::logic_error( std::string(str) + " does not end with " + std::string(postfix) );
	return str.substr( str.size() - postfix.size() );
}
开发者ID:spillerrec,项目名称:BooruSurfer2,代码行数:5,代码来源:StringViewUtils.hpp

示例11: ends_with

inline bool ends_with( std::string_view input, std::string_view match ){
	if( input.length() >= match.length() )
		return input.substr( input.size() - match.length() ) == match;
	return false;
}
开发者ID:spillerrec,项目名称:BooruSurfer2,代码行数:5,代码来源:StringViewUtils.hpp

示例12: starts_with

inline bool starts_with( std::string_view input, std::string_view match ){
	if( input.length() >= match.length() )
		return input.substr( 0, match.length() ) == match;
	return false;
}
开发者ID:spillerrec,项目名称:BooruSurfer2,代码行数:5,代码来源:StringViewUtils.hpp

示例13: removeSuffix

std::string_view removeSuffix(std::string_view a, std::string_view b)
{
    ASSERT(endsWith(a, b));
    return a.substr(0, a.size() - b.size());
}
开发者ID:emlai,项目名称:zenith,代码行数:5,代码来源:utility.cpp

示例14: endsWith

bool endsWith(std::string_view a, std::string_view b)
{
    return a.size() >= b.size() && a.substr(a.size() - b.size()) == b;
}
开发者ID:emlai,项目名称:zenith,代码行数:4,代码来源:utility.cpp

示例15: startsWith

bool startsWith(std::string_view a, std::string_view b)
{
    return a.size() >= b.size() && a.substr(0, b.size()) == b;
}
开发者ID:emlai,项目名称:zenith,代码行数:4,代码来源:utility.cpp


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