-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathdotenv.cpp
More file actions
47 lines (31 loc) · 974 Bytes
/
dotenv.cpp
File metadata and controls
47 lines (31 loc) · 974 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include "dotenv.h"
#include "environ.h"
#include "Parser.h"
#include <fstream>
#include <utility>
using namespace std;
// Type alias to work around the fact that class name matches namespace name
// This is a known C++ limitation when defining out-of-line members
typedef class ::dotenv::dotenv DotenvClass;
DotenvClass& ::dotenv::dotenv::load_dotenv(const string& dotenv_path, const bool overwrite, const bool interpolate)
{
ifstream env_file;
env_file.open(dotenv_path);
if (env_file.good())
{
Parser parser;
parser.parse(env_file, overwrite, interpolate);
env_file.close();
}
return *this;
}
const string DotenvClass::operator[](const key_type& k) const
{
return getenv(k).second;
}
DotenvClass& ::dotenv::dotenv::instance()
{
return _instance;
}
// Define the global 'env' reference. Static members are inline in the header (C++17).
::dotenv::dotenv& ::dotenv::env = ::dotenv::dotenv::instance();