Skip to content

Commit 64c7a68

Browse files
committedAug 15, 2017
bab.cpp: code modernization
* Use for range based loops * Simplify some tests * Code style fixes
1 parent 342e933 commit 64c7a68

File tree

1 file changed

+9
-11
lines changed

1 file changed

+9
-11
lines changed
 

Diff for: ‎src/ban.cpp

+9-11
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,12 @@ void BanManager::load()
4848
MutexAutoLock lock(m_mutex);
4949
infostream<<"BanManager: loading from "<<m_banfilepath<<std::endl;
5050
std::ifstream is(m_banfilepath.c_str(), std::ios::binary);
51-
if(is.good() == false)
52-
{
51+
if (!is.good()) {
5352
infostream<<"BanManager: failed loading from "<<m_banfilepath<<std::endl;
5453
throw SerializationError("BanManager::load(): Couldn't open file");
5554
}
5655

57-
while(!is.eof() && is.good())
58-
{
56+
while (!is.eof() && is.good()) {
5957
std::string line;
6058
std::getline(is, line, '\n');
6159
Strfnd f(line);
@@ -74,8 +72,8 @@ void BanManager::save()
7472
infostream << "BanManager: saving to " << m_banfilepath << std::endl;
7573
std::ostringstream ss(std::ios_base::binary);
7674

77-
for (StringMap::iterator it = m_ips.begin(); it != m_ips.end(); ++it)
78-
ss << it->first << "|" << it->second << "\n";
75+
for (const auto &ip : m_ips)
76+
ss << ip.first << "|" << ip.second << "\n";
7977

8078
if (!fs::safeWriteToFile(m_banfilepath, ss.str())) {
8179
infostream << "BanManager: failed saving to " << m_banfilepath << std::endl;
@@ -94,11 +92,11 @@ bool BanManager::isIpBanned(const std::string &ip)
9492
std::string BanManager::getBanDescription(const std::string &ip_or_name)
9593
{
9694
MutexAutoLock lock(m_mutex);
97-
std::string s = "";
98-
for (StringMap::iterator it = m_ips.begin(); it != m_ips.end(); ++it) {
99-
if (it->first == ip_or_name || it->second == ip_or_name
100-
|| ip_or_name == "") {
101-
s += it->first + "|" + it->second + ", ";
95+
std::string s;
96+
for (const auto &ip : m_ips) {
97+
if (ip.first == ip_or_name || ip.second == ip_or_name
98+
|| ip_or_name.empty()) {
99+
s += ip.first + "|" + ip.second + ", ";
102100
}
103101
}
104102
s = s.substr(0, s.size() - 2);

0 commit comments

Comments
 (0)
Please sign in to comment.