diff options
author | dec05eba <dec05eba@protonmail.com> | 2024-08-06 05:57:21 +0200 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2024-08-06 05:57:21 +0200 |
commit | 9f1fddc47ce10fbc65cdeaa70461063b9921434e (patch) | |
tree | e9a8f19fa2ea5445e62ac2f4f8a488c591805347 /include/Utils.hpp | |
parent | b778fd7cc654f28a2bfe0ff74537f120241b289c (diff) |
Copy Config from gpu-screen-recorder-gtk, make it more modern and efficient with string_view and variant, use string_view in gsr info parsing
Diffstat (limited to 'include/Utils.hpp')
-rw-r--r-- | include/Utils.hpp | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/include/Utils.hpp b/include/Utils.hpp new file mode 100644 index 0000000..f917834 --- /dev/null +++ b/include/Utils.hpp @@ -0,0 +1,32 @@ +#pragma once + +#include <functional> +#include <optional> +#include <string_view> +#include <map> +#include <string> + +namespace gsr { + struct KeyValue { + std::string_view key; + std::string_view value; + }; + + using StringSplitCallback = std::function<bool(std::string_view line)>; + + void string_split_char(std::string_view str, char delimiter, StringSplitCallback callback_func); + + // key value separated by one space + std::optional<KeyValue> parse_key_value(std::string_view line); + + std::string get_home_dir(); + std::string get_config_dir(); + + // Whoever designed xdg-user-dirs is retarded. Why are some XDG variables environment variables + // while others are in this pseudo shell config file ~/.config/user-dirs.dirs + std::map<std::string, std::string> get_xdg_variables(); + + std::string get_videos_dir(); + int create_directory_recursive(char *path); + bool file_get_content(const char *filepath, std::string &file_content); +}
\ No newline at end of file |