diff options
| author | Felix Morgner <felix.morgner@gmail.com> | 2022-09-16 23:28:09 +0200 |
|---|---|---|
| committer | Felix Morgner <felix.morgner@gmail.com> | 2022-09-16 23:28:09 +0200 |
| commit | f4d9880d3c9555b48affad727589ef5c093b1841 (patch) | |
| tree | a5552b5a33000a527748ac1c72ca366476af0936 /source/lib/src/environment.cpp | |
| parent | 64922e213ac731279cf3341253e67509adb2dfc8 (diff) | |
| download | wanda-f4d9880d3c9555b48affad727589ef5c093b1841.tar.xz wanda-f4d9880d3c9555b48affad727589ef5c093b1841.zip | |
source: clean up structure
Diffstat (limited to 'source/lib/src/environment.cpp')
| -rw-r--r-- | source/lib/src/environment.cpp | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/source/lib/src/environment.cpp b/source/lib/src/environment.cpp new file mode 100644 index 0000000..2f1af0a --- /dev/null +++ b/source/lib/src/environment.cpp @@ -0,0 +1,71 @@ +#include "wanda/environment.hpp" + +#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 |
