18 #ifndef _SMALLUT_H_INCLUDED_ 19 #define _SMALLUT_H_INCLUDED_ 31 void smallut_init_mt();
33 #ifndef SMALLUT_DISABLE_MACROS 35 #define MIN(A,B) (((A)<(B)) ? (A) : (B)) 38 #define MAX(A,B) (((A)>(B)) ? (A) : (B)) 41 #define deleteZ(X) {delete X;X = 0;} 44 #define PRETEND_USE(var) ((void)(var)) 49 extern int stringicmp(
const std::string& s1,
const std::string& s2);
56 bool operator()(
const std::string& s2) {
57 return stringicmp(m_s1, s2) == 0;
59 const std::string& m_s1;
62 extern int stringlowercmp(
const std::string& s1,
63 const std::string& s2);
64 extern int stringuppercmp(
const std::string& s1,
65 const std::string& s2);
67 extern void stringtolower(std::string& io);
68 extern std::string stringtolower(
const std::string& io);
69 extern void stringtoupper(std::string& io);
70 extern std::string stringtoupper(
const std::string& io);
71 extern bool beginswith(
const std::string& bg,
const std::string& sml);
92 extern bool parsedateinterval(
const std::string& s,
DateInterval *di);
93 extern int monthdays(
int mon,
int year);
115 template <
class T>
bool stringToStrings(
const std::string& s, T& tokens,
116 const std::string& addseps =
"");
121 template <
class T>
void stringsToString(
const T& tokens, std::string& s);
122 template <
class T> std::string stringsToString(
const T& tokens);
129 template <
class T>
void stringsToCSV(
const T& tokens, std::string& s,
135 extern void stringToTokens(
const std::string& s,
136 std::vector<std::string>& tokens,
137 const std::string& delims =
" \t",
138 bool skipinit =
true);
141 extern void stringSplitString(
const std::string& str,
142 std::vector<std::string>& tokens,
143 const std::string& sep);
146 extern bool stringToBool(
const std::string& s);
150 extern void trimstring(std::string& s,
const char *ws =
" \t");
151 extern void rtrimstring(std::string& s,
const char *ws =
" \t");
152 extern void ltrimstring(std::string& s,
const char *ws =
" \t");
155 extern std::string escapeHtml(
const std::string& in);
158 extern std::string makeCString(
const std::string& in);
161 extern std::string neutchars(
const std::string& str,
const std::string& chars,
163 extern void neutchars(
const std::string& str, std::string& out,
164 const std::string& chars,
char rep =
' ');
168 extern std::string escapeShell(
const std::string& in);
172 extern std::string truncate_to_word(
const std::string& input,
173 std::string::size_type maxlen);
175 void ulltodecstr(uint64_t val, std::string& buf);
176 void lltodecstr(int64_t val, std::string& buf);
177 std::string lltodecstr(int64_t val);
178 std::string ulltodecstr(uint64_t val);
181 std::string displayableBytes(int64_t size);
184 std::string breakIntoLines(
const std::string& in,
unsigned int ll = 100,
185 unsigned int maxlines = 50);
188 bool pcSubst(
const std::string& in, std::string& out,
189 const std::map<char, std::string>& subs);
191 bool pcSubst(
const std::string& in, std::string& out,
192 const std::map<std::string, std::string>& subs);
195 void catstrerror(std::string *reason,
const char *what,
int _errno);
200 time_t portable_timegm(
struct tm *tm);
202 inline void leftzeropad(std::string& s,
unsigned len)
204 if (s.length() && s.length() < len) {
205 s = s.insert(0, len - s.length(),
'0');
211 extern std::string hexprint(
const std::string& in,
char separ= 0);
213 #ifndef SMALLUT_NO_REGEX 219 enum Flags {SRE_NONE = 0, SRE_ICASE = 1, SRE_NOSUB = 2};
221 SimpleRegexp(
const std::string& exp,
int flags,
int nmatch = 0);
224 bool simpleMatch(
const std::string& val)
const;
227 std::string getMatch(
const std::string& val,
int i)
const;
229 bool operator() (
const std::string& val)
const;
232 std::string simpleSub(
const std::string& input,
const std::string& repl);
242 #endif // SMALLUT_NO_REGEX 248 CharFlags(
int v,
const char *y,
const char *n=
nullptr)
249 : value(v), yesname(y), noname(n) {}
257 #define CHARFLAGENTRY(NM) {NM, #NM} 260 extern std::string flagsToString(
const std::vector<CharFlags>&,
264 extern std::string valToString(
const std::vector<CharFlags>&,
unsigned int val);
Definition: smallut.h:217
Definition: smallut.cpp:1207
Utilities for printing names for defined values (Ex: O_RDONLY->"O_RDONLY")
Definition: smallut.h:247