From 5c330068e75946286e8e0d3dc0bd381e419074a9 Mon Sep 17 00:00:00 2001 From: Roland Reichwein Date: Wed, 4 Jan 2023 15:16:36 +0100 Subject: Namespaces for API --- file.cpp | 12 ++++++------ file.h | 4 ++-- mime.cpp | 2 +- mime.h | 4 ++++ stringutil.cpp | 8 ++++---- stringutil.h | 6 ++++++ tempfile.cpp | 6 +++--- tempfile.h | 4 ++++ url.cpp | 2 +- url.h | 4 ++++ 10 files changed, 35 insertions(+), 17 deletions(-) diff --git a/file.cpp b/file.cpp index 47ab8be..0c28511 100644 --- a/file.cpp +++ b/file.cpp @@ -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& data) +void Reichwein::File::setFile(const fs::path& filename, const std::vector& data) { - File::setFile(filename, reinterpret_cast(data.data()), data.size()); + Reichwein::File::setFile(filename, reinterpret_cast(data.data()), data.size()); } diff --git a/file.h b/file.h index 37653cb..9ca846e 100644 --- a/file.h +++ b/file.h @@ -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& data); -} +} // namespace diff --git a/mime.cpp b/mime.cpp index f64d046..cb3e323 100644 --- a/mime.cpp +++ b/mime.cpp @@ -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] { diff --git a/mime.h b/mime.h index 8065d4f..1102b29 100644 --- a/mime.h +++ b/mime.h @@ -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 -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 split(std::string value, const std::string separators) +std::vector Reichwein::Stringutil::split(std::string value, const std::string separators) { std::vector result; @@ -44,7 +44,7 @@ std::vector split(std::string value, const std::string separators) return result; } -std::string join(std::vector vs, std::string separator) +std::string Reichwein::Stringutil::join(std::vector vs, std::string separator) { std::string s; for (const auto& line : vs) { @@ -56,7 +56,7 @@ std::string join(std::vector vs, std::string separator) return s; } -bool startsWithAnyOfLower(const std::string &s, const std::vector &list) { +bool Reichwein::Stringutil::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; 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 split(std::string value, const std::string separators = "\r\n "); EXPORT std::string join(std::vector vs, std::string separator = "\n"); EXPORT bool startsWithAnyOfLower(const std::string &s, const std::vector &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); diff --git a/tempfile.h b/tempfile.h index 989e6d6..7fe86ea 100644 --- a/tempfile.h +++ b/tempfile.h @@ -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 diff --git a/url.cpp b/url.cpp index 5baf603..5ad820a 100644 --- a/url.cpp +++ b/url.cpp @@ -1,6 +1,6 @@ #include "url.h" -std::string urlDecode(std::string s) +std::string Reichwein::URL::urlDecode(std::string s) { std::string result; diff --git a/url.h b/url.h index c4745ab..f1db226 100644 --- a/url.h +++ b/url.h @@ -4,5 +4,9 @@ #define EXPORT __attribute__((visibility("default"))) +namespace Reichwein::URL { + EXPORT std::string urlDecode(std::string s); +} // namespace + -- cgit v1.2.3