20 #ifndef JDFTX_CORE_ISTRING_H 21 #define JDFTX_CORE_ISTRING_H 33 {
static bool eq(
char c1,
char c2 ) {
return toupper(c1) == toupper(c2); }
34 static bool ne(
char c1,
char c2 ) {
return toupper(c1) != toupper(c2); }
35 static bool lt(
char c1,
char c2 ) {
return toupper(c1) < toupper(c2); }
36 static int compare(
const char* s1,
const char* s2,
size_t n ) {
return strncasecmp( s1, s2, n ); }
37 static const char* find(
const char* s,
int n,
char a )
38 {
for(
int i=0; i<n; i++)
if(toupper(s[i])==toupper(a))
return s+i;
42 typedef std::basic_string<char, ichar_traits>
string;
45 inline void trim(
string& s)
47 size_t endNonWS = s.find_last_not_of(
" \t\n\r");
48 if(endNonWS != string::npos)
51 s.erase(0, s.find_first_not_of(
" \t\n\r"));
57 inline istream& operator>>(istream& is,
string& str) {
std::string tmp; is >> tmp; str.assign(tmp.c_str());
return is; }
58 inline ostream& operator<<(ostream& os,
const string& str) { os << str.c_str();
return os; }
59 inline istream& getline (istream& is,
string& str,
char delim=
'\n')
61 getline(is, tmp, delim);
62 str.assign(tmp.c_str());
68 explicit ifstream(
const string& fname) : std::ifstream(fname.c_str()) {}
69 void open(
const string& fname) { std::ifstream::open(fname.c_str()); }
73 explicit ofstream(
const string& fname) : std::ofstream(fname.c_str()) {}
74 void open(
const string& fname) { std::ofstream::open(fname.c_str()); }
80 void str(
const string& s) { std::istringstream::str(
std::string(s.c_str())); }
83 {
string str()
const {
return string(std::ostringstream::str().c_str()); }
void trim(string &s)
Remove leading and trailing spaces from a string.
Definition: string.h:45
std::basic_string< char, ichar_traits > string
Case-insensitive string.
Definition: string.h:42
Case insensitive character trait.
Definition: string.h:32