9 Compares two strings, ignoring case.
11 @param s1 First string
12 @param s2 Second string
14 @return -1 if s1<s2, 0 if s1==s2, 1 if s1>s2
16 int strcasecmp(const string &s1, const string &s2)
18 string::const_iterator i1=s1.begin();
19 string::const_iterator i2=s2.begin();
20 for(; (i1!=s1.end() && i2!=s2.end()); ++i1, ++i2)
22 const char c1=::tolower(*i1);
23 const char c2=::tolower(*i2);
24 if(c1!=c2) return c1-c2;
26 if(i1!=s1.end()) return *i1;
27 if(i2!=s2.end()) return -*i2;
32 Returns a lowercase copy of the given string.
34 string tolower(const string &str)
37 transform(result.begin(), result.end(), result.begin(), ::tolower);
42 Returns an uppercase copy of the given string.
44 string toupper(const string &str)
47 transform(result.begin(), result.end(), result.begin(), ::toupper);
52 Splits a string to parts.
54 @param str String to be split
55 @param sep A set of separator characters
56 @param allow_empty Whether or not to produce empty parts for sequences of
57 more than one separator character
59 vector<string> split(const string &str, const string &sep, bool allow_empty)
61 vector<string> result;
62 unsigned start=str.find_first_not_of(sep);
63 while(start<str.size())
65 unsigned end=str.find_first_of(sep, start);
66 result.push_back(str.substr(start, end-start));
67 if(end==string::npos) break;
71 start=str.find_first_not_of(sep, end);
76 vector<string> split(const string &str, char sep, bool allow_empty)
78 return split(str, string(1,sep), allow_empty);
82 Builds a single string from the strings in the given sequence by concatenating
85 @param seq A sequence of strings
86 @param sep Separator to be inserted between strings
89 string join(const T &seq, const string &sep)
92 for(typename T::const_iterator i=seq.begin(); i!=seq.end(); ++i)
101 template string join<list<string> >(const list<string> &, const string &);
102 template string join<vector<string> >(const vector<string> &, const string &);
105 Returns a copy of the given string with leading and trailing whitespace
108 string strip(const string &s)
111 if(!result.erase(0, result.find_first_not_of(" \t\n")).empty())
112 result.erase(result.find_last_not_of(" \t\n")+1);