7 #ifndef _MIMETIC_STRINGUTILS_H_ 8 #define _MIMETIC_STRINGUTILS_H_ 18 extern const std::string nullstring;
20 struct ichar_traits :
public std::char_traits<char>
22 static bool eq (
const char_type & c1,
const char_type& c2)
23 {
return (toupper(c1) == toupper(c2)); }
24 static bool ne (
const char_type& c1,
const char_type& c2)
25 {
return (toupper(c1) != toupper(c2)); }
26 static bool lt (
const char_type& c1,
const char_type& c2)
27 {
return (toupper(c1) < toupper(c2)); }
28 static int compare (
const char_type* s1,
const char_type* s2,
size_t n)
30 for(
size_t i=0; i < n; ++i)
31 if(toupper(s1[i]) != toupper(s2[i]))
32 return (toupper(s1[i]) < toupper(s2[i])) ?-1: 1;
35 static const char* find(
const char* s,
int n,
char a )
37 while( n-- > 0 && tolower(*s) != tolower(a) )
46 struct istring:
public string
51 istring(
const std::string& right)
54 explicit istring(
const allocator_type& al)
57 istring(
const istring& right)
60 istring(
const istring& right, size_type roff, size_type count = npos)
61 : string(right, roff, count)
63 istring(
const istring& right, size_type roff, size_type count,
64 const allocator_type& al)
65 : string(right, roff, count, al)
67 istring(
const value_type *ptr, size_type count)
70 istring(
const value_type *ptr, size_type count,
const allocator_type& al)
71 : string(ptr, count, al)
73 istring(
const value_type *ptr)
76 istring(
const value_type *ptr,
const allocator_type& al)
79 istring(size_type count, value_type ch)
82 istring(size_type count, value_type ch,
const allocator_type& al)
86 istring(InIt first, InIt last)
90 istring(InIt first, InIt last,
const allocator_type& al)
91 : string(first, last, al)
96 inline bool operator==(
const istring& is,
const std::string& s)
98 return (0 == ichar_traits::compare(is.c_str(),s.c_str(),
99 std::max(is.length(),s.length())) );
102 inline bool operator!=(
const istring& is,
const std::string& s)
104 return (0 != ichar_traits::compare(is.c_str(),s.c_str(),
105 std::max(is.length(),s.length())) );
108 inline bool operator!=(
const istring& is,
const char* str)
110 return (0 != ichar_traits::compare(is.c_str(),str,
111 std::max(is.length(),::strlen(str))) );
114 inline bool operator==(
const istring& is,
const char* str)
116 return (0 == ichar_traits::compare(is.c_str(),str,
117 std::max(is.length(),::strlen(str))) );
120 inline std::string dquoted(
const std::string& s)
122 return "\"" + s +
"\"";
125 inline std::string parenthed(
const std::string& s)
127 return "(" + s +
")";
133 int len = s.length();
136 if(s[0] ==
'"' && s[len-1] ==
'"')
137 return std::string(s, 1, len-2);
145 std::string
canonical(
const std::string& s,
bool no_ws =
false);
153 int beg = 0, end = s.length();
154 for(; beg < end; ++beg)
155 if(s[beg] !=
' ' && s[beg] !=
'\t')
157 end = s.length() - 1;
158 for(; end > beg; --end)
159 if(s[end] !=
' ' && s[end] !=
'\t')
161 s.assign(std::string(s, beg, end - beg + 1));
std::string remove_dquote(const std::string &s)
removes double quotes
Definition: strutils.h:131
std::string canonical(const std::string &s, bool no_ws=false)
std::string remove_external_blanks(const std::string &in)
removes leading and trailing blanks
Definition: strutils.h:148