summaryrefslogtreecommitdiff
path: root/zp/include-private/zp/prv
diff options
context:
space:
mode:
Diffstat (limited to 'zp/include-private/zp/prv')
-rw-r--r--zp/include-private/zp/prv25
-rw-r--r--zp/include-private/zp/prv/fmt47
-rw-r--r--zp/include-private/zp/prv/str73
3 files changed, 120 insertions, 25 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/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/prv/str b/zp/include-private/zp/prv/str
new file mode 100644
index 0000000..fee12e5
--- /dev/null
+++ b/zp/include-private/zp/prv/str
@@ -0,0 +1,73 @@
+/*
+ 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>
+
+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;
+
+ while (*src != typ (0x0)) {*dst++ = *src++;}
+
+ 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) {
+ //static_assert(::zp::ischrtyp<typ>::val,"type must be a character type");
+
+ for (;;++lstr,++rstr) {
+ zp_lik (*lstr != *rstr) {return false;}
+ zp_unlik (*lstr == typ (0x0)) {break;}
+ }
+
+ return true;
+}
+
+template<typename typ> zp_nothw ::zp::siz zp::det::strfil(typ * str,typ const chr) {
+ //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 srt = str;
+
+ while (*str != typ (0x0)) {*str++ = chr;}
+
+ return static_cast< ::zp::siz>(str-srt)-0x1u;
+}
+
+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;
+
+ 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) {
+ //static_assert(::zp::ischrtyp<typ>::val,"type must be a character type");
+
+ for (;;++str) {
+ typ const cunrchr = *str;
+
+ zp_unlik (cunrchr == chr) {return const_cast<typ *>(str);}
+ zp_unlik (cunrchr == typ (0x0)) {break;}
+ }
+
+ return zp_nulptr;
+}