From 375799fa79d1af76f33299acc20a11a167a021f8 Mon Sep 17 00:00:00 2001 From: Felix Morgner Date: Thu, 17 Aug 2023 12:32:50 +0200 Subject: project: restructure libraries and build env --- source/lib/system/src/environment.cpp | 71 +++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 source/lib/system/src/environment.cpp (limited to 'source/lib/system/src/environment.cpp') diff --git a/source/lib/system/src/environment.cpp b/source/lib/system/src/environment.cpp new file mode 100644 index 0000000..8f79531 --- /dev/null +++ b/source/lib/system/src/environment.cpp @@ -0,0 +1,71 @@ +#include "wanda/system/environment.hpp" + +#include + +namespace wanda::system +{ + 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::system \ No newline at end of file -- cgit v1.2.3