summaryrefslogtreecommitdiff
path: root/src/common/conversion.cpp
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2022-03-14 10:24:36 +0100
committerHampusM <hampus@hampusmat.com>2022-03-14 10:24:36 +0100
commita119e6ca70ffab14f0a70908fa3eeb83b41bb5ab (patch)
tree51b72774694f5e1aac0bb17fc1a5e528dbad9b44 /src/common/conversion.cpp
parent6b5754655f78a7f93b756ff902ce9fd80d9dc4ec (diff)
refactor: rename std to common
Diffstat (limited to 'src/common/conversion.cpp')
-rw-r--r--src/common/conversion.cpp39
1 files changed, 39 insertions, 0 deletions
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<common::String> doubleToStr(double num, unsigned int width,
+ unsigned int precision)
+{
+ auto str = common::make_unique<common::String>(width + precision);
+
+ dtostrf(num, static_cast<signed char>(width), static_cast<unsigned char>(precision),
+ str->c_str);
+
+ return str;
+}
+
+common::UniquePtr<common::String> intToStr(int num)
+{
+ auto width = static_cast<unsigned int>(log10(num));
+
+ auto str = common::make_unique<common::String>(width + 1U);
+
+ dtostrf(num, static_cast<signed char>(width + 1U), 0U, str->c_str);
+
+ return str;
+}
+
+common::UniquePtr<common::String> uintToStr(unsigned int num)
+{
+ auto width = static_cast<unsigned int>(log10(num));
+
+ auto str = common::make_unique<common::String>(width + 1U);
+
+ dtostrf(num, static_cast<signed char>(width + 1U), 0U, str->c_str);
+
+ return str;
+}
+
+} // namespace common