mirror of
https://gitlab.com/niansa/commoncpp.git
synced 2025-03-06 20:48:30 +01:00
Added COMMONCPP_LITE option
This commit is contained in:
parent
eeb7602821
commit
6a6c0c7c49
8 changed files with 41 additions and 0 deletions
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
CMakeLists.txt.user*
|
|
@ -1,8 +1,12 @@
|
|||
cmake_minimum_required(VERSION 3.15)
|
||||
|
||||
project(commoncpp LANGUAGES CXX)
|
||||
|
||||
set(CMAKE_CXX_STANDARD 17)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
|
||||
option(COMMONCPP_LITE "Build lite version on CommonCPP only" No)
|
||||
|
||||
add_library(commoncpp STATIC
|
||||
config.cpp include/commoncpp/config.hpp
|
||||
utils.cpp include/commoncpp/utils.hpp
|
||||
|
@ -11,3 +15,7 @@ add_library(commoncpp STATIC
|
|||
|
||||
target_include_directories(commoncpp PUBLIC include/)
|
||||
target_include_directories(commoncpp PRIVATE include/commoncpp/)
|
||||
|
||||
if (COMMONCPP_LITE)
|
||||
target_compile_definitions(commoncpp PUBLIC COMMONCPP_LITE)
|
||||
endif()
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
#ifndef COMMONCPP_LITE
|
||||
#include "config.hpp"
|
||||
#include "utils.hpp"
|
||||
|
||||
|
@ -104,3 +105,4 @@ void Configuration::parse(const std::string &file) {
|
|||
fill(file_parser(file), true);
|
||||
}
|
||||
}
|
||||
#endif // COMMONCPP_LITE
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
#ifndef COMMONCPP_LITE
|
||||
#ifndef CONFIG_HPP
|
||||
#define CONFIG_HPP
|
||||
#include <string>
|
||||
|
@ -46,3 +47,4 @@ public:
|
|||
};
|
||||
}
|
||||
#endif // CONFIG_HPP
|
||||
#endif // COMMONCPP_LITE
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
#ifndef COMMONCPP_LITE
|
||||
#ifndef SCHEDULED_THREAD_HPP
|
||||
#define SCHEDULED_THREAD_HPP
|
||||
#include <functional>
|
||||
|
@ -64,3 +65,4 @@ namespace [[deprecated("Use the common namespace instead of commoncpp")]] common
|
|||
using namespace common;
|
||||
}
|
||||
#endif // SCHEDULED_THREAD_HPP
|
||||
#endif // COMMONCPP_LITE
|
||||
|
|
|
@ -2,12 +2,18 @@
|
|||
#define UTILS_HPP
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#ifndef COMMONCPP_LITE
|
||||
#include <vector>
|
||||
#endif
|
||||
#include <utility>
|
||||
|
||||
|
||||
namespace common {
|
||||
namespace utils {
|
||||
#ifndef COMMONCPP_LITE
|
||||
std::vector<std::string_view> str_split(std::string_view s, char delimiter, size_t times = -1);
|
||||
#endif
|
||||
std::pair<std::string_view, std::string_view> str_split_once(std::string_view s, std::string_view delim);
|
||||
bool str_replace_in_place(std::string& subject, std::string_view search, const std::string& replace);
|
||||
std::string_view max_words(std::string_view text, unsigned count);
|
||||
bool contains(std::string_view value, std::string_view other);
|
||||
|
@ -15,8 +21,10 @@ bool starts_with(std::string_view value, std::string_view beginning);
|
|||
bool ends_with(std::string_view value, std::string_view ending);
|
||||
bool force_trailing(std::string& value, std::string_view ending);
|
||||
bool chop_down(std::string& s, char delim);
|
||||
#ifndef COMMONCPP_LITE
|
||||
std::string remove_nonprintable(std::string_view);
|
||||
std::string read_text_file(const std::string& path);
|
||||
#endif
|
||||
|
||||
[[noreturn]] inline void unreachable() {
|
||||
// Uses compiler specific extensions if possible.
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
#ifndef COMMONCPP_LITE
|
||||
#include "pooled_thread.hpp"
|
||||
|
||||
#include <exception>
|
||||
|
@ -38,3 +39,4 @@ void PooledThread::main_loop() {
|
|||
|
||||
}
|
||||
}
|
||||
#endif // COMMONCPP_LITE
|
||||
|
|
16
utils.cpp
16
utils.cpp
|
@ -1,14 +1,17 @@
|
|||
#include "utils.hpp"
|
||||
|
||||
#ifndef COMMONCPP_LITE
|
||||
#include <sstream>
|
||||
#include <fstream>
|
||||
#include <stdexcept>
|
||||
#include <cerrno>
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
namespace common {
|
||||
namespace utils {
|
||||
#ifndef COMMONCPP_LITE
|
||||
std::vector<std::string_view> str_split(std::string_view s, char delimiter, size_t times) {
|
||||
std::vector<std::string_view> to_return;
|
||||
decltype(s.size()) start = 0, finish = 0;
|
||||
|
@ -20,6 +23,17 @@ std::vector<std::string_view> str_split(std::string_view s, char delimiter, size
|
|||
to_return.emplace_back(s.substr(start));
|
||||
return to_return;
|
||||
}
|
||||
#endif
|
||||
|
||||
std::pair<std::string_view, std::string_view> str_split_once(std::string_view s, std::string_view delim) {
|
||||
// Find the delimiter
|
||||
auto pos = s.find(delim);
|
||||
if (pos == s.npos) {
|
||||
return {s, ""};
|
||||
}
|
||||
// Split there
|
||||
return {s.substr(0, pos), s.substr(pos+delim.size(), s.size()-1)};
|
||||
}
|
||||
|
||||
bool str_replace_in_place(std::string& subject, std::string_view search,
|
||||
const std::string& replace) {
|
||||
|
@ -80,6 +94,7 @@ bool chop_down(std::string& s, char delim) {
|
|||
return true;
|
||||
}
|
||||
|
||||
#ifndef COMMONCPP_LITE
|
||||
std::string remove_nonprintable(std::string_view str) {
|
||||
std::string fres;
|
||||
for (const char c : str) {
|
||||
|
@ -95,5 +110,6 @@ std::string read_text_file(const std::string& path) {
|
|||
sstr << in.rdbuf();
|
||||
return sstr.str();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue