Skip to content

Commit ce44b07

Browse files
committed
Replacing whole src (Python=>C++)
1 parent 92e19ff commit ce44b07

27 files changed

+1553
-269
lines changed

DetExploit.ico

73.3 KB
Binary file not shown.

INIReader/INIReader.cpp

+108
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
// Read an INI file into easy-to-access name/value pairs.
2+
3+
// SPDX-License-Identifier: BSD-3-Clause
4+
5+
// Copyright (C) 2009-2019, Ben Hoyt
6+
7+
// inih and INIReader are released under the New BSD license (see LICENSE.txt).
8+
// Go to the project home page for more info:
9+
//
10+
// https://github.com/benhoyt/inih
11+
12+
#include <algorithm>
13+
#include <cctype>
14+
#include <cstdlib>
15+
#include "ini.h"
16+
#include "INIReader.h"
17+
18+
using std::string;
19+
20+
INIReader::INIReader(const string& filename)
21+
{
22+
_error = ini_parse(filename.c_str(), ValueHandler, this);
23+
}
24+
25+
int INIReader::ParseError() const
26+
{
27+
return _error;
28+
}
29+
30+
string INIReader::Get(const string& section, const string& name, const string& default_value) const
31+
{
32+
string key = MakeKey(section, name);
33+
// Use _values.find() here instead of _values.at() to support pre C++11 compilers
34+
return _values.count(key) ? _values.find(key)->second : default_value;
35+
}
36+
37+
string INIReader::GetString(const string& section, const string& name, const string& default_value) const
38+
{
39+
const string str = Get(section, name, "");
40+
return str.empty() ? default_value : str;
41+
}
42+
43+
long INIReader::GetInteger(const string& section, const string& name, long default_value) const
44+
{
45+
string valstr = Get(section, name, "");
46+
const char* value = valstr.c_str();
47+
char* end;
48+
// This parses "1234" (decimal) and also "0x4D2" (hex)
49+
long n = strtol(value, &end, 0);
50+
return end > value ? n : default_value;
51+
}
52+
53+
double INIReader::GetReal(const string& section, const string& name, double default_value) const
54+
{
55+
string valstr = Get(section, name, "");
56+
const char* value = valstr.c_str();
57+
char* end;
58+
double n = strtod(value, &end);
59+
return end > value ? n : default_value;
60+
}
61+
62+
bool INIReader::GetBoolean(const string& section, const string& name, bool default_value) const
63+
{
64+
string valstr = Get(section, name, "");
65+
// Convert to lower case to make string comparisons case-insensitive
66+
std::transform(valstr.begin(), valstr.end(), valstr.begin(), ::tolower);
67+
if (valstr == "true" || valstr == "yes" || valstr == "on" || valstr == "1")
68+
return true;
69+
else if (valstr == "false" || valstr == "no" || valstr == "off" || valstr == "0")
70+
return false;
71+
else
72+
return default_value;
73+
}
74+
75+
bool INIReader::HasSection(const string& section) const
76+
{
77+
const string key = MakeKey(section, "");
78+
std::map<string, string>::const_iterator pos = _values.lower_bound(key);
79+
if (pos == _values.end())
80+
return false;
81+
// Does the key at the lower_bound pos start with "section"?
82+
return pos->first.compare(0, key.length(), key) == 0;
83+
}
84+
85+
bool INIReader::HasValue(const string& section, const string& name) const
86+
{
87+
string key = MakeKey(section, name);
88+
return _values.count(key);
89+
}
90+
91+
string INIReader::MakeKey(const string& section, const string& name)
92+
{
93+
string key = section + "=" + name;
94+
// Convert to lower case to make section/name lookups case-insensitive
95+
std::transform(key.begin(), key.end(), key.begin(), ::tolower);
96+
return key;
97+
}
98+
99+
int INIReader::ValueHandler(void* user, const char* section, const char* name,
100+
const char* value)
101+
{
102+
INIReader* reader = static_cast<INIReader*>(user);
103+
string key = MakeKey(section, name);
104+
if (reader->_values[key].size() > 0)
105+
reader->_values[key] += "\n";
106+
reader->_values[key] += value;
107+
return 1;
108+
}

INIReader/INIReader.h

+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
// Read an INI file into easy-to-access name/value pairs.
2+
3+
// SPDX-License-Identifier: BSD-3-Clause
4+
5+
// Copyright (C) 2009-2019, Ben Hoyt
6+
7+
// inih and INIReader are released under the New BSD license (see LICENSE.txt).
8+
// Go to the project home page for more info:
9+
//
10+
// https://github.com/benhoyt/inih
11+
12+
#ifndef __INIREADER_H__
13+
#define __INIREADER_H__
14+
15+
#include <map>
16+
#include <string>
17+
18+
// Read an INI file into easy-to-access name/value pairs. (Note that I've gone
19+
// for simplicity here rather than speed, but it should be pretty decent.)
20+
class INIReader
21+
{
22+
public:
23+
// Construct INIReader and parse given filename. See ini.h for more info
24+
// about the parsing.
25+
explicit INIReader(const std::string& filename);
26+
27+
// Return the result of ini_parse(), i.e., 0 on success, line number of
28+
// first error on parse error, or -1 on file open error.
29+
int ParseError() const;
30+
31+
// Get a string value from INI file, returning default_value if not found.
32+
std::string Get(const std::string& section, const std::string& name,
33+
const std::string& default_value) const;
34+
35+
// Get a string value from INI file, returning default_value if not found,
36+
// empty, or contains only whitespace.
37+
std::string GetString(const std::string& section, const std::string& name,
38+
const std::string& default_value) const;
39+
40+
// Get an integer (long) value from INI file, returning default_value if
41+
// not found or not a valid integer (decimal "1234", "-1234", or hex "0x4d2").
42+
long GetInteger(const std::string& section, const std::string& name, long default_value) const;
43+
44+
// Get a real (floating point double) value from INI file, returning
45+
// default_value if not found or not a valid floating point value
46+
// according to strtod().
47+
double GetReal(const std::string& section, const std::string& name, double default_value) const;
48+
49+
// Get a boolean value from INI file, returning default_value if not found or if
50+
// not a valid true/false value. Valid true values are "true", "yes", "on", "1",
51+
// and valid false values are "false", "no", "off", "0" (not case sensitive).
52+
bool GetBoolean(const std::string& section, const std::string& name, bool default_value) const;
53+
54+
// Return true if the given section exists (section must contain at least
55+
// one name=value pair).
56+
bool HasSection(const std::string& section) const;
57+
58+
// Return true if a value exists with the given section and field names.
59+
bool HasValue(const std::string& section, const std::string& name) const;
60+
61+
private:
62+
int _error;
63+
std::map<std::string, std::string> _values;
64+
static std::string MakeKey(const std::string& section, const std::string& name);
65+
static int ValueHandler(void* user, const char* section, const char* name,
66+
const char* value);
67+
};
68+
69+
#endif // __INIREADER_H__

0 commit comments

Comments
 (0)