X-Git-Url: https://gerrit.akraino.org/r/gitweb?a=blobdiff_plain;f=src%2Ftype3_AndroidCloud%2Fanbox-master%2Fsrc%2Fanbox%2Futils%2Fenvironment_file.cpp;fp=src%2Ftype3_AndroidCloud%2Fanbox-master%2Fsrc%2Fanbox%2Futils%2Fenvironment_file.cpp;h=5285e0e35c425dde87c31f05c45bcca459d9a376;hb=e26c1ec581be598521517829adba8c8dd23a768f;hp=0000000000000000000000000000000000000000;hpb=6699c1aea74eeb0eb400e6299079f0c7576f716f;p=iec.git diff --git a/src/type3_AndroidCloud/anbox-master/src/anbox/utils/environment_file.cpp b/src/type3_AndroidCloud/anbox-master/src/anbox/utils/environment_file.cpp new file mode 100644 index 0000000..5285e0e --- /dev/null +++ b/src/type3_AndroidCloud/anbox-master/src/anbox/utils/environment_file.cpp @@ -0,0 +1,43 @@ +/* + * Copyright (C) 2017 Simon Fels + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; version 3. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + * + */ + +#include "anbox/utils/environment_file.h" +#include "anbox/utils.h" + +#include + +namespace anbox { +namespace utils { +EnvironmentFile::EnvironmentFile(const boost::filesystem::path &path) { + std::ifstream in(path.string()); + std::string line; + while (std::getline(in, line)) { + auto tokens = utils::string_split(line, '='); + if (tokens.size() != 2) + continue; + data_[tokens[0]] = utils::strip_surrounding_quotes(tokens[1]); + } +} + +std::string EnvironmentFile::value(const std::string &key, const std::string &default_value) const { + auto iter = data_.find(key); + if (iter == data_.end()) + return default_value; + return iter->second; +} +} // namespace utils +} // namespace anbox