summaryrefslogtreecommitdiff
path: root/src/util
diff options
context:
space:
mode:
Diffstat (limited to 'src/util')
-rw-r--r--src/util/areastore.cpp21
-rw-r--r--src/util/areastore.h5
-rw-r--r--src/util/enriched_string.cpp20
-rw-r--r--src/util/numeric.h3
-rw-r--r--src/util/srp.cpp2
-rw-r--r--src/util/string.cpp9
-rw-r--r--src/util/string.h12
7 files changed, 35 insertions, 37 deletions
diff --git a/src/util/areastore.cpp b/src/util/areastore.cpp
index c660502f6..50d237bba 100644
--- a/src/util/areastore.cpp
+++ b/src/util/areastore.cpp
@@ -68,9 +68,8 @@ void AreaStore::serialize(std::ostream &os) const
// TODO: Compression?
writeU16(os, areas_map.size());
- for (AreaMap::const_iterator it = areas_map.begin();
- it != areas_map.end(); ++it) {
- const Area &a = it->second;
+ for (const auto &it : areas_map) {
+ const Area &a = it.second;
writeV3S16(os, a.minedge);
writeV3S16(os, a.maxedge);
writeU16(os, a.data.size());
@@ -193,10 +192,9 @@ bool VectorAreaStore::removeArea(u32 id)
void VectorAreaStore::getAreasForPosImpl(std::vector<Area *> *result, v3s16 pos)
{
- for (size_t i = 0; i < m_areas.size(); ++i) {
- Area *b = m_areas[i];
- if (AST_CONTAINS_PT(b, pos)) {
- result->push_back(b);
+ for (Area *area : m_areas) {
+ if (AST_CONTAINS_PT(area, pos)) {
+ result->push_back(area);
}
}
}
@@ -204,11 +202,10 @@ void VectorAreaStore::getAreasForPosImpl(std::vector<Area *> *result, v3s16 pos)
void VectorAreaStore::getAreasInArea(std::vector<Area *> *result,
v3s16 minedge, v3s16 maxedge, bool accept_overlap)
{
- for (size_t i = 0; i < m_areas.size(); ++i) {
- Area *b = m_areas[i];
- if (accept_overlap ? AST_AREAS_OVERLAP(minedge, maxedge, b) :
- AST_CONTAINS_AREA(minedge, maxedge, b)) {
- result->push_back(b);
+ for (Area *area : m_areas) {
+ if (accept_overlap ? AST_AREAS_OVERLAP(minedge, maxedge, area) :
+ AST_CONTAINS_AREA(minedge, maxedge, area)) {
+ result->push_back(area);
}
}
}
diff --git a/src/util/areastore.h b/src/util/areastore.h
index e94aa4e2a..24840210e 100644
--- a/src/util/areastore.h
+++ b/src/util/areastore.h
@@ -37,7 +37,8 @@ with this program; if not, write to the Free Software Foundation, Inc.,
struct Area {
- Area() {}
+ Area() = default;
+
Area(const v3s16 &mine, const v3s16 &maxe) :
minedge(mine), maxedge(maxe)
{
@@ -56,7 +57,7 @@ public:
m_res_cache(1000, &cacheMiss, this)
{}
- virtual ~AreaStore() {}
+ virtual ~AreaStore() = default;
static AreaStore *getOptimalImplementation();
diff --git a/src/util/enriched_string.cpp b/src/util/enriched_string.cpp
index 05d7b8c25..f79e77d5a 100644
--- a/src/util/enriched_string.cpp
+++ b/src/util/enriched_string.cpp
@@ -97,7 +97,6 @@ void EnrichedString::addAtEnd(const std::wstring &s, const SColor &initial_color
parseColorString(wide_to_utf8(parts[1]), m_background, true);
m_has_background = true;
}
- continue;
}
}
@@ -111,7 +110,7 @@ void EnrichedString::addCharNoColor(wchar_t c)
{
m_string += c;
if (m_colors.empty()) {
- m_colors.push_back(SColor(255, 255, 255, 255));
+ m_colors.emplace_back(255, 255, 255, 255);
} else {
m_colors.push_back(m_colors[m_colors.size() - 1]);
}
@@ -138,15 +137,16 @@ EnrichedString EnrichedString::substr(size_t pos, size_t len) const
}
if (len == std::string::npos || pos + len > m_string.length()) {
return EnrichedString(
- m_string.substr(pos, std::string::npos),
- std::vector<SColor>(m_colors.begin() + pos, m_colors.end())
- );
- } else {
- return EnrichedString(
- m_string.substr(pos, len),
- std::vector<SColor>(m_colors.begin() + pos, m_colors.begin() + pos + len)
- );
+ m_string.substr(pos, std::string::npos),
+ std::vector<SColor>(m_colors.begin() + pos, m_colors.end())
+ );
}
+
+ return EnrichedString(
+ m_string.substr(pos, len),
+ std::vector<SColor>(m_colors.begin() + pos, m_colors.begin() + pos + len)
+ );
+
}
const wchar_t *EnrichedString::c_str() const
diff --git a/src/util/numeric.h b/src/util/numeric.h
index 36e6fddd0..766efd366 100644
--- a/src/util/numeric.h
+++ b/src/util/numeric.h
@@ -281,7 +281,8 @@ inline aabb3f getNodeBox(v3s16 p, float d)
class IntervalLimiter
{
public:
- IntervalLimiter() {}
+ IntervalLimiter() = default;
+
/*
dtime: time from last call to this method
wanted_interval: interval wanted
diff --git a/src/util/srp.cpp b/src/util/srp.cpp
index aa8dcb4a7..4c1a772e2 100644
--- a/src/util/srp.cpp
+++ b/src/util/srp.cpp
@@ -697,7 +697,7 @@ struct SRPVerifier *srp_verifier_new(SRP_HashAlgorithm alg,
goto cleanup_and_exit;
}
- memcpy((char *)ver->username, username, ulen);
+ memcpy(ver->username, username, ulen);
ver->authenticated = 0;
diff --git a/src/util/string.cpp b/src/util/string.cpp
index d41b91f24..fc2a2057f 100644
--- a/src/util/string.cpp
+++ b/src/util/string.cpp
@@ -167,7 +167,7 @@ std::string wide_to_utf8(const std::wstring &input)
wchar_t *utf8_to_wide_c(const char *str)
{
- std::wstring ret = utf8_to_wide(std::string(str)).c_str();
+ std::wstring ret = utf8_to_wide(std::string(str));
size_t len = ret.length();
wchar_t *ret_c = new wchar_t[len + 1];
memset(ret_c, 0, (len + 1) * sizeof(wchar_t));
@@ -308,8 +308,8 @@ std::string wide_to_narrow(const std::wstring &wcs)
size_t len = wcstombs(*mbs, wcs.c_str(), mbl);
if (len == (size_t)(-1))
return "Character conversion failed!";
- else
- mbs[len] = 0;
+
+ mbs[len] = 0;
return *mbs;
}
@@ -321,8 +321,7 @@ std::string urlencode(const std::string &str)
// followed by two hex digits. See RFC 3986, section 2.3.
static const char url_hex_chars[] = "0123456789ABCDEF";
std::ostringstream oss(std::ios::binary);
- for (u32 i = 0; i < str.size(); i++) {
- unsigned char c = str[i];
+ for (unsigned char c : str) {
if (isalnum(c) || c == '-' || c == '.' || c == '_' || c == '~') {
oss << c;
} else {
diff --git a/src/util/string.h b/src/util/string.h
index 584ffb73a..122262af8 100644
--- a/src/util/string.h
+++ b/src/util/string.h
@@ -20,7 +20,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#pragma once
#include "irrlichttypes_bloated.h"
-#include <stdlib.h>
+#include <cstdlib>
#include <string>
#include <cstring>
#include <vector>
@@ -231,12 +231,12 @@ inline std::vector<std::basic_string<T> > str_split(
*/
inline std::string lowercase(const std::string &str)
{
- std::string s2 = "";
+ std::string s2;
s2.reserve(str.size());
- for (size_t i = 0; i < str.size(); i++)
- s2 += tolower(str[i]);
+ for (char i : str)
+ s2 += tolower(i);
return s2;
}
@@ -607,8 +607,8 @@ std::vector<std::basic_string<T> > split(const std::basic_string<T> &s, T delim)
*/
inline bool is_number(const std::string &to_check)
{
- for (size_t i = 0; i < to_check.size(); i++)
- if (!std::isdigit(to_check[i]))
+ for (char i : to_check)
+ if (!std::isdigit(i))
return false;
return !to_check.empty();