summaryrefslogtreecommitdiff
path: root/zp/include/zp/imp/str.ii
blob: f5e40e398f2de664e64912eaa2a3ce893e421269 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/*
	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>.
*/

#if false
template<typename sgntyp> constexpr auto zp::fmt(::zp::c02 * buf,sgntyp sgnval,::zp::i8m 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))];
}
#endif

#if false
template<typename typ> constexpr auto zp::fmtlen(typ val,::zp::i8m const bs) noexcept -> ::zp::siz {
	static_assert(::zp::isinttyp<typ>::val,"type must be an integral type");

	::zp::siz len = 0x0u;

	if (val < typ {0x0}) {
		val = typ {0x0}-val;
		len = 0x1u;
	}

	len += ::zp::prv::numdig(val,bs);
	
	return len;
}
#endif

template<typename typ> zp_nothw ::zp::siz zp::prv::numdig(typ fmtval,::zp::i8m 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;
}