Remove some dead code and fix format output when to_chars gives a value other than 'nan' or 'inf'

This commit is contained in:
rexy712 2022-06-30 12:14:23 -07:00
parent dfa4202e55
commit 7ee0beb343
3 changed files with 11 additions and 4 deletions

View File

@ -30,7 +30,7 @@
#include "parse.hpp"
#include "utf_iterator.hpp"
#include "../../utility.hpp" //abs
#include "../../utility.hpp" //abs, memcpy
#include <type_traits> //remove_cvref
#include <utility> //forward, move
@ -537,7 +537,14 @@ namespace rexy::fmt::detail{
break;
};
if(manual_precision){
//manually handle nan and inf since some compilers (msvc) output something other than the desired values in 'to_chars'
if(is_nan){
result.ptr = buffstart + 3;
rexy::memcpy(buffstart, "nan", 3);
}else if(is_infinity){
result.ptr = buffstart + 3;
rexy::memcpy(buffstart, "inf", 3);
}else if(manual_precision){
const int precision = supplied_precision ? specs.precision : 6;
result = std::to_chars(buffstart, buffend, f, fmt, precision);
}else{

View File

@ -114,6 +114,7 @@ namespace rexy::fmt::detail{
if(written != this->m_size){
REXY_THROW_FORMAT_ERROR("Failed to print data");
}
return written;
}
};

View File

@ -80,8 +80,8 @@ namespace rexy::fmt::detail::parse{
return static_cast<long long>(t);
}else{
REXY_THROW_FORMAT_ERROR("Invalid dynamic specifier");
return static_cast<long long>(0);
}
return {};
}
template<class Specs>
constexpr decltype(auto) dynamic_width_adapter<Specs>::operator()(void){
@ -182,7 +182,6 @@ namespace rexy::fmt::detail::parse{
}
}
return last;
REXY_THROW_FORMAT_ERROR("Invalid index spec");
}
for(auto it = start+1;it != last;++it){
if(!is_a_number(*it)){