mirror of
https://github.com/openmc-dev/openmc.git
synced 2026-07-27 05:35:49 -04:00
Combined string_functions.h and string_utils.h
This commit is contained in:
parent
7d6ab8d72d
commit
97634d59ad
10 changed files with 90 additions and 98 deletions
|
|
@ -1,49 +1,24 @@
|
|||
#ifndef OPENMC_STRING_UTILS_H
|
||||
#define OPENMC_STRING_UTILS_H
|
||||
|
||||
#include <algorithm>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace openmc {
|
||||
|
||||
inline std::vector<std::string>
|
||||
split(const std::string& in)
|
||||
{
|
||||
std::vector<std::string> out;
|
||||
std::string& strtrim(std::string& s);
|
||||
|
||||
for (int i = 0; i < in.size(); ) {
|
||||
// Increment i until we find a non-whitespace character.
|
||||
if (std::isspace(in[i])) {
|
||||
i++;
|
||||
char* strtrim(char* c_str);
|
||||
|
||||
} else {
|
||||
// Find the next whitespace character at j.
|
||||
int j = i + 1;
|
||||
while (j < in.size() && std::isspace(in[j]) == 0) {j++;}
|
||||
void to_lower(std::string& str);
|
||||
|
||||
// Push-back everything between i and j.
|
||||
out.push_back(in.substr(i, j-i));
|
||||
i = j + 1; // j is whitespace so leapfrog to j+1
|
||||
}
|
||||
}
|
||||
int word_count(std::string const& str);
|
||||
|
||||
return out;
|
||||
}
|
||||
std::vector<std::string> split(const std::string& in);
|
||||
|
||||
inline bool
|
||||
ends_with(const std::string& value, const std::string& ending)
|
||||
{
|
||||
if (ending.size() > value.size()) return false;
|
||||
return std::equal(ending.rbegin(), ending.rend(), value.rbegin());
|
||||
}
|
||||
bool ends_with(const std::string& value, const std::string& ending);
|
||||
|
||||
inline bool
|
||||
starts_with(const std::string& value, const std::string& beginning)
|
||||
{
|
||||
if (beginning.size() > value.size()) return false;
|
||||
return std::equal(beginning.begin(), beginning.end(), value.begin());
|
||||
}
|
||||
bool starts_with(const std::string& value, const std::string& beginning);
|
||||
|
||||
} // namespace openmc
|
||||
#endif // OPENMC_STRING_UTILS_H
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue