Read-only mirrors. Development, issues and pull requests are on GitHub.

summaryrefslogtreecommitdiffhomepage
path: root/src/catch2
diff options
context:
space:
mode:
authorMartin Hořeňovský2020-05-10 06:54:19 +0200
committerMartin Hořeňovský2020-05-10 06:54:23 +0200
commita595066ff9ed0af56957c48971b8a0beb941525e (patch)
treeed87cb257a663ac96e836542406108992381cfd1 /src/catch2
parentcb25c4a8a3d8857b07f7b87e4879a8a993c47de7 (diff)
downloadcatch3-a595066ff9ed0af56957c48971b8a0beb941525e.tar.gz
Use internal linkage for float stringification helper
Diffstat (limited to 'src/catch2')
-rw-r--r--src/catch2/catch_tostring.cpp48
1 files changed, 24 insertions, 24 deletions
diff --git a/src/catch2/catch_tostring.cpp b/src/catch2/catch_tostring.cpp
index 4eeabbae..d8b90dfd 100644
--- a/src/catch2/catch_tostring.cpp
+++ b/src/catch2/catch_tostring.cpp
@@ -41,7 +41,27 @@ namespace Detail {
return value ? Little : Big;
}
};
- }
+
+ template<typename T>
+ std::string fpToString(T value, int precision) {
+ if (Catch::isnan(value)) {
+ return "nan";
+ }
+
+ ReusableStringStream rss;
+ rss << std::setprecision(precision)
+ << std::fixed
+ << value;
+ std::string d = rss.str();
+ std::size_t i = d.find_last_not_of('0');
+ if (i != std::string::npos && i != d.size() - 1) {
+ if (d[i] == '.')
+ i++;
+ d = d.substr(0, i + 1);
+ }
+ return d;
+ }
+ } // end unnamed namespace
std::string rawMemoryToString( const void *object, std::size_t size ) {
// Reverse order for little endian architectures
@@ -58,29 +78,9 @@ namespace Detail {
rss << std::setw(2) << static_cast<unsigned>(bytes[i]);
return rss.str();
}
-}
+} // end Detail namespace
-template<typename T>
-std::string fpToString( T value, int precision ) {
- if (Catch::isnan(value)) {
- return "nan";
- }
-
- ReusableStringStream rss;
- rss << std::setprecision( precision )
- << std::fixed
- << value;
- std::string d = rss.str();
- std::size_t i = d.find_last_not_of( '0' );
- if( i != std::string::npos && i != d.size()-1 ) {
- if( d[i] == '.' )
- i++;
- d = d.substr( 0, i+1 );
- }
- return d;
-}
-
//// ======================================================= ////
//
@@ -228,13 +228,13 @@ std::string StringMaker<unsigned char>::convert(unsigned char c) {
int StringMaker<float>::precision = 5;
std::string StringMaker<float>::convert(float value) {
- return fpToString(value, precision) + 'f';
+ return Detail::fpToString(value, precision) + 'f';
}
int StringMaker<double>::precision = 10;
std::string StringMaker<double>::convert(double value) {
- return fpToString(value, precision);
+ return Detail::fpToString(value, precision);
}
} // end namespace Catch