diff options
author | Toni Uhlig <matzeton@googlemail.com> | 2023-09-15 01:55:26 +0200 |
---|---|---|
committer | Toni Uhlig <matzeton@googlemail.com> | 2023-09-15 01:55:26 +0200 |
commit | 43339d5e7917d2d50e071d53a3a3eebec5f33afb (patch) | |
tree | e0363f496790f668fbeb237f1a2d5f5a2033fbcd /CRT/eastl_compat.cpp | |
parent | 5c24a28bc6f5da20a1bc631a075c20ff343c8457 (diff) |
Added `nanoprintf.h` header only library to implement `::to_string` functions.
* `eastl::to_string` does not work for now
Signed-off-by: Toni Uhlig <matzeton@googlemail.com>
Diffstat (limited to 'CRT/eastl_compat.cpp')
-rw-r--r-- | CRT/eastl_compat.cpp | 120 |
1 files changed, 120 insertions, 0 deletions
diff --git a/CRT/eastl_compat.cpp b/CRT/eastl_compat.cpp new file mode 100644 index 0000000..43068b3 --- /dev/null +++ b/CRT/eastl_compat.cpp @@ -0,0 +1,120 @@ +#include "eastl_compat.hpp" + +#define NANOPRINTF_VISIBILITY_STATIC 1 +#define NANOPRINTF_USE_FLOAT_FORMAT_SPECIFIERS 1 +#define NANOPRINTF_USE_PRECISION_FORMAT_SPECIFIERS 1 +#define NANOPRINTF_USE_FIELD_WIDTH_FORMAT_SPECIFIERS 1 +#define NANOPRINTF_USE_LARGE_FORMAT_SPECIFIERS 1 +#define NANOPRINTF_USE_BINARY_FORMAT_SPECIFIERS 0 +#define NANOPRINTF_USE_WRITEBACK_FORMAT_SPECIFIERS 0 +#define NANOPRINTF_IMPLEMENTATION 1 +#include "nanoprintf.h" + +/* + * eastl::to_string(...) does not work yet event if with a provided Vsnprintf/Vsnprintf8 + * The issue seems to be caused by a broken va_list/va_copy. + */ + +eastl::string to_string(int value) +{ + int nbytes = npf_snprintf(nullptr, 0, "%d", value); + if (nbytes > 0) + { + char result[nbytes + 1] = {}; + npf_snprintf(result, nbytes, "%d", value); + return result; + } + else + return ""; +} + +eastl::string to_string(long value) +{ + int nbytes = npf_snprintf(nullptr, 0, "%ld", value); + if (nbytes > 0) + { + char result[nbytes + 1] = {}; + npf_snprintf(result, nbytes, "%ld", value); + return result; + } + else + return ""; +} + +eastl::string to_string(long long value) +{ + int nbytes = npf_snprintf(nullptr, 0, "%lld", value); + if (nbytes > 0) + { + char result[nbytes + 1] = {}; + npf_snprintf(result, nbytes, "%lld", value); + return result; + } + else + return ""; +} + +eastl::string to_string(unsigned int value) +{ + int nbytes = npf_snprintf(nullptr, 0, "%u", value); + if (nbytes > 0) + { + char result[nbytes + 1] = {}; + npf_snprintf(result, nbytes, "%u", value); + return result; + } + else + return ""; +} + +eastl::string to_string(unsigned long int value) +{ + int nbytes = npf_snprintf(nullptr, 0, "%lu", value); + if (nbytes > 0) + { + char result[nbytes + 1] = {}; + npf_snprintf(result, nbytes, "%lu", value); + return result; + } + else + return ""; +} + +eastl::string to_string(unsigned long long int value) +{ + int nbytes = npf_snprintf(nullptr, 0, "%llu", value); + if (nbytes > 0) + { + char result[nbytes + 1] = {}; + npf_snprintf(result, nbytes, "%llu", value); + return result; + } + else + return ""; +} + +eastl::string to_string(float value) +{ + int nbytes = npf_snprintf(nullptr, 0, "%f", value); + if (nbytes > 0) + { + char result[nbytes + 1] = {}; + npf_snprintf(result, nbytes, "%f", value); + return result; + } + else + return ""; +} + +eastl::string to_string(double value) +{ + int nbytes = npf_snprintf(nullptr, 0, "%lf", value); + if (nbytes > 0) + { + char result[nbytes + 1] = {}; + npf_snprintf(result, nbytes, "%lf", value); + return result; + } + else + return ""; +} |