summaryrefslogtreecommitdiff
path: root/zap/source/any/str/fmt.cc
diff options
context:
space:
mode:
Diffstat (limited to 'zap/source/any/str/fmt.cc')
-rw-r--r--zap/source/any/str/fmt.cc43
1 files changed, 43 insertions, 0 deletions
diff --git a/zap/source/any/str/fmt.cc b/zap/source/any/str/fmt.cc
new file mode 100644
index 0000000..b2c0c75
--- /dev/null
+++ b/zap/source/any/str/fmt.cc
@@ -0,0 +1,43 @@
+/*
+ Copyright 2022-2023 Gabriel Jensen.
+ This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
+ If a copy of the MPL was not distributed with this file, You can obtain one at <https://mozilla.org/MPL/2.0>.
+*/
+
+#include <zap/str.h>
+
+#include "numdig.hh"
+
+namespace zap {
+ namespace impl {
+ template<typename signtyp> zap_priv_inln inline static auto fmt(::zap::i02 * buf,signtyp signval,::zap::i8 const bs,::zap::i8 const rtl) noexcept -> void {
+ using typ = typename ::zap::usign<signtyp>;
+ char32_t const * digs = U"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
+ if (bs == 0xCu) digs = U"0123456789\u218A\u218B";
+ if (signval < 0x0) {
+ signval = -signval;
+ *buf++ = 0x2212u;
+ }
+ typ val = static_cast<typ>(signval);
+ if (rtl) {
+ buf += ::zap::impl::numdig(val,bs) - 0x1u;
+ for (;val > 0x0u;val /= bs) *buf-- = static_cast<::zap::i02>(digs[static_cast<::zap::sz>(val % static_cast<typ>(bs))]);
+ return;
+ }
+ for (;val > 0x0u;val /= bs) *buf++ = static_cast<::zap::i02>(digs[static_cast<::zap::sz>(val % static_cast<typ>(bs))]);
+ }
+ }
+}
+
+extern "C" {
+ auto zap_fmti( ::zap::i02 * const buf,int const val,::zap::i8 const bs,::zap::i8 const rtl) -> void {return ::zap::impl::fmt(buf,val,bs,rtl);}
+ auto zap_fmtl( ::zap::i02 * const buf,long const val,::zap::i8 const bs,::zap::i8 const rtl) -> void {return ::zap::impl::fmt(buf,val,bs,rtl);}
+ auto zap_fmtll( ::zap::i02 * const buf,long long const val,::zap::i8 const bs,::zap::i8 const rtl) -> void {return ::zap::impl::fmt(buf,val,bs,rtl);}
+ auto zap_fmts( ::zap::i02 * const buf,short const val,::zap::i8 const bs,::zap::i8 const rtl) -> void {return ::zap::impl::fmt(buf,val,bs,rtl);}
+ auto zap_fmtsc( ::zap::i02 * const buf,signed char const val,::zap::i8 const bs,::zap::i8 const rtl) -> void {return ::zap::impl::fmt(buf,val,bs,rtl);}
+ auto zap_fmtuc( ::zap::i02 * const buf,unsigned char const val,::zap::i8 const bs,::zap::i8 const rtl) -> void {return ::zap::impl::fmt(buf,val,bs,rtl);}
+ auto zap_fmtui( ::zap::i02 * const buf,unsigned int const val,::zap::i8 const bs,::zap::i8 const rtl) -> void {return ::zap::impl::fmt(buf,val,bs,rtl);}
+ auto zap_fmtul( ::zap::i02 * const buf,unsigned long const val,::zap::i8 const bs,::zap::i8 const rtl) -> void {return ::zap::impl::fmt(buf,val,bs,rtl);}
+ auto zap_fmtull(::zap::i02 * const buf,unsigned long long const val,::zap::i8 const bs,::zap::i8 const rtl) -> void {return ::zap::impl::fmt(buf,val,bs,rtl);}
+ auto zap_fmtus( ::zap::i02 * const buf,unsigned short const val,::zap::i8 const bs,::zap::i8 const rtl) -> void {return ::zap::impl::fmt(buf,val,bs,rtl);}
+}