5 #include <Rivet/Math/Math.hh>
14 inline int nocase_cmp(
const string& s1,
const string& s2) {
15 string::const_iterator it1 = s1.begin();
16 string::const_iterator it2 = s2.begin();
17 while ( (it1 != s1.end()) && (it2 != s2.end()) ) {
18 if(::toupper(*it1) != ::toupper(*it2)) {
20 return (::toupper(*it1) < ::toupper(*it2)) ? -1 : 1;
26 size_t size1 = s1.size(), size2 = s2.size();
28 if (size1 == size2)
return 0;
29 return (size1 < size2) ? -1 : 1;
33 inline string toLower(
const string& s) {
35 transform(out.begin(), out.end(), out.begin(), (int(*)(int)) tolower);
40 inline string toUpper(
const string& s) {
42 std::transform(out.begin(), out.end(), out.begin(), (int(*)(int)) toupper);
47 inline bool startsWith(
const string& s,
const string& start) {
48 if (s.length() < start.length())
return false;
49 return s.substr(0, start.length()) == start;
54 inline bool endsWith(
const string& s,
const string& end) {
55 if (s.length() < end.length())
return false;
56 return s.substr(s.length() - end.length()) == end;
62 inline vector<string>
pathsplit(
const string& path) {
63 const string delim =
":";
65 string tmppath = path;
67 const size_t delim_pos = tmppath.find(delim);
68 if (delim_pos == string::npos)
break;
69 const string dir = tmppath.substr(0, delim_pos);
70 if (dir.length()) dirs.push_back(dir);
71 tmppath.replace(0, delim_pos+1,
"");
73 if (tmppath.length()) dirs.push_back(tmppath);
78 inline vector<string>
split(
const string& path,
const string& UNUSED(delim) =
":") {
85 inline string pathjoin(
const vector<string>& paths) {
86 const string delim =
":";
88 for (vector<string>::const_iterator is = paths.begin(); is != paths.end(); ++is) {
89 if (rtn.size() > 0) rtn += delim;
104 template <
typename T>
105 inline void operator+=(set<T>& s1,
const set<T>& s2) {
106 for (
typename set<T>::const_iterator s = s2.begin(); s != s2.end(); ++s) {
111 template <
typename T>
112 inline set<T> operator+(
const set<T>& s1,
const set<T>& s2) {
118 template <
typename T>
119 inline string join(
const set<T>& s,
const string& sep =
" ") {
122 for (
typename set<T>::const_iterator it = s.begin(); it != s.end(); ++it) {
134 template <
typename T>
135 inline void operator+=(vector<T>& v1,
const vector<T>& v2) {
136 for (
typename vector<T>::const_iterator s = v2.begin(); s != v2.end(); ++s) {
141 template <
typename T>
142 inline vector<T> operator+(
const vector<T>& v1,
const vector<T>& v2) {
148 template <
typename T>
149 inline string join(
const vector<T>& v,
const string& sep =
" ") {
151 for (
size_t i = 0; i < v.size(); ++i) {
152 if (i != 0) out << sep;
string pathjoin(const vector< string > &paths)
Join several filesystem paths together with a delimiter character. Note that this does NOT join path ...
Definition: Utils.hh:85
vector< string > split(const string &path, const string &UNUSED(delim)=":")
Definition: Utils.hh:78
vector< string > pathsplit(const string &path)
Split a path string with colon delimiters. Ignores zero-length substrings. Designed for getting eleme...
Definition: Utils.hh:62
bool endsWith(const string &s, const string &end)
Check whether a string end is found at the end of s.
Definition: Utils.hh:54