diff options
Diffstat (limited to 'zp/include-private')
-rw-r--r-- | zp/include-private/zp/prv | 25 | ||||
-rw-r--r-- | zp/include-private/zp/prv.h | 16 | ||||
-rw-r--r-- | zp/include-private/zp/prv/fmt | 47 | ||||
-rw-r--r-- | zp/include-private/zp/prv/str (renamed from zp/include-private/zp/imp/prv.ii) | 24 |
4 files changed, 66 insertions, 46 deletions
diff --git a/zp/include-private/zp/prv b/zp/include-private/zp/prv deleted file mode 100644 index 03e63e5..0000000 --- a/zp/include-private/zp/prv +++ /dev/null @@ -1,25 +0,0 @@ -/* - 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>. -*/ - -#ifndef zp_prv_cxxhdr_prv -#define zp_prv_cxxhdr_prv - -#include <zp/zp> -#include <zp/prv.h> - -namespace zp { - namespace det { - template<typename typ> zp_nothw ::zp::siz strcpy(typ * dst, typ const * src); - template<typename typ> zp_nothw bool strequ(typ const * lstr,typ const * rsrc); - template<typename typ> zp_nothw ::zp::siz strfil(typ * dst, typ chr); - template<typename typ> zp_nothw ::zp::siz strlen(typ const * str); - template<typename typ> zp_nothw typ * strsrh(typ const * str, typ chr); - } -} - -#include <zp/imp/prv.ii> - -#endif diff --git a/zp/include-private/zp/prv.h b/zp/include-private/zp/prv.h deleted file mode 100644 index 2d25dc0..0000000 --- a/zp/include-private/zp/prv.h +++ /dev/null @@ -1,16 +0,0 @@ -/* - 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>. -*/ - -#ifndef zp_prv_hdr_prv -#define zp_prv_hdr_prv - -#include <zp/zp.h> - -zp_prv_cdecl - -zp_prv_cdeclend - -#endif diff --git a/zp/include-private/zp/prv/fmt b/zp/include-private/zp/prv/fmt new file mode 100644 index 0000000..52a6935 --- /dev/null +++ b/zp/include-private/zp/prv/fmt @@ -0,0 +1,47 @@ +/* + 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>. +*/ + +#pragma once + +#include <zp/str> + + + +template<typename typ> zp_nothw ::zp::siz zp::prv::numdig(typ fmtval,::zp::i8 const bs) { + //static_assert(::zp::isinttyp<typ>::val,"type must be an integral type"); + + if (fmtval == typ (0x0)) return 0x1u; + + ::zp::siz len = 0x0u; + + for (typ val = fmtval;val > typ (0x0);val /= static_cast<typ>(bs)) {++len;} + + return len; +} + +template<typename sgntyp> constexpr auto zp::det::fmt(char * buf,sgntyp sgnval,::zp::i8 const bs,bool const rtl) noexcept -> void { + using typ = typename ::zp::usgn<sgntyp>::typ; + + ::zp::c02 const* digs = U"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; + if (bs == 0xCu) digs = U"0123456789\u218A\u218B"; + + if (sgnval < sgntyp {0x0}) { + sgnval = sgntyp {0x0}-sgnval; + *buf++ = 0x2212u; + } + + typ val = static_cast<typ>(sgnval); + + if (rtl) { + buf += ::zp::prv::numdig(val,bs)-0x1u; + + for (;val > 0x0u;val /= bs) *buf-- = digs[static_cast< ::zp::siz>(val % static_cast<typ>(bs))]; + + return; + } + + for (;val > 0x0u;val /= bs) *buf++ = digs[static_cast< ::zp::siz>(val % static_cast<typ>(bs))]; +} diff --git a/zp/include-private/zp/imp/prv.ii b/zp/include-private/zp/prv/str index a91db49..fee12e5 100644 --- a/zp/include-private/zp/imp/prv.ii +++ b/zp/include-private/zp/prv/str @@ -4,7 +4,21 @@ If a copy of the MPL was not distributed with this file, You can obtain one at <https://mozilla.org/MPL/2.0>. */ -template<typename typ> zp_nothw ::zp::siz zp::det::strcpy(typ * dst,typ const * src) { +#pragma once + +#include <zp/str> + +namespace zp { + namespace det { + template<typename typ> zp_nothw ::zp::siz strcpy(typ * dst, typ const* src); + template<typename typ> zp_nothw bool strequ(typ const* lstr,typ const* rsrc); + template<typename typ> zp_nothw ::zp::siz strfil(typ * dst, typ chr); + template<typename typ> zp_nothw ::zp::siz strlen(typ const* str); + template<typename typ> zp_nothw typ * strsrh(typ const* str, typ chr); + } +} + +template<typename typ> zp_nothw ::zp::siz zp::det::strcpy(typ * dst,typ const* src) { //static_assert(::zp::ischrtyp<typ>::val,"type must be a character type"); typ * const dstsrt = dst; @@ -14,7 +28,7 @@ template<typename typ> zp_nothw ::zp::siz zp::det::strcpy(typ * dst,typ const * return static_cast< ::zp::siz>(dst-dstsrt); /* Number of values copied. */ } -template<typename typ> zp_nothw bool zp::det::strequ(typ const * lstr,typ const * rstr) { +template<typename typ> zp_nothw bool zp::det::strequ(typ const* lstr,typ const* rstr) { //static_assert(::zp::ischrtyp<typ>::val,"type must be a character type"); for (;;++lstr,++rstr) { @@ -35,17 +49,17 @@ template<typename typ> zp_nothw ::zp::siz zp::det::strfil(typ * str,typ const ch return static_cast< ::zp::siz>(str-srt)-0x1u; } -template<typename typ> zp_nothw ::zp::siz zp::det::strlen(typ const * str) { +template<typename typ> zp_nothw ::zp::siz zp::det::strlen(typ const* str) { //static_assert(::zp::ischrtyp<typ>::val,"type must be a character type"); /* If the string format uses multiple values per character, the number of these values is returned (use utfXdeclen if the number of characters is needed). */ - typ const * const srt = str; + typ const* const srt = str; while (*str++ != typ (0x0)) {} return static_cast< ::zp::siz>(str-srt)-0x1u; } -template<typename typ> zp_nothw typ * zp::det::strsrh(typ const * str,typ const chr) { +template<typename typ> zp_nothw typ * zp::det::strsrh(typ const* str,typ const chr) { //static_assert(::zp::ischrtyp<typ>::val,"type must be a character type"); for (;;++str) { |