37 inline void swaperase(
typename std::vector<T>& vect,
const typename std::vector<T>::iterator& it)
56 inline bool swaperase(
typename std::vector<T>& vect,
const T& val)
58 const typename std::vector<T>::iterator it = std::find(vect.begin(), vect.end(), val);
74 inline const char* tocstr(
const char* str)
83 inline const char* tocstr(
const std::string& str)
93 template <
typename S1,
typename S2>
94 inline bool equalsci(
const S1& str1,
const S2& str2)
96 return (!strcasecmp(tocstr(str1), tocstr(str2)));
104 template<
typename Collection>
105 inline std::string join(
const Collection& sequence,
char separator =
' ')
108 if (sequence.empty())
111 for (
typename Collection::const_iterator iter = sequence.begin(); iter != sequence.end(); ++iter)
112 joined.append(ConvToStr(*iter)).push_back(separator);
114 joined.erase(joined.end() - 1);
124 template<
typename CharT,
typename Traits,
typename Alloc>
125 inline bool replace(std::basic_string<CharT, Traits, Alloc>& str,
const std::basic_string<CharT, Traits, Alloc>& target,
const std::basic_string<CharT, Traits, Alloc>& replacement)
127 const typename std::basic_string<CharT, Traits, Alloc>::size_type p = str.find(target);
128 if (p == std::basic_string<CharT, Traits, Alloc>::npos)
130 str.replace(p, target.size(), replacement);
139 template<
typename CharT,
typename Traits,
typename Alloc>
140 inline void replace_all(std::basic_string<CharT, Traits, Alloc>& str,
const std::basic_string<CharT, Traits, Alloc>& target,
const std::basic_string<CharT, Traits, Alloc>& replacement)
145 typename std::basic_string<CharT, Traits, Alloc>::size_type p = 0;
146 while ((p = str.find(target, p)) != std::basic_string<CharT, Traits, Alloc>::npos)
148 str.replace(p, target.size(), replacement);
149 p += replacement.size();
157 template <
typename T>
160 void operator()(T* o)
179 template <
template<
typename,
typename>
class Cont,
typename T,
typename Alloc>
180 inline void delete_all(
const Cont<T*, Alloc>& cont)
189 void delete_zero(T*& pr)
202 template <
template<
typename,
typename>
class Cont,
typename T,
typename Alloc>
203 inline bool erase(Cont<T, Alloc>& cont,
const T& val)
205 const typename Cont<T, Alloc>::iterator it = std::find(cont.begin(), cont.end(), val);
206 if (it != cont.end())
220 template <
template<
typename,
typename>
class Cont,
typename T,
typename Alloc>
221 inline bool isin(
const Cont<T, Alloc>& cont,
const T& val)
223 return (std::find(cont.begin(), cont.end(), val) != cont.end());
233 template <
char from,
char to,
char esc>
234 inline void escape(
const std::string& str, std::string& out)
236 for (std::string::const_iterator i = str.begin(); i != str.end(); ++i)
258 template <
char from,
char to>
259 inline void escape(
const std::string& str, std::string& out)
261 escape<from, to, '\\'>(str, out);
270 template<
char from,
char to,
char esc>
271 inline bool unescape(
const std::string& str, std::string& out)
273 for (std::string::const_iterator i = str.begin(); i != str.end(); ++i)
285 else if (nextc != to)
301 template <
char from,
char to>
302 inline bool unescape(
const std::string& str, std::string& out)
304 return unescape<from, to, '\\'>(str, out);