diff options
author | Roland Reichwein <mail@reichwein.it> | 2023-01-04 15:16:36 +0100 |
---|---|---|
committer | Roland Reichwein <mail@reichwein.it> | 2023-01-04 15:16:36 +0100 |
commit | 5c330068e75946286e8e0d3dc0bd381e419074a9 (patch) | |
tree | 597a180b2b623e70af18bd80e380b2ce650b27d8 | |
parent | 17d2d6e657cb25260ed9cc329678ecf227191978 (diff) |
Namespaces for API
-rw-r--r-- | file.cpp | 12 | ||||
-rw-r--r-- | file.h | 4 | ||||
-rw-r--r-- | mime.cpp | 2 | ||||
-rw-r--r-- | mime.h | 4 | ||||
-rw-r--r-- | stringutil.cpp | 8 | ||||
-rw-r--r-- | stringutil.h | 6 | ||||
-rw-r--r-- | tempfile.cpp | 6 | ||||
-rw-r--r-- | tempfile.h | 4 | ||||
-rw-r--r-- | url.cpp | 2 | ||||
-rw-r--r-- | url.h | 4 |
10 files changed, 35 insertions, 17 deletions
@@ -6,7 +6,7 @@ namespace fs = std::filesystem; using namespace std::string_literals; -std::string File::getFile(const fs::path& filename) +std::string Reichwein::File::getFile(const fs::path& filename) { std::ifstream file(filename.string(), std::ios::in | std::ios::binary | std::ios::ate); @@ -24,12 +24,12 @@ std::string File::getFile(const fs::path& filename) } } -void File::setFile(const fs::path& filename, const std::string& s) +void Reichwein::File::setFile(const fs::path& filename, const std::string& s) { - File::setFile(filename, s.data(), s.size()); + Reichwein::File::setFile(filename, s.data(), s.size()); } -void File::setFile(const fs::path& filename, const char* data, size_t size) +void Reichwein::File::setFile(const fs::path& filename, const char* data, size_t size) { std::ofstream file(filename.string(), std::ios::out | std::ios::binary); if (file.is_open()) { @@ -39,8 +39,8 @@ void File::setFile(const fs::path& filename, const char* data, size_t size) } } -void File::setFile(const fs::path& filename, const std::vector<uint8_t>& data) +void Reichwein::File::setFile(const fs::path& filename, const std::vector<uint8_t>& data) { - File::setFile(filename, reinterpret_cast<const char*>(data.data()), data.size()); + Reichwein::File::setFile(filename, reinterpret_cast<const char*>(data.data()), data.size()); } @@ -7,11 +7,11 @@ #define EXPORT __attribute__((visibility("default"))) -namespace File { +namespace Reichwein::File { EXPORT std::string getFile(const std::filesystem::path& filename); EXPORT void setFile(const std::filesystem::path& filename, const std::string& s); EXPORT void setFile(const std::filesystem::path& filename, const char* data, size_t size); EXPORT void setFile(const std::filesystem::path& filename, const std::vector<uint8_t>& data); -} +} // namespace @@ -6,7 +6,7 @@ namespace beast = boost::beast; // Return a reasonable mime type based on the extension of a file. -std::string mime_type(const std::string& path) +std::string Reichwein::Mime::mime_type(const std::string& path) { auto const ext = [&path] { @@ -4,4 +4,8 @@ #define EXPORT __attribute__((visibility("default"))) +namespace Reichwein::Mime { + EXPORT std::string mime_type(const std::string& path); + +} // namespace diff --git a/stringutil.cpp b/stringutil.cpp index f87fa00..6eb2899 100644 --- a/stringutil.cpp +++ b/stringutil.cpp @@ -5,7 +5,7 @@ #include <cstdarg> -std::string strfmt(const char* fmt, ...) +std::string Reichwein::Stringutil::strfmt(const char* fmt, ...) { va_list args; @@ -22,7 +22,7 @@ std::string strfmt(const char* fmt, ...) return result; } -std::vector<std::string> split(std::string value, const std::string separators) +std::vector<std::string> Reichwein::Stringutil::split(std::string value, const std::string separators) { std::vector<std::string> result; @@ -44,7 +44,7 @@ std::vector<std::string> split(std::string value, const std::string separators) return result; } -std::string join(std::vector<std::string> vs, std::string separator) +std::string Reichwein::Stringutil::join(std::vector<std::string> vs, std::string separator) { std::string s; for (const auto& line : vs) { @@ -56,7 +56,7 @@ std::string join(std::vector<std::string> vs, std::string separator) return s; } -bool startsWithAnyOfLower(const std::string &s, const std::vector<std::string> &list) { +bool Reichwein::Stringutil::startsWithAnyOfLower(const std::string &s, const std::vector<std::string> &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; diff --git a/stringutil.h b/stringutil.h index 6cd74aa..510d2fd 100644 --- a/stringutil.h +++ b/stringutil.h @@ -5,7 +5,13 @@ #define EXPORT __attribute__((visibility("default"))) +namespace Reichwein::Stringutil { + +[[deprecated("Better use libfmt or std::format[C++20]")]] EXPORT std::string strfmt(const char* fmt, ...); + EXPORT std::vector<std::string> split(std::string value, const std::string separators = "\r\n "); EXPORT std::string join(std::vector<std::string> vs, std::string separator = "\n"); EXPORT bool startsWithAnyOfLower(const std::string &s, const std::vector<std::string> &list); + +} // namespace diff --git a/tempfile.cpp b/tempfile.cpp index f425db2..ca87d9b 100644 --- a/tempfile.cpp +++ b/tempfile.cpp @@ -9,12 +9,12 @@ namespace fs = std::filesystem; using namespace std::string_literals; -fs::path Tempfile::GetPath() const +fs::path Reichwein::Tempfile::GetPath() const { return m_path; } -Tempfile::Tempfile(const std::filesystem::path& extension) +Reichwein::Tempfile::Tempfile(const std::filesystem::path& extension) { try { fs::path path { fs::temp_directory_path() / "tempfileXXXXXX"}; @@ -32,7 +32,7 @@ Tempfile::Tempfile(const std::filesystem::path& extension) } } -Tempfile::~Tempfile() +Reichwein::Tempfile::~Tempfile() { try { fs::remove_all(m_path); @@ -4,6 +4,8 @@ #define EXPORT __attribute__((visibility("default"))) +namespace Reichwein { + class EXPORT Tempfile { std::filesystem::path m_path; @@ -15,3 +17,5 @@ class EXPORT Tempfile Tempfile(const std::filesystem::path& extension = std::filesystem::path{}); ~Tempfile(); }; + +} // namespace @@ -1,6 +1,6 @@ #include "url.h" -std::string urlDecode(std::string s) +std::string Reichwein::URL::urlDecode(std::string s) { std::string result; @@ -4,5 +4,9 @@ #define EXPORT __attribute__((visibility("default"))) +namespace Reichwein::URL { + EXPORT std::string urlDecode(std::string s); +} // namespace + |