本文整理汇总了C++中std::string_view::find方法的典型用法代码示例。如果您正苦于以下问题:C++ string_view::find方法的具体用法?C++ string_view::find怎么用?C++ string_view::find使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类std::string_view
的用法示例。
在下文中一共展示了string_view::find方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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 ) };
}
示例3: quote_this
std::string quote_this(std::string_view arg)
{
if (arg.size() && arg[0] != '"' && arg.find(' ') != std::string::npos)
{
return '"' + std::string(arg) + '"';
}
return std::string(arg);
}
示例4: 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, "");
}
示例5: 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;
}
示例6: add
void message_headers::add(std::string_view name, std::string_view value)
{
std::unordered_map<std::string, std::string>::iterator iter
(fields_.find(name.data()));
// if the field name was found previously
if (iter != fields_.end())
{
char separator((name.find(COOKIE) != std::string::npos) ? ';' : ',');
iter->second.append({separator});
iter->second.append(value);
}
else
fields_.insert(std::unordered_map<std::string, std::string>::value_type
(name, value));
}
示例7: 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;
}