diff options
| author | Felix Morgner <felix.morgner@gmail.com> | 2018-11-30 10:48:44 +0100 |
|---|---|---|
| committer | Felix Morgner <felix.morgner@gmail.com> | 2018-11-30 10:48:44 +0100 |
| commit | 5b2974cd16b5d2841b72c7d0cc4a34469a8ded5b (patch) | |
| tree | 27fe6f0b428a1e02f7fe7c677795bdd989e0498c /src/environment.cpp | |
| parent | 543e91dc65d839864b42114b353d0c30db4dcdd1 (diff) | |
| download | wanda-5b2974cd16b5d2841b72c7d0cc4a34469a8ded5b.tar.xz wanda-5b2974cd16b5d2841b72c7d0cc4a34469a8ded5b.zip | |
core: implement basic XDG Base Specification support
Diffstat (limited to 'src/environment.cpp')
| -rw-r--r-- | src/environment.cpp | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/src/environment.cpp b/src/environment.cpp new file mode 100644 index 0000000..2051573 --- /dev/null +++ b/src/environment.cpp @@ -0,0 +1,73 @@ +#include "environment.hpp" + +#include <iostream> +#include <string> + +namespace wanda +{ + +environment::environment(char const *const *env) +{ + if (!env) + { + return; + } + + std::string buffer{}; + for (; *env != nullptr; ++env) + { + buffer = *env; + int split_point = buffer.find('='); + if (split_point != std::string::npos) + { + m_cache[buffer.substr(0, split_point)] = buffer.substr(split_point + 1); + } + } +} + +std::string & environment::operator[](std::string const & variable) +{ + return m_cache[variable]; +} + +std::string const & environment::operator[](std::string const & variable) const +{ + static std::string const empty{}; + if(auto needle = m_cache.find(variable); needle != cend()) + { + return needle->second; + } + return empty; +} + +environment::iterator environment::begin() +{ + return m_cache.begin(); +} + +environment::const_iterator environment::begin() const +{ + return m_cache.begin(); +} + +environment::const_iterator environment::cbegin() const +{ + return m_cache.cbegin(); +} + +environment::iterator environment::end() +{ + return m_cache.end(); +} + +environment::const_iterator environment::end() const +{ + return m_cache.end(); +} + +environment::const_iterator environment::cend() const +{ + return m_cache.cend(); +} + +} // namespace wanda
\ No newline at end of file |
