8#ifndef convert_h_included
9#define convert_h_included
28 snprintf(intbuf,
sizeof(intbuf),
"%d", i_in);
29 return std::string(intbuf);
36 snprintf(intbuf,
sizeof(intbuf),
"%u", i_in);
37 return std::string(intbuf);
41 inline std::string
toString(
unsigned long i_in)
44 snprintf(longbuf,
sizeof(longbuf),
"%lu", i_in);
45 return std::string(longbuf);
51 return std::string(i_in);
55 inline int atoi(
const std::string &s_in)
57 return ::atoi(s_in.c_str());
61 inline std::string
toHex(
const std::string &s)
63 const char hexchars[] =
"0123456789abcdef";
65 for (std::string::const_iterator i = s.begin(); i != s.end(); ++i) {
66 unsigned char c = (
unsigned char)*i;
67 tmp += hexchars[((c & 0xf0) >> 4)];
68 tmp += hexchars[c & 0x0f];
75 inline std::string
fromHex(
const std::string &s)
78 char hexchars[] =
"0123456789abcdef";
80 for (std::string::const_iterator i = s.begin();
81 i != s.end() && i + 1 != s.end(); i += 2) {
84 unsigned char d = *(i + 1);
87 if ((t = strchr(hexchars, c)) == 0)
return "out of range";
88 n = (t - hexchars) << 4;
90 if ((t = strchr(hexchars, d)) == 0)
return "out of range";
93 if (n >= 0 && n <= 255)
96 return "out of range";
105 for (std::string::const_iterator i = s_in.begin(); i != s_in.end(); ++i) {
106 unsigned char c = (
unsigned char)*i;
107 if (c <= 31 || c >= 127 || c ==
'\"' || c ==
'\\')
108 return "{" +
toString(s_in.length()) +
"}\r\n" + s_in;
111 return "\"" + s_in +
"\"";
117 for (std::string::iterator i = input.begin(); i != input.end(); ++i)
124 for (std::string::iterator i = input.begin(); i != input.end(); ++i)
129 inline void chomp(std::string &s_in,
const std::string &chars =
" \t\r\n")
131 int n = s_in.length();
132 while (n > 1 && chars.find(s_in[n - 1]) != std::string::npos)
133 s_in.resize(n-- - 1);
137 inline void trim(std::string &s_in,
const std::string &chars =
" \t\r\n")
139 while (s_in !=
"" && chars.find(s_in[0]) != std::string::npos)
140 s_in = s_in.substr(1);
145 inline const std::string
unfold(
const std::string &a,
146 bool removecomment =
true)
149 bool incomment =
false;
150 bool inquotes =
false;
151 for (std::string::const_iterator i = a.begin(); i != a.end(); ++i) {
152 unsigned char c = (
unsigned char)*i;
153 if (!inquotes && removecomment) {
157 }
else if (c ==
')') {
159 }
else if (c != 0x0a && c != 0x0d) {
162 }
else if (c != 0x0a && c != 0x0d) {
168 inquotes = !inquotes;
177 inline void split(
const std::string &s_in,
const std::string &delim,
178 std::vector<std::string> &dest,
bool skipempty =
true)
181 for (std::string::const_iterator i = s_in.begin(); i != s_in.end(); ++i) {
182 if (delim.find(*i) != std::string::npos) {
183 if (!skipempty || token !=
"")
184 dest.push_back(token);
191 dest.push_back(token);
196 std::vector<std::string> &dest,
bool skipempty =
true)
198 static const std::string delim =
",";
200 bool inquote =
false;
201 for (std::string::const_iterator i = s_in.begin(); i != s_in.end(); ++i) {
202 if (inquote && *i ==
'\"') inquote =
false;
203 else if (!inquote && *i ==
'\"') inquote =
true;
205 if (!inquote && delim.find(*i) != std::string::npos) {
206 if (!skipempty || token !=
"") dest.push_back(token);
212 dest.push_back(token);
218 if (s_in.find(
"..") != std::string::npos)
return "";
220 if (s_in.length() >= 5) {
221 std::string a = s_in.substr(0, 5);
223 return a ==
"INBOX" ?
224 a + (s_in.length() > 5 ? s_in.substr(5) :
"") : s_in;
231 inline std::string
toRegex(
const std::string &s_in,
char delimiter)
233 std::string regex =
"^";
234 for (std::string::const_iterator i = s_in.begin(); i != s_in.end(); ++i) {
235 if (*i ==
'.' || *i ==
'[' || *i ==
']' || *i ==
'{' || *i ==
'}' ||
236 *i ==
'(' || *i ==
')' || *i ==
'^' || *i ==
'$' || *i ==
'?' ||
237 *i ==
'+' || *i ==
'\\') {
240 }
else if (*i ==
'*')
242 else if (*i ==
'%') {
253 if (regex[regex.length() - 1] ==
'?')
254 regex[regex.length() - 1] =
'$';
276 std::string
popString(
unsigned int size);
281 void unpopStr(
const std::string &s);
284 const std::string &
str(
void)
const;
287 unsigned int getSize(
void)
const;
Declaration of the Address class.
void unpopStr(const std::string &s)
const std::string & str(void) const
std::string popString(unsigned int size)
unsigned int getSize(void) const
BincStream & operator<<(std::ostream &(*)(std::ostream &))
std::string toImapString(const std::string &s_in)
std::string toString(int i_in)
void splitAddr(const std::string &s_in, std::vector< std::string > &dest, bool skipempty=true)
std::string toCanonMailbox(const std::string &s_in)
std::string fromHex(const std::string &s)
std::string toRegex(const std::string &s_in, char delimiter)
const std::string unfold(const std::string &a, bool removecomment=true)
void chomp(std::string &s_in, const std::string &chars=" \t\r\n")
int atoi(const std::string &s_in)
void split(const std::string &s_in, const std::string &delim, std::vector< std::string > &dest, bool skipempty=true)
void uppercase(std::string &input)
void lowercase(std::string &input)
void trim(std::string &s_in, const std::string &chars=" \t\r\n")
std::string toHex(const std::string &s)