QMCPACK
qmcplusplus::modernstrutil Namespace Reference

prevent clash with string_utils.h More...

Functions

std::vector< std::string_view > split (const string_view s, const string_view delimiters)
 
std::string_view strip (const string_view s)
 
std::vector< std::string_view > split (const std::string_view s, const std::string_view delimiters)
 return string_view tokens More...
 
std::string_view strip (const std::string_view s)
 remove white space from each beginning and end of string_view More...
 

Detailed Description

prevent clash with string_utils.h

Function Documentation

◆ split() [1/2]

std::vector<std::string_view> qmcplusplus::modernstrutil::split ( const string_view  s,
const string_view  delimiters 
)

Definition at line 32 of file ModernStringUtils.cpp.

References qmcplusplus::Units::time::s.

Referenced by AnotherInput::getTokens(), qmcplusplus::parseGridInput(), ReferencePointsInput::readRefPointsXML(), CustomTestInput::setFromStreamCustom(), and qmcplusplus::TEST_CASE().

33 {
34  std::vector<std::string_view> tokens;
35  size_t right = 0;
36  size_t left = 0;
37  while (true)
38  {
39  left = s.find_first_not_of(delimiters, right);
40  if (left == s.npos)
41  break;
42  else
43  right = s.find_first_of(delimiters, left);
44  if (right == s.npos)
45  right = s.size();
46  size_t count = right - left;
47  tokens.push_back(s.substr(left, count));
48  }
49  return tokens;
50 }

◆ split() [2/2]

std::vector<std::string_view> qmcplusplus::modernstrutil::split ( const std::string_view  s,
const std::string_view  delimiters 
)

return string_view tokens

◆ strip() [1/2]

std::string_view qmcplusplus::modernstrutil::strip ( const std::string_view  s)

remove white space from each beginning and end of string_view

◆ strip() [2/2]

std::string_view qmcplusplus::modernstrutil::strip ( const string_view  s)

Definition at line 52 of file ModernStringUtils.cpp.

References qmcplusplus::Units::time::s.

Referenced by ReferencePointsInput::readRefPointsXML(), and qmcplusplus::TEST_CASE().

53 {
54  std::string_view delimiters = " \t\n\0";
55  size_t left = s.find_first_not_of(delimiters, 0);
56  if (left != s.npos) {
57  size_t right = s.find_last_not_of(delimiters, s.npos);
58  return s.substr(left, right - left + 1);
59  }
60  else
61  return std::string_view{};
62 }