Verified Commit 29a31ecd authored by Alberto Miranda's avatar Alberto Miranda ♨️
Browse files

Add convenience functions to `environment` class

- Implement `environment::as_vector()`.
- Add `environment::size()`.
parent 784f675f
Loading
Loading
Loading
Loading
+13 −2
Original line number Diff line number Diff line
@@ -295,8 +295,19 @@ environment::get(const std::string& key) const {

std::vector<std::string>
environment::as_vector() const {
    // TODO
    return {};

    std::vector<std::string> tmp;
    tmp.reserve(m_env.size());
    for(const auto& [key, value] : m_env) {
        tmp.emplace_back(fmt::format("{}={}", key, value));
    }

    return tmp;
}

std::size_t
environment::size() const {
    return m_env.size();
}

std::unordered_map<std::string, std::string>::const_iterator
+9 −0
Original line number Diff line number Diff line
@@ -59,12 +59,21 @@ public:

    /**
     * @brief Get the environment variables as a vector of strings.
     * Each string is of the form `key=value`.
     *
     * @return The environment variables as a vector of strings.
     */
    std::vector<std::string>
    as_vector() const;

    /**
     * @brief Get the number of environment variables.
     *
     * @return The number of environment variables.
     */
    std::size_t
    size() const;

    /**
     * @brief Get an iterator to the beginning of the environment variables.
     *