summaryrefslogtreecommitdiff
path: root/src/include/convert.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/include/convert.h')
-rw-r--r--src/include/convert.h109
1 files changed, 53 insertions, 56 deletions
diff --git a/src/include/convert.h b/src/include/convert.h
index cea2906..9e51027 100644
--- a/src/include/convert.h
+++ b/src/include/convert.h
@@ -2,22 +2,23 @@
* @file convert.h
* @brief Declaration of miscellaneous convertion functions.
* @author Andreas Aardal Hanssen
- * @date 2002-2005
+ * @date 2002-2005
* ----------------------------------------------------------------- **/
#ifndef convert_h_included
#define convert_h_included
+#include "address.h"
+#include "depot.h"
+
#include <cstring>
-#include <string>
-#include <vector>
#include <iomanip>
#include <iostream>
+#include <string>
+#include <vector>
#include <stdio.h>
-#include <sys/stat.h>
-#include "address.h"
-#include "depot.h"
+#include <sys/stat.h>
namespace Binc {
@@ -67,7 +68,7 @@ namespace Binc {
tmp += hexchars[((c & 0xf0) >> 4)];
tmp += hexchars[c & 0x0f];
}
-
+
return tmp;
}
@@ -77,8 +78,7 @@ namespace Binc {
// const
char hexchars[] = "0123456789abcdef";
std::string tmp;
- for (std::string::const_iterator i = s.begin();
- i != s.end() && i + 1 != s.end(); i += 2) {
+ for (std::string::const_iterator i = s.begin(); i != s.end() && i + 1 != s.end(); i += 2) {
int n;
unsigned char c = *i;
unsigned char d = *(i + 1);
@@ -91,14 +91,14 @@ namespace Binc {
n += (t - hexchars);
if (n >= 0 && n <= 255)
- tmp += (char) n;
+ tmp += (char)n;
else
return "out of range";
}
return tmp;
}
-
+
//----------------------------------------------------------------------
inline std::string toImapString(const std::string &s_in)
{
@@ -142,8 +142,7 @@ namespace Binc {
}
//----------------------------------------------------------------------
- inline const std::string unfold(const std::string &a,
- bool removecomment = true)
+ inline const std::string unfold(const std::string &a, bool removecomment = true)
{
std::string tmp;
bool incomment = false;
@@ -152,55 +151,55 @@ namespace Binc {
unsigned char c = (unsigned char)*i;
if (!inquotes && removecomment) {
if (c == '(') {
- incomment = true;
+ incomment = true;
tmp += " ";
} else if (c == ')') {
- incomment = false;
+ incomment = false;
} else if (c != 0x0a && c != 0x0d) {
- tmp += *i;
+ tmp += *i;
}
} else if (c != 0x0a && c != 0x0d) {
- tmp += *i;
+ tmp += *i;
}
if (!incomment) {
- if (*i == '\"')
- inquotes = !inquotes;
+ if (*i == '\"') inquotes = !inquotes;
}
}
trim(tmp);
return tmp;
}
-
+
//----------------------------------------------------------------------
- inline void split(const std::string &s_in, const std::string &delim,
- std::vector<std::string> &dest, bool skipempty = true)
+ inline void split(const std::string &s_in,
+ const std::string &delim,
+ std::vector<std::string> &dest,
+ bool skipempty = true)
{
std::string token;
for (std::string::const_iterator i = s_in.begin(); i != s_in.end(); ++i) {
if (delim.find(*i) != std::string::npos) {
- if (!skipempty || token != "")
- dest.push_back(token);
+ if (!skipempty || token != "") dest.push_back(token);
token = "";
} else
token += *i;
}
- if (token != "")
- dest.push_back(token);
+ if (token != "") dest.push_back(token);
}
//----------------------------------------------------------------------
- inline void splitAddr(const std::string &s_in,
- std::vector<std::string> &dest, bool skipempty = true)
+ inline void splitAddr(const std::string &s_in, std::vector<std::string> &dest, bool skipempty = true)
{
static const std::string delim = ",";
std::string token;
bool inquote = false;
for (std::string::const_iterator i = s_in.begin(); i != s_in.end(); ++i) {
- if (inquote && *i == '\"') inquote = false;
- else if (!inquote && *i == '\"') inquote = true;
+ if (inquote && *i == '\"')
+ inquote = false;
+ else if (!inquote && *i == '\"')
+ inquote = true;
if (!inquote && delim.find(*i) != std::string::npos) {
if (!skipempty || token != "") dest.push_back(token);
@@ -208,8 +207,7 @@ namespace Binc {
} else
token += *i;
}
- if (token != "")
- dest.push_back(token);
+ if (token != "") dest.push_back(token);
}
//----------------------------------------------------------------------
@@ -220,8 +218,7 @@ namespace Binc {
if (s_in.length() >= 5) {
std::string a = s_in.substr(0, 5);
uppercase(a);
- return a == "INBOX" ?
- a + (s_in.length() > 5 ? s_in.substr(5) : "") : s_in;
+ return a == "INBOX" ? a + (s_in.length() > 5 ? s_in.substr(5) : "") : s_in;
}
return s_in;
@@ -232,22 +229,22 @@ namespace Binc {
{
std::string regex = "^";
for (std::string::const_iterator i = s_in.begin(); i != s_in.end(); ++i) {
- if (*i == '.' || *i == '[' || *i == ']' || *i == '{' || *i == '}' ||
- *i == '(' || *i == ')' || *i == '^' || *i == '$' || *i == '?' ||
- *i == '+' || *i == '\\') {
- regex += "\\";
- regex += *i;
- } else if (*i == '*')
- regex += ".*?";
- else if (*i == '%') {
- regex += "(\\";
- regex += delimiter;
- regex += "){0,1}";
- regex += "[^\\";
- regex += delimiter;
- regex += "]*?";
- } else
- regex += *i;
+ if (*i == '.' || *i == '[' || *i == ']' || *i == '{' || *i == '}' || *i == '(' || *i == ')'
+ || *i == '^' || *i == '$' || *i == '?' || *i == '+' || *i == '\\')
+ {
+ regex += "\\";
+ regex += *i;
+ } else if (*i == '*')
+ regex += ".*?";
+ else if (*i == '%') {
+ regex += "(\\";
+ regex += delimiter;
+ regex += "){0,1}";
+ regex += "[^\\";
+ regex += delimiter;
+ regex += "]*?";
+ } else
+ regex += *i;
}
if (regex[regex.length() - 1] == '?')
@@ -265,12 +262,12 @@ namespace Binc {
public:
//--
- BincStream &operator << (std::ostream&(*)(std::ostream&));
- BincStream &operator << (const std::string &t);
- BincStream &operator << (unsigned long t);
- BincStream &operator << (unsigned int t);
- BincStream &operator << (int t);
- BincStream &operator << (char t);
+ BincStream &operator<<(std::ostream &(*)(std::ostream &));
+ BincStream &operator<<(const std::string &t);
+ BincStream &operator<<(unsigned long t);
+ BincStream &operator<<(unsigned int t);
+ BincStream &operator<<(int t);
+ BincStream &operator<<(char t);
//--
std::string popString(unsigned int size);