TYPE3
[iec.git] / src / type3_AndroidCloud / anbox-master / src / anbox / utils / environment_file.cpp
1 /*
2  * Copyright (C) 2017 Simon Fels <morphis@gravedo.de>
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License as published by
6  * the Free Software Foundation; version 3.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11  * GNU Lesser General Public License for more details.
12  *
13  * You should have received a copy of the GNU Lesser General Public License
14  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
15  *
16  */
17
18 #include "anbox/utils/environment_file.h"
19 #include "anbox/utils.h"
20
21 #include <fstream>
22
23 namespace anbox {
24 namespace utils {
25 EnvironmentFile::EnvironmentFile(const boost::filesystem::path &path) {
26   std::ifstream in(path.string());
27   std::string line;
28   while (std::getline(in, line)) {
29     auto tokens = utils::string_split(line, '=');
30     if (tokens.size() != 2)
31       continue;
32     data_[tokens[0]] = utils::strip_surrounding_quotes(tokens[1]);
33   }
34 }
35
36 std::string EnvironmentFile::value(const std::string &key, const std::string &default_value) const {
37   auto iter = data_.find(key);
38   if (iter == data_.end())
39     return default_value;
40   return iter->second;
41 }
42 } // namespace utils
43 } // namespace anbox