本文整理汇总了C++中std::string_view::find_first_not_of方法的典型用法代码示例。如果您正苦于以下问题:C++ string_view::find_first_not_of方法的具体用法?C++ string_view::find_first_not_of怎么用?C++ string_view::find_first_not_of使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类std::string_view
的用法示例。
在下文中一共展示了string_view::find_first_not_of方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
}
示例2: 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 );
}
示例3: trim
std::string_view trim(std::string_view str)
{
str.remove_prefix(str.find_first_not_of(' '));
str.remove_suffix(str.size() - (str.find_last_not_of(' ') + 1));
return str;
}