Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use C++20's from_chars #24

Merged
merged 1 commit into from
Mar 26, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 11 additions & 15 deletions graphics/meshes/shared.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,28 +12,24 @@

#include <aw/io/input_stream_utils.h>

#include <aw/utility/string/trim.h>
#include <aw/utility/string/split.h>
#include <aw/utility/string/strto.h>
#include <aw/utility/string/trim.h>

//#include <aw/types/promote.h>
#include <limits>
#include <cassert>
#include <charconv>

namespace aw {
namespace obj {
namespace aw::obj {
constexpr string_view ws (" \t\v\f\r", 5);


template<typename T>
bool parse1(string_view line, T& v)
{
char* end;
std::string tmp(line);
// unfortunately, strto* requires string to be null-terminated

v = strto<T>( tmp.data(), &end );
return (end != tmp.data());
auto result = std::from_chars(begin(line), end(line), v);
if (result.ec != std::errc()) {
v = T();
return false;
}
return true;
}

using split_func = std::vector<string_view>(string_view, string_view);
Expand Down Expand Up @@ -74,6 +70,6 @@ size_t parse3(string_view line, T(&arr)[3], string_view delim = ws)
{
return parse3(line, arr[0], arr[1], arr[2], delim);
}
} // namespace obj
} // namespace aw
} // namespace aw::obj

#endif//aw_internal_obj_shared_h
Loading