From 5bc1f7bed536e0e936fd13fad45c49392b0bfff4 Mon Sep 17 00:00:00 2001 From: Roland Reichwein Date: Mon, 11 May 2020 12:24:04 +0200 Subject: Separated out routines to libcommon --- plugins/weblog/Makefile | 1 - plugins/weblog/stringutil.cpp | 66 ------------------------------------------- plugins/weblog/stringutil.h | 10 ------- plugins/weblog/weblog.cpp | 3 +- 4 files changed, 1 insertion(+), 79 deletions(-) delete mode 100644 plugins/weblog/stringutil.cpp delete mode 100644 plugins/weblog/stringutil.h (limited to 'plugins/weblog') diff --git a/plugins/weblog/Makefile b/plugins/weblog/Makefile index b9f278a..b660995 100644 --- a/plugins/weblog/Makefile +++ b/plugins/weblog/Makefile @@ -60,7 +60,6 @@ endif LDFLAGS=-L../../libcommon PROGSRC=\ - stringutil.cpp \ weblog.cpp TESTSRC=\ diff --git a/plugins/weblog/stringutil.cpp b/plugins/weblog/stringutil.cpp deleted file mode 100644 index f87fa00..0000000 --- a/plugins/weblog/stringutil.cpp +++ /dev/null @@ -1,66 +0,0 @@ -#include "stringutil.h" - -#include -#include - -#include - -std::string strfmt(const char* fmt, ...) -{ - va_list args; - - va_start(args, fmt); - int size = std::vsnprintf(nullptr, 0, fmt, args); - va_end(args); - - std::string result(size, ' '); - - va_start(args, fmt); - std::vsnprintf(result.data(), size + 1, fmt, args); - va_end(args); - - return result; -} - -std::vector split(std::string value, const std::string separators) -{ - std::vector result; - - size_t pos0 = 0; - size_t pos1 = 0; - while (pos0 < value.size()) { - pos1 = value.find_first_of(separators, pos0); - if (pos1 == std::string::npos) - pos1 = value.size(); - std::string part = value.substr(pos0, pos1 - pos0); - //std::cout << "DEBUG: " << part << std::endl << std::flush; - if (part != "") - result.push_back(part); - pos0 = value.find_first_not_of(separators, pos1); - if (pos0 == std::string::npos) - pos0 = value.size(); - } - - return result; -} - -std::string join(std::vector vs, std::string separator) -{ - std::string s; - for (const auto& line : vs) { - if (s.size() > 0) - s += separator; - s += line; - } - - return s; -} - -bool startsWithAnyOfLower(const std::string &s, const std::vector &list) { - for (const std::string& element : list) { - if (boost::algorithm::starts_with(boost::algorithm::to_lower_copy(s), boost::algorithm::to_lower_copy(element))) - return true; - } - return false; -} - diff --git a/plugins/weblog/stringutil.h b/plugins/weblog/stringutil.h deleted file mode 100644 index 5110e2e..0000000 --- a/plugins/weblog/stringutil.h +++ /dev/null @@ -1,10 +0,0 @@ -#pragma once - -#include -#include - -std::string strfmt(const char* fmt, ...); - -std::vector split(std::string value, const std::string separators = "\r\n "); -std::string join(std::vector vs, std::string separator = "\n"); -bool startsWithAnyOfLower(const std::string &s, const std::vector &list); diff --git a/plugins/weblog/weblog.cpp b/plugins/weblog/weblog.cpp index 4a14799..eb02bb2 100644 --- a/plugins/weblog/weblog.cpp +++ b/plugins/weblog/weblog.cpp @@ -1,8 +1,7 @@ #include "weblog.h" -#include "stringutil.h" - #include "libcommon/mime.h" +#include "libcommon/stringutil.h" #include #include -- cgit v1.2.3