Beispiel #1
0
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;
}
Beispiel #2
0
	void replaceStringInPlace(std::string& subject, const std::string_view search, const std::string_view replace)
	{
		size_t pos = 0;
		while ((pos = subject.find(search, pos)) != std::string::npos)
		{
			subject.replace(pos, search.length(), replace);
			pos += replace.length();
		}
	}
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;
}
 size_t length() const {
   return str.length();
 }
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;
}