42 #include "Teuchos_MatrixMarket_split.hpp" 53 trim (
const std::string& in)
55 size_t start = in.find_first_not_of(
" \t");
56 size_t end = in.find_last_not_of(
" \t");
57 if (start == std::string::npos)
58 return std::string(
"");
60 return in.substr (start, end-start+1);
64 lowercase (
const std::string& in)
67 std::transform (in.begin(), in.end(), out.begin(), tolower);
72 trim_and_lowercase (
const std::string& in)
74 std::string out = trim (in);
75 std::string out2 (out);
76 std::transform (out.begin(), out.end(), out2.begin(), tolower);
82 endToken (
const std::pair<size_t, size_t>& range)
84 return range.first == std::string::npos && range.second == std::string::npos;
92 static std::pair<size_t, size_t>
93 nextToken (
const std::string& str,
94 const std::string& delimiters,
102 return make_pair (string::npos, string::npos);
105 const size_t first = str.find_first_not_of (delimiters, start);
106 if (first == string::npos)
108 return make_pair (string::npos, string::npos);
109 else if (first == size-1)
111 return make_pair (first, 1);
114 const size_t next = str.find_first_of (delimiters, start+1);
115 return make_pair (first, next - first);
119 std::vector<std::string>
120 split (
const std::string& str,
const std::string& delimiters,
const size_t start)
122 size_t curStart = start;
123 size_t size = str.size();
124 std::vector<std::string> tokens;
126 std::pair<size_t, size_t> token = nextToken (str, delimiters, curStart, size);
127 if (endToken (token)) {
130 tokens.push_back (str.substr (token.first, token.second));
131 curStart = token.first + token.second;
Teuchos implementation details.
The Teuchos namespace contains all of the classes, structs and enums used by Teuchos, as well as a number of utility routines.
Matrix Market file utilities.