Bogofilter adapter for OpenSMTPD in C++
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

41 lines
1.0 KiB

#include <util.hpp>
#include <string>
#include <vector>
using namespace std;
namespace util {
const vector<string> split(const string input, const string::value_type separator, const size_t max_tokens) {
vector<string> tokens;
for(size_t index = 0, last = -1; index != max_tokens; ++index) {
auto current = input.find(separator, last + 1);
auto eol = current == string::npos;
if(eol || index == max_tokens) {
current = input.length();
}
auto length = current - last - 1;
auto token = input.substr(last + 1, length);
tokens.push_back(token);
last = current;
if(eol) {
break;
}
}
return tokens;
}
const string lpad(const string input, const int length, const string str) {
string output;
for(int i = 0; i < length; ++i) {
output += str;
}
output += input;
return output.c_str();
}
}