entdata.cc: avoid exception-throwing std::stod/stoi
mostly because it's annoying when debugging with "break on first exception thrown"
This commit is contained in:
parent
35fa5bd129
commit
0dfb4e52ab
|
|
@ -20,6 +20,7 @@
|
|||
#include <common/entdata.h>
|
||||
|
||||
#include <sstream>
|
||||
#include <cstdlib> // atoi()
|
||||
|
||||
#include <common/bsputils.hh>
|
||||
#include <common/parser.hh>
|
||||
|
|
@ -50,32 +51,24 @@ const std::string &entdict_t::get(const std::string_view &key) const
|
|||
|
||||
vec_t entdict_t::get_float(const std::string_view &key) const
|
||||
{
|
||||
auto s = get(key);
|
||||
const std::string &s = get(key);
|
||||
|
||||
if (s.empty()) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
try {
|
||||
return std::stod(s);
|
||||
} catch (std::exception &) {
|
||||
return 0.0;
|
||||
}
|
||||
return atof(s.data());
|
||||
}
|
||||
|
||||
int32_t entdict_t::get_int(const std::string_view &key) const
|
||||
{
|
||||
auto s = get(key);
|
||||
const std::string &s = get(key);
|
||||
|
||||
if (s.empty()) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
try {
|
||||
return std::stoi(s);
|
||||
} catch (std::exception &) {
|
||||
return 0;
|
||||
}
|
||||
return atoi(s.data());
|
||||
}
|
||||
|
||||
int32_t entdict_t::get_vector(const std::string_view &key, qvec3d &vec) const
|
||||
|
|
|
|||
Loading…
Reference in New Issue