From a119e6ca70ffab14f0a70908fa3eeb83b41bb5ab Mon Sep 17 00:00:00 2001 From: HampusM Date: Mon, 14 Mar 2022 10:24:36 +0100 Subject: refactor: rename std to common --- src/common/conversion.cpp | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 src/common/conversion.cpp (limited to 'src/common/conversion.cpp') diff --git a/src/common/conversion.cpp b/src/common/conversion.cpp new file mode 100644 index 0000000..0bdc81a --- /dev/null +++ b/src/common/conversion.cpp @@ -0,0 +1,39 @@ +#include "conversion.hpp" + +namespace common +{ + +common::UniquePtr doubleToStr(double num, unsigned int width, + unsigned int precision) +{ + auto str = common::make_unique(width + precision); + + dtostrf(num, static_cast(width), static_cast(precision), + str->c_str); + + return str; +} + +common::UniquePtr intToStr(int num) +{ + auto width = static_cast(log10(num)); + + auto str = common::make_unique(width + 1U); + + dtostrf(num, static_cast(width + 1U), 0U, str->c_str); + + return str; +} + +common::UniquePtr uintToStr(unsigned int num) +{ + auto width = static_cast(log10(num)); + + auto str = common::make_unique(width + 1U); + + dtostrf(num, static_cast(width + 1U), 0U, str->c_str); + + return str; +} + +} // namespace common -- cgit v1.2.3-18-g5258