Advertisement
Petrovi4

SplitIntoWordsView

Jul 31st, 2022
975
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.48 KB | None | 0 0
  1. std::vector<std::string_view> SplitIntoWordsView(std::string_view str) {
  2.     std::vector<std::string_view> result;
  3.     str.remove_prefix(std::min(str.size(), str.find_first_not_of(' ')));
  4.  
  5.     while (!str.empty()) {
  6.        
  7.         auto space = str.find(' ');
  8.         result.push_back(space == str.npos ? str.substr(0, str.size()) : str.substr(0, space));
  9.        
  10.         str.remove_prefix(std::min(str.size(), str.find_first_not_of(' ', space)));
  11.     }
  12.     return result;
  13. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement