From da9098d0e40e09e7d37049225b9c1929e155bf47 Mon Sep 17 00:00:00 2001 From: Olaf van der Spek Date: Sun, 31 Oct 2021 10:05:17 +0100 Subject: [PATCH] --- Library/StdAfx.h | 1 + misc/map_ra_ini_reader.cpp | 10 +++++----- misc/map_td_ini_reader.cpp | 8 ++++---- misc/string_conversion.cpp | 5 ++--- misc/xcc/string_view.h | 15 +++++++++------ vcpkg-install.txt | 2 +- 6 files changed, 22 insertions(+), 19 deletions(-) diff --git a/Library/StdAfx.h b/Library/StdAfx.h index b8525e47..520a54db 100644 --- a/Library/StdAfx.h +++ b/Library/StdAfx.h @@ -16,6 +16,7 @@ #include #include #include +#include using namespace std; using boost::iequals; diff --git a/misc/map_ra_ini_reader.cpp b/misc/map_ra_ini_reader.cpp index 60555c5f..00932a29 100644 --- a/misc/map_ra_ini_reader.cpp +++ b/misc/map_ra_ini_reader.cpp @@ -18,7 +18,7 @@ void Cmap_ra_ini_reader::erase() int Cmap_ra_ini_reader::process_section_start(const string& line) { - m_section = static_cast(find_id(line, section_code, sei_unknown)); + m_section = t_section_id(find_id(line, section_code, sei_unknown)); return 0; } @@ -46,16 +46,16 @@ int Cmap_ra_ini_reader::process_key(const string& name, const string& value) switch (find_id(name, map_code, mai_unknown)) { case mai_x: - m_map_data.x = atoi(value.c_str()); + m_map_data.x = to_int(value); break; case mai_y: - m_map_data.y = atoi(value.c_str()); + m_map_data.y = to_int(value); break; case mai_cx: - m_map_data.cx = atoi(value.c_str()); + m_map_data.cx = to_int(value); break; case mai_cy: - m_map_data.cy = atoi(value.c_str()); + m_map_data.cy = to_int(value); break; case mai_theater: m_map_data.theater = value; diff --git a/misc/map_td_ini_reader.cpp b/misc/map_td_ini_reader.cpp index 44625ba9..84f40251 100644 --- a/misc/map_td_ini_reader.cpp +++ b/misc/map_td_ini_reader.cpp @@ -46,16 +46,16 @@ int Cmap_td_ini_reader::process_key(const string& name, const string& value) switch (find_id(name, map_code, mai_unknown)) { case mai_x: - m_map_data.x = atoi(value.c_str()); + m_map_data.x = to_int(value); break; case mai_y: - m_map_data.y = atoi(value.c_str()); + m_map_data.y = to_int(value); break; case mai_cx: - m_map_data.cx = atoi(value.c_str()); + m_map_data.cx = to_int(value); break; case mai_cy: - m_map_data.cy = atoi(value.c_str()); + m_map_data.cy = to_int(value); break; case mai_theater: m_map_data.theater = value; diff --git a/misc/string_conversion.cpp b/misc/string_conversion.cpp index ab749d5e..eef57b3c 100644 --- a/misc/string_conversion.cpp +++ b/misc/string_conversion.cpp @@ -71,20 +71,19 @@ string n(unsigned long long v) string swsl(int l, string s) { while (s.size() < l) - s = ' '+ s; + s = ' ' + s; return s; } string swsr(int l, string s) { while (s.size() < l) - s = s + ' '; + s += ' '; return s; } string nwzl(int l, unsigned int v) { - string s = n(v); while (s.size() < l) s = '0' + s; diff --git a/misc/xcc/string_view.h b/misc/xcc/string_view.h index 757f10f6..7d048896 100644 --- a/misc/xcc/string_view.h +++ b/misc/xcc/string_view.h @@ -1,7 +1,6 @@ #pragma once -#include -#include +#include #include #include @@ -16,14 +15,18 @@ inline std::enable_if_t::value, std::string&> operator<<(std return a += std::to_string(b); } -inline float to_float(std::string_view v) +inline float to_float(std::string_view s) { - return boost::convert(v, boost::cnv::strtol(), 0.0f); + float v; + auto res = std::from_chars(s.data(), s.data() + s.size(), v); + return res.ec == std::errc() && res.ptr == s.data() + s.size() ? v : 0; } -inline long long to_int(std::string_view v) +inline long long to_int(std::string_view s) { - return boost::convert(v, boost::cnv::strtol(), 0); + long long v; + auto res = std::from_chars(s.data(), s.data() + s.size(), v); + return res.ec == std::errc() && res.ptr == s.data() + s.size() ? v : 0; } template diff --git a/vcpkg-install.txt b/vcpkg-install.txt index 170983d3..9f05c0e8 100644 --- a/vcpkg-install.txt +++ b/vcpkg-install.txt @@ -1 +1 @@ -vcpkg install boost-convert boost-crc bzip2 libjpeg-turbo libpng libvorbis lzo +vcpkg install boost-algorithm boost-crc bzip2 libjpeg-turbo libpng libvorbis lzo