summaryrefslogtreecommitdiff
path: root/src/strutil.hh
diff options
context:
space:
mode:
authorJoel Klinghed <the_jk@spawned.biz>2021-11-17 22:34:57 +0100
committerJoel Klinghed <the_jk@spawned.biz>2021-11-17 22:34:57 +0100
commit6232d13f5321b87ddf12a1aa36b4545da45f173d (patch)
tree23f3316470a14136debd9d02f9e920ca2b06f4cc /src/strutil.hh
Travel3: Simple image and video display site
Reads the images and videos from filesystem and builds a site in memroy.
Diffstat (limited to 'src/strutil.hh')
-rw-r--r--src/strutil.hh51
1 files changed, 51 insertions, 0 deletions
diff --git a/src/strutil.hh b/src/strutil.hh
new file mode 100644
index 0000000..28bbf55
--- /dev/null
+++ b/src/strutil.hh
@@ -0,0 +1,51 @@
+#ifndef STRUTIL_HH
+#define STRUTIL_HH
+
+#include <optional>
+#include <stdint.h>
+#include <string>
+#include <string_view>
+#include <vector>
+
+namespace str {
+
+std::optional<uint16_t> parse_uint16(std::string const& str);
+std::optional<uint32_t> parse_uint32(std::string const& str);
+std::optional<uint64_t> parse_uint64(std::string const& str);
+
+// Empty substrings are ignored but out will always be at least one entry
+std::vector<std::string_view> split(std::string_view str, char delim = ' ');
+
+std::vector<std::string> split(std::string const& str, char delim = ' ');
+
+std::string join(std::vector<std::string> const& in, char delim);
+std::string join(std::vector<std::string> const& in, std::string_view delim);
+
+void join(std::vector<std::string> const& in, char delim, std::string& out);
+void join(std::vector<std::string> const& in, std::string_view delim,
+ std::string& out);
+
+std::string join(std::vector<std::string_view> const& in, char delim);
+std::string join(std::vector<std::string_view> const& in,
+ std::string_view delim);
+
+void join(std::vector<std::string_view> const& in, char delim,
+ std::string& out);
+void join(std::vector<std::string_view> const& in, std::string_view delim,
+ std::string& out);
+
+[[nodiscard]] std::string_view trim(std::string_view str);
+[[nodiscard]] std::string trim(std::string const& str);
+
+[[nodiscard]] std::string_view ltrim(std::string_view str);
+[[nodiscard]] std::string ltrim(std::string const& str);
+
+[[nodiscard]] std::string_view rtrim(std::string_view str);
+[[nodiscard]] std::string rtrim(std::string const& str);
+
+[[nodiscard]] bool starts_with(std::string_view str, std::string_view prefix);
+[[nodiscard]] bool ends_with(std::string_view str, std::string_view suffix);
+
+} // namespace str
+
+#endif // STRUTIL_HH