diff options
Diffstat (limited to 'zap/source/any/str/fmtlen.cc')
-rw-r--r-- | zap/source/any/str/fmtlen.cc | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/zap/source/any/str/fmtlen.cc b/zap/source/any/str/fmtlen.cc new file mode 100644 index 0000000..866d011 --- /dev/null +++ b/zap/source/any/str/fmtlen.cc @@ -0,0 +1,37 @@ +/* + 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/math.h> +#include <zap/str.h> + +#include "numdig.hh" + +namespace zap { + namespace impl { + template<typename typ> zap_priv_inln inline static auto fmtlen(typ val,::zap::i8 const bs) noexcept -> ::zap::i8 { + ::zap::i8 len = 0x0u; + if (val < 0x0) { + val = static_cast<typ>(::zap::abs(val)); + len = 0x1u; + } + len += ::zap::impl::numdig(val,bs); + return len; + } + } +} + +extern "C" { + auto zap_fmtleni( int const val,::zap::i8 const bs) -> ::zap::i8 {return ::zap::impl::fmtlen(val,bs);} + auto zap_fmtlenl( long const val,::zap::i8 const bs) -> ::zap::i8 {return ::zap::impl::fmtlen(val,bs);} + auto zap_fmtlenll( long long const val,::zap::i8 const bs) -> ::zap::i8 {return ::zap::impl::fmtlen(val,bs);} + auto zap_fmtlens( short const val,::zap::i8 const bs) -> ::zap::i8 {return ::zap::impl::fmtlen(val,bs);} + auto zap_fmtlensc( signed char const val,::zap::i8 const bs) -> ::zap::i8 {return ::zap::impl::fmtlen(val,bs);} + auto zap_fmtlenuc( unsigned char const val,::zap::i8 const bs) -> ::zap::i8 {return ::zap::impl::fmtlen(val,bs);} + auto zap_fmtlenui( unsigned int const val,::zap::i8 const bs) -> ::zap::i8 {return ::zap::impl::fmtlen(val,bs);} + auto zap_fmtlenul( unsigned long const val,::zap::i8 const bs) -> ::zap::i8 {return ::zap::impl::fmtlen(val,bs);} + auto zap_fmtlenull(unsigned long long const val,::zap::i8 const bs) -> ::zap::i8 {return ::zap::impl::fmtlen(val,bs);} + auto zap_fmtlenus( unsigned short const val,::zap::i8 const bs) -> ::zap::i8 {return ::zap::impl::fmtlen(val,bs);} +} |