]> git.lizzy.rs Git - minetest.git/blobdiff - src/util/string.h
Modernize source code: last part (#6285)
[minetest.git] / src / util / string.h
index cc278da1323d06185499788268e034499217e2f3..122262af85348d227c10ba94c3fd5fb902df9f89 100644 (file)
@@ -17,12 +17,10 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */
 
-#ifndef UTIL_STRING_HEADER
-#define UTIL_STRING_HEADER
+#pragma once
 
 #include "irrlichttypes_bloated.h"
-#include "cpp11_container.h"
-#include <stdlib.h>
+#include <cstdlib>
 #include <string>
 #include <cstring>
 #include <vector>
@@ -30,6 +28,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include <sstream>
 #include <iomanip>
 #include <cctype>
+#include <unordered_map>
 
 #define STRINGIFY(x) #x
 #define TOSTRING(x) STRINGIFY(x)
@@ -55,7 +54,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
        (((unsigned char)(x) < 0xe0) ? 2 :     \
        (((unsigned char)(x) < 0xf0) ? 3 : 4))
 
-typedef UNORDERED_MAP<std::string, std::string> StringMap;
+typedef std::unordered_map<std::string, std::string> StringMap;
 
 struct FlagDesc {
        const char *name;
@@ -232,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;
 }
@@ -608,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();
@@ -648,6 +647,3 @@ inline const std::string duration_to_string(int sec)
 
        return ss.str();
 }
-
-
-#endif