mirror of https://github.com/catchorg/Catch2.git
Use internal linkage for float stringification helper
This commit is contained in:
parent
cb25c4a8a3
commit
a595066ff9
|
@ -41,25 +41,6 @@ namespace Detail {
|
||||||
return value ? Little : Big;
|
return value ? Little : Big;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
|
||||||
|
|
||||||
std::string rawMemoryToString( const void *object, std::size_t size ) {
|
|
||||||
// Reverse order for little endian architectures
|
|
||||||
int i = 0, end = static_cast<int>( size ), inc = 1;
|
|
||||||
if( Endianness::which() == Endianness::Little ) {
|
|
||||||
i = end-1;
|
|
||||||
end = inc = -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
unsigned char const *bytes = static_cast<unsigned char const *>(object);
|
|
||||||
ReusableStringStream rss;
|
|
||||||
rss << "0x" << std::setfill('0') << std::hex;
|
|
||||||
for( ; i != end; i += inc )
|
|
||||||
rss << std::setw(2) << static_cast<unsigned>(bytes[i]);
|
|
||||||
return rss.str();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
std::string fpToString(T value, int precision) {
|
std::string fpToString(T value, int precision) {
|
||||||
|
@ -80,6 +61,25 @@ std::string fpToString( T value, int precision ) {
|
||||||
}
|
}
|
||||||
return d;
|
return d;
|
||||||
}
|
}
|
||||||
|
} // end unnamed namespace
|
||||||
|
|
||||||
|
std::string rawMemoryToString( const void *object, std::size_t size ) {
|
||||||
|
// Reverse order for little endian architectures
|
||||||
|
int i = 0, end = static_cast<int>( size ), inc = 1;
|
||||||
|
if( Endianness::which() == Endianness::Little ) {
|
||||||
|
i = end-1;
|
||||||
|
end = inc = -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned char const *bytes = static_cast<unsigned char const *>(object);
|
||||||
|
ReusableStringStream rss;
|
||||||
|
rss << "0x" << std::setfill('0') << std::hex;
|
||||||
|
for( ; i != end; i += inc )
|
||||||
|
rss << std::setw(2) << static_cast<unsigned>(bytes[i]);
|
||||||
|
return rss.str();
|
||||||
|
}
|
||||||
|
} // end Detail namespace
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//// ======================================================= ////
|
//// ======================================================= ////
|
||||||
|
@ -228,13 +228,13 @@ std::string StringMaker<unsigned char>::convert(unsigned char c) {
|
||||||
int StringMaker<float>::precision = 5;
|
int StringMaker<float>::precision = 5;
|
||||||
|
|
||||||
std::string StringMaker<float>::convert(float value) {
|
std::string StringMaker<float>::convert(float value) {
|
||||||
return fpToString(value, precision) + 'f';
|
return Detail::fpToString(value, precision) + 'f';
|
||||||
}
|
}
|
||||||
|
|
||||||
int StringMaker<double>::precision = 10;
|
int StringMaker<double>::precision = 10;
|
||||||
|
|
||||||
std::string StringMaker<double>::convert(double value) {
|
std::string StringMaker<double>::convert(double value) {
|
||||||
return fpToString(value, precision);
|
return Detail::fpToString(value, precision);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // end namespace Catch
|
} // end namespace Catch
|
||||||
|
|
Loading…
Reference in New Issue