Skip to content

Commit

Permalink
No commit message
Browse files Browse the repository at this point in the history
  • Loading branch information
OlafvdSpek committed Oct 31, 2021
1 parent b8a746c commit da9098d
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 19 deletions.
1 change: 1 addition & 0 deletions Library/StdAfx.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include <vector>
#include <xcc/data_ref.h>
#include <xcc/find_ptr.h>
#include <xcc/string_view.h>

using namespace std;
using boost::iequals;
Expand Down
10 changes: 5 additions & 5 deletions misc/map_ra_ini_reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<t_section_id>(find_id(line, section_code, sei_unknown));
m_section = t_section_id(find_id(line, section_code, sei_unknown));
return 0;
}

Expand Down Expand Up @@ -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;
Expand Down
8 changes: 4 additions & 4 deletions misc/map_td_ini_reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 2 additions & 3 deletions misc/string_conversion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
15 changes: 9 additions & 6 deletions misc/xcc/string_view.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#pragma once

#include <boost/convert.hpp>
#include <boost/convert/strtol.hpp>
#include <charconv>
#include <string>
#include <string_view>

Expand All @@ -16,14 +15,18 @@ inline std::enable_if_t<std::is_integral<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<float>(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<long long>(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<size_t N>
Expand Down
2 changes: 1 addition & 1 deletion vcpkg-install.txt
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit da9098d

Please sign in to comment.