don't use boost string algorithm

This commit is contained in:
Chunting Gu
2020-02-18 09:49:45 +08:00
parent 7e7ab1c1e8
commit 1e3c2b2604
25 changed files with 336 additions and 308 deletions
+2 -39
View File
@@ -7,22 +7,12 @@
#include <iomanip> // for put_time
#include <sstream>
#include "boost/algorithm/string.hpp"
#include "boost/uuid/random_generator.hpp"
#include "boost/uuid/uuid_io.hpp"
#include "webcc/string.h"
#include "webcc/version.h"
namespace webcc {
namespace utility {
std::string RandomUuid() {
boost::uuids::uuid u = boost::uuids::random_generator()();
std::stringstream ss;
ss << u;
return ss.str();
}
const std::string& UserAgent() {
static auto s_user_agent = std::string("Webcc/") + WEBCC_VERSION;
return s_user_agent;
@@ -35,33 +25,6 @@ std::string GetTimestamp() {
return ss.str();
}
bool SplitKV(const std::string& str, char delimiter, std::string* key,
std::string* value, bool trim) {
std::size_t pos = str.find(delimiter);
if (pos == std::string::npos) {
return false;
}
*key = str.substr(0, pos);
*value = str.substr(pos + 1);
if (trim) {
boost::trim(*key);
boost::trim(*value);
}
return true;
}
bool ToSize(const std::string& str, int base, std::size_t* size) {
try {
*size = static_cast<std::size_t>(std::stoul(str, 0, base));
} catch (const std::exception&) {
return false;
}
return true;
}
std::size_t TellSize(const std::filesystem::path& path) {
// Flag "ate": seek to the end of stream immediately after open.
std::ifstream stream{ path, std::ios::binary | std::ios::ate };
@@ -91,7 +54,7 @@ bool ReadFile(const std::filesystem::path& path, std::string* output) {
void DumpByLine(const std::string& data, std::ostream& os,
const std::string& prefix) {
std::vector<std::string> lines;
boost::split(lines, data, boost::is_any_of("\n"));
split(lines, data, '\n');
std::size_t size = 0;