#ifndef DOTENV_H #define DOTENV_H #include #include #include #include #include "platformUtils.h" namespace platform { class DotEnv { private: std::map env; std::string trim(const std::string& str) { std::string result = str; result.erase(result.begin(), std::find_if(result.begin(), result.end(), [](int ch) { return !std::isspace(ch); })); result.erase(std::find_if(result.rbegin(), result.rend(), [](int ch) { return !std::isspace(ch); }).base(), result.end()); return result; } public: DotEnv() { std::ifstream file(".env"); if (!file.is_open()) { std::cerr << "File .env not found" << std::endl; exit(1); } std::string line; while (std::getline(file, line)) { line = trim(line); if (line.empty() || line[0] == '#') { continue; } std::istringstream iss(line); std::string key, value; if (std::getline(iss, key, '=') && std::getline(iss, value)) { env[key] = value; } } } std::string get(const std::string& key) { return env[key]; } std::vector getSeeds() { auto seeds = std::vector(); auto seeds_str = env["seeds"]; seeds_str = trim(seeds_str); seeds_str = seeds_str.substr(1, seeds_str.size() - 2); auto seeds_str_split = split(seeds_str, ','); transform(seeds_str_split.begin(), seeds_str_split.end(), back_inserter(seeds), [](const std::string& str) { return stoi(str); }); return seeds; } }; } #endif