UltraGrid
UltraGrid Low-Latency High-Resolution Transmission System
Loading...
Searching...
No Matches
string_view_utils.cpp
Go to the documentation of this file.
2
3std::string_view tokenize(std::string_view& str, char delim, char quot){
4 if(str.empty())
5 return {};
6
7 bool escaped = false;
8
9 auto token_begin = str.begin();
10 while(token_begin != str.end()){
11 if(*token_begin == quot)
12 escaped = !escaped;
13 else if(*token_begin != delim)
14 break;
15
16 token_begin++;
17 }
18
19 auto token_end = token_begin;
20 while(token_end != str.end()){
21 if(*token_end == quot){
22 str = std::string_view(token_end, str.end() - token_end);
23 str.remove_prefix(1); //remove the end quote
24 return std::string_view(token_begin, token_end - token_begin);
25 }
26 else if(*token_end == delim && !escaped)
27 break;
28
29 token_end++;
30 }
31
32 str = std::string_view(token_end, str.end() - token_end);
33
34 return std::string_view(token_begin, token_end - token_begin);
35}
std::string_view tokenize(std::string_view &str, char delim, char quot)
Tokenizer for string_view.