diff options
Diffstat (limited to 'zap/source')
-rw-r--r-- | zap/source/any/bs/trap.c | 4 | ||||
-rw-r--r-- | zap/source/any/math/abs.c | 20 | ||||
-rw-r--r-- | zap/source/any/math/abs.cc | 18 | ||||
-rw-r--r-- | zap/source/any/math/divmod.c | 24 | ||||
-rw-r--r-- | zap/source/any/math/divmod.cc | 15 | ||||
-rw-r--r-- | zap/source/any/math/exp.c | 27 | ||||
-rw-r--r-- | zap/source/any/math/exp.cc | 23 | ||||
-rw-r--r-- | zap/source/any/mem/cp.c | 12 | ||||
-rw-r--r-- | zap/source/any/mem/eq.c | 14 | ||||
-rw-r--r-- | zap/source/any/mem/fill.c | 10 | ||||
-rw-r--r-- | zap/source/any/mem/srch.c | 13 | ||||
-rw-r--r-- | zap/source/any/mem/streq.c | 23 | ||||
-rw-r--r-- | zap/source/any/str/fmt.cc | 43 | ||||
-rw-r--r-- | zap/source/any/str/fmtlen.cc | 37 | ||||
-rw-r--r-- | zap/source/any/str/numdig.hh | 12 | ||||
-rw-r--r-- | zap/source/any/str/streq.c (renamed from zap/source/any/mem/strlen.c) | 14 | ||||
-rw-r--r-- | zap/source/any/str/strlen.c (renamed from zap/source/any/math/div0.c) | 10 | ||||
-rw-r--r-- | zap/source/any/str/utf8dec.c (renamed from zap/source/any/mem/utf8dec.c) | 12 | ||||
-rw-r--r-- | zap/source/any/str/utf8declen.c (renamed from zap/source/any/mem/utf8declen.c) | 21 | ||||
-rw-r--r-- | zap/source/any/str/utf8enc.c (renamed from zap/source/any/mem/utf8enc.c) | 12 | ||||
-rw-r--r-- | zap/source/any/str/utf8enclen.c (renamed from zap/source/any/mem/utf8enclen.c) | 13 | ||||
-rw-r--r-- | zap/source/any/str/win1252dec.c (renamed from zap/source/any/mem/win1252dec.c) | 12 | ||||
-rw-r--r-- | zap/source/any/str/win1252enc.c (renamed from zap/source/any/mem/win1252enc.c) | 12 |
23 files changed, 213 insertions, 188 deletions
diff --git a/zap/source/any/bs/trap.c b/zap/source/any/bs/trap.c index 9428d44..552572d 100644 --- a/zap/source/any/bs/trap.c +++ b/zap/source/any/bs/trap.c @@ -7,10 +7,8 @@ #include <zap/bs.h> void zap_priv_trap(void) { -#if defined(__has_builtin) -#if __has_builtin(__builtin_trap) +#if zap_priv_hasbuiltin(__builtin_trap) __builtin_trap(); #endif -#endif for (;;) {} } diff --git a/zap/source/any/math/abs.c b/zap/source/any/math/abs.c deleted file mode 100644 index d12b6a6..0000000 --- a/zap/source/any/math/abs.c +++ /dev/null @@ -1,20 +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>. -*/ - -#include <zap/math.h> - -#define zap_priv_abs(_wdth) \ -zap_i##_wdth zap_abs##_wdth(zap_i##_wdth##s const _val) { \ - if (_val > 0x0) { \ - return (zap_i##_wdth)_val; \ - } \ - return (zap_i##_wdth)(0x0 - _val); \ -} - -zap_priv_abs(8) -zap_priv_abs(01) -zap_priv_abs(02) -zap_priv_abs(04) diff --git a/zap/source/any/math/abs.cc b/zap/source/any/math/abs.cc new file mode 100644 index 0000000..3e6f53e --- /dev/null +++ b/zap/source/any/math/abs.cc @@ -0,0 +1,18 @@ +/* + 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> + +extern "C" { + zap_priv_nothrw unsigned char zap_abssc(signed char const val) {return ::zap::abs(val);} + zap_priv_nothrw unsigned short zap_abss( short const val) {return ::zap::abs(val);} + zap_priv_nothrw unsigned int zap_absi( int const val) {return ::zap::abs(val);} + zap_priv_nothrw unsigned long zap_absl( long const val) {return ::zap::abs(val);} + zap_priv_nothrw unsigned long long zap_absll(long long const val) {return ::zap::abs(val);} + zap_priv_nothrw float zap_absf( float const val) {return ::zap::abs(val);} + zap_priv_nothrw double zap_absd( double const val) {return ::zap::abs(val);} + zap_priv_nothrw long double zap_absld(long double const val) {return ::zap::abs(val);} +} diff --git a/zap/source/any/math/divmod.c b/zap/source/any/math/divmod.c deleted file mode 100644 index 4214651..0000000 --- a/zap/source/any/math/divmod.c +++ /dev/null @@ -1,24 +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>. -*/ - -#include <zap/math.h> - -#define zap_priv_divmod(_wdth) \ -zap_quotrem##_wdth zap_divmod##_wdth(zap_i##_wdth const _num,zap_i##_wdth const _den) { \ -zap_quotrem##_wdth quotrem; \ - if (__builtin_expect(_den == 0x0,0x0)) { \ - quotrem.quot = zap_priv_div0(); \ - quotrem.rem = quotrem.quot; \ - return quotrem; \ - } \ - for (quotrem = (zap_quotrem##_wdth){.quot = 0x0u,.rem = _num};quotrem.rem >= _den;++quotrem.quot,quotrem.rem -= _den) {} \ - return quotrem; \ -} - -zap_priv_divmod(8) -zap_priv_divmod(01) -zap_priv_divmod(02) -zap_priv_divmod(04) diff --git a/zap/source/any/math/divmod.cc b/zap/source/any/math/divmod.cc new file mode 100644 index 0000000..c686c15 --- /dev/null +++ b/zap/source/any/math/divmod.cc @@ -0,0 +1,15 @@ +/* + 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> + +extern "C" { + zap_priv_nothrw auto zap_divmodsc(signed char const num,signed char const den) -> ::zap_quotremsc {return ::zap::divmod(num,den).cquotrem();} + zap_priv_nothrw auto zap_divmods( short const num,short const den) -> ::zap_quotrems {return ::zap::divmod(num,den).cquotrem();} + zap_priv_nothrw auto zap_divmodi( int const num,int const den) -> ::zap_quotremi {return ::zap::divmod(num,den).cquotrem();} + zap_priv_nothrw auto zap_divmodl( long const num,long const den) -> ::zap_quotreml {return ::zap::divmod(num,den).cquotrem();} + zap_priv_nothrw auto zap_divmodll(long long const num,long long const den) -> ::zap_quotremll {return ::zap::divmod(num,den).cquotrem();} +} diff --git a/zap/source/any/math/exp.c b/zap/source/any/math/exp.c deleted file mode 100644 index bf0869d..0000000 --- a/zap/source/any/math/exp.c +++ /dev/null @@ -1,27 +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>. -*/ - -#include <zap/math.h> - -#define zap_priv_exp(_wdth) \ -zap_i##_wdth zap_exp##_wdth(zap_i##_wdth const _val,zap_i##_wdth const _n) { \ - if (__builtin_expect(_n == 0x0u,0x0)) { \ - return 0x1u; \ - } \ - if (__builtin_expect(_val == 0x0u,0x0)) { \ - return 0x0u; \ - } \ - zap_i##_wdth val = _val; \ - for (zap_i##_wdth i = 0x1u;i < _n;++i) { \ - val *= _val; \ - } \ - return val; \ -} - -zap_priv_exp(8) -zap_priv_exp(01) -zap_priv_exp(02) -zap_priv_exp(04) diff --git a/zap/source/any/math/exp.cc b/zap/source/any/math/exp.cc new file mode 100644 index 0000000..2d4831b --- /dev/null +++ b/zap/source/any/math/exp.cc @@ -0,0 +1,23 @@ +/* + 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> + +extern "C" { + zap_priv_nothrw unsigned char zap_expuc( unsigned char val,unsigned char n) {return ::zap::exp(val,n);} + zap_priv_nothrw unsigned short zap_expus( unsigned short val,unsigned short n) {return ::zap::exp(val,n);} + zap_priv_nothrw unsigned int zap_expui( unsigned int val,unsigned int n) {return ::zap::exp(val,n);} + zap_priv_nothrw unsigned long zap_expul( unsigned long val,unsigned long n) {return ::zap::exp(val,n);} + zap_priv_nothrw unsigned long long zap_expull(unsigned long long val,unsigned long long n) {return ::zap::exp(val,n);} + zap_priv_nothrw signed char zap_expsc( signed char val,signed char n) {return ::zap::exp(val,n);} + zap_priv_nothrw short zap_exps( short val,short n) {return ::zap::exp(val,n);} + zap_priv_nothrw int zap_expi( int val,int n) {return ::zap::exp(val,n);} + zap_priv_nothrw long zap_expl( long val,long n) {return ::zap::exp(val,n);} + zap_priv_nothrw long long zap_expll( long long val,long long n) {return ::zap::exp(val,n);} + zap_priv_nothrw float zap_expf( float val,float n) {return ::zap::exp(val,n);} + zap_priv_nothrw double zap_expd( double val,double n) {return ::zap::exp(val,n);} + zap_priv_nothrw long double zap_expld( long double val,long double n) {return ::zap::exp(val,n);} +} diff --git a/zap/source/any/mem/cp.c b/zap/source/any/mem/cp.c index 2c1b265..9752721 100644 --- a/zap/source/any/mem/cp.c +++ b/zap/source/any/mem/cp.c @@ -6,11 +6,9 @@ #include <zap/mem.h> -void zap_cp(void * const zap_priv_restr _dest,void const * const zap_priv_restr _src,zap_sz const _num) { - zap_i8 * dest; - zap_i8 const * src; - zap_i8 * const stop = (zap_i8 *)_dest + _num; - for (dest = _dest,src = _src;dest != stop;++dest,++src) { - *dest = *src; - } +void zap_cp(void * const zap_priv_restr voiddest,void const * const zap_priv_restr voidsrc,zap_sz const num) { + unsigned char * dest = voiddest; + unsigned char const * src = voidsrc; + unsigned char * const stop = dest + num; + while (dest != stop) *dest++ = *src++; } diff --git a/zap/source/any/mem/eq.c b/zap/source/any/mem/eq.c index 3f6cd8e..5ff5c4f 100644 --- a/zap/source/any/mem/eq.c +++ b/zap/source/any/mem/eq.c @@ -6,14 +6,10 @@ #include <zap/mem.h> -zap_i8 zap_eq(void const * const _lbuf,void const * const _rbuf,zap_sz const _num) { - zap_i8 const * lbuf; - zap_i8 const * rbuf; - zap_i8 * const stop = (zap_i8 *)_lbuf + _num; - for (lbuf = _lbuf,rbuf = _rbuf;lbuf != stop;++lbuf,++rbuf) { - if (*lbuf != *rbuf) { - return 0x0u; - } - } +zap_i8 zap_eq(void const * const voidlbuf,void const * const voidrbuf,zap_sz const num) { + unsigned char const * lbuf = voidlbuf; + unsigned char const * rbuf = voidrbuf; + unsigned char const * const stop = lbuf + num; + while (lbuf != stop) if (*lbuf++ != *rbuf++) return 0x0u; return 0x1u; } diff --git a/zap/source/any/mem/fill.c b/zap/source/any/mem/fill.c index dc59263..548dfeb 100644 --- a/zap/source/any/mem/fill.c +++ b/zap/source/any/mem/fill.c @@ -6,10 +6,8 @@ #include <zap/mem.h> -void zap_fill(void * const _dest,zap_i8 const _val,zap_sz const _num) { - zap_i8 * dest; - zap_i8 * const stop = (zap_i8 *)_dest + _num; - for (dest = _dest;dest != stop;++dest) { - *dest = _val; - } +void zap_fill(void * const voiddest,unsigned char const val,zap_sz const num) { + unsigned char * dest = voiddest; + unsigned char * const stop = dest + num; + while (dest != stop) *dest++ = val; } diff --git a/zap/source/any/mem/srch.c b/zap/source/any/mem/srch.c index 9f86634..46c8ec8 100644 --- a/zap/source/any/mem/srch.c +++ b/zap/source/any/mem/srch.c @@ -6,13 +6,12 @@ #include <zap/mem.h> -void * zap_srch(void const * const _buf,zap_i8 const _val,zap_sz const _num) { - zap_i8 const * buf; - zap_i8 * const stop = (zap_i8 *)_buf + _num; - for (buf = _buf;buf != stop;++buf) { - if (*buf == _val) { - return (void *)buf; - } +void * zap_srch(void const * const voidbuf,zap_i8 const val,zap_sz const num) { + unsigned char const * buf = voidbuf; + unsigned char const * const stop = buf + num; + while (buf != stop) { + unsigned char const * addr = buf++; + if (*addr == val) return (void *)addr; } return zap_nullptr; } diff --git a/zap/source/any/mem/streq.c b/zap/source/any/mem/streq.c deleted file mode 100644 index 69c6bf6..0000000 --- a/zap/source/any/mem/streq.c +++ /dev/null @@ -1,23 +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>. -*/ - -#include <zap/mem.h> - -zap_i8 zap_streq(char const * const _lstr,char const * const _rstr) { - char const * lpos = _lstr; - char const * rpos = _rstr; - for (;;++lpos,++rpos) { - char const lchr = *lpos; - char const rchr = *rpos; - if (lchr != rchr) { - return 0x0u; - } - if (lchr == '\x0') { - break; - } - } - return zap_maxval_i8; -} 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);} +} 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);} +} diff --git a/zap/source/any/str/numdig.hh b/zap/source/any/str/numdig.hh new file mode 100644 index 0000000..65756b9 --- /dev/null +++ b/zap/source/any/str/numdig.hh @@ -0,0 +1,12 @@ +#pragma once + +namespace zap { + namespace impl { + template<typename typ> zap_priv_inln inline static auto numdig(typ fmtval,::zap::i8 const bs) noexcept -> ::zap::i8 { + ::zap::i8 len = 0x0u; + if (fmtval == typ {0x0}) return 0x1u; + for (typ val = fmtval;val > 0x0;val /= static_cast<typ>(bs)) ++len; + return len; + } + } +} diff --git a/zap/source/any/mem/strlen.c b/zap/source/any/str/streq.c index 200269c..6b1002d 100644 --- a/zap/source/any/mem/strlen.c +++ b/zap/source/any/str/streq.c @@ -4,10 +4,14 @@ 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/mem.h> +#include <zap/str.h> -zap_sz zap_strlen(char const * const _str) { - char const * pos = _str; - for (;*pos != '\x0';++pos) {} - return (zap_sz)(pos - _str); +zap_i8 zap_streq(char const * lstr,char const * rstr) { + for (;;++lstr,++rstr) { + char const lchr = *lstr; + char const rchr = *rstr; + if (lchr != rchr) return 0x0u; + if (lchr == '\x0') break; + } + return zap_maxval8; } diff --git a/zap/source/any/math/div0.c b/zap/source/any/str/strlen.c index 07c15a4..e6e9019 100644 --- a/zap/source/any/math/div0.c +++ b/zap/source/any/str/strlen.c @@ -4,10 +4,10 @@ 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 <csys.h> - -zap_i04 zap_priv_div0(void) { - return (zap_i04)-0x1; +zap_sz zap_strlen(char const * str) { + char const * const start = str; + while (*str++); + return (zap_sz)(str - start) - 0x1u; } diff --git a/zap/source/any/mem/utf8dec.c b/zap/source/any/str/utf8dec.c index 6f3141a..add8697 100644 --- a/zap/source/any/mem/utf8dec.c +++ b/zap/source/any/str/utf8dec.c @@ -4,16 +4,12 @@ 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/mem.h> +#include <zap/str.h> -void zap_utf8dec(zap_i02 * const _dest,zap_i8 const * const _src) { - zap_i02 * dest; - zap_i8 const * src; - for (dest = _dest,src = _src;;++dest) { +void zap_utf8dec(zap_i02 * dest,zap_i8 const * src) { + for (;;++dest) { zap_i8 const oct = *src; - if (oct == 0x0u) { - break; - } + if (oct == 0x0u) break; if (oct >= 0xF0u) { /* Four octets. */ zap_i02 chr = ((zap_i02)oct ^ 0xF0u) << 0x12u; ++src; diff --git a/zap/source/any/mem/utf8declen.c b/zap/source/any/str/utf8declen.c index 99c224b..f8b7ae8 100644 --- a/zap/source/any/mem/utf8declen.c +++ b/zap/source/any/str/utf8declen.c @@ -4,29 +4,26 @@ 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/mem.h> +#include <zap/str.h> -zap_sz zap_utf8declen(zap_i8 const * const _buf) { +zap_sz zap_utf8declen(zap_i8 const * buf) { zap_sz len = 0x0u; - zap_i8 const * pos; - for (pos = _buf;;++len) { - zap_i8 const oct = *pos; - if (oct == 0x0u) { - break; - } + for (;;++len) { + zap_i8 const oct = *buf; + if (oct == 0x0u) break; if (oct >= 0xF0u) { - pos += 0x4u; + buf += 0x4u; continue; } if (oct >= 0xE0u) { - pos += 0x3u; + buf += 0x3u; continue; } if (oct >= 0xC0u) { - pos += 0x2u; + buf += 0x2u; continue; } - ++pos; + ++buf; } return len; } diff --git a/zap/source/any/mem/utf8enc.c b/zap/source/any/str/utf8enc.c index ea62d52..a6b31c6 100644 --- a/zap/source/any/mem/utf8enc.c +++ b/zap/source/any/str/utf8enc.c @@ -4,12 +4,10 @@ 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/mem.h> +#include <zap/str.h> -void zap_utf8enc(zap_i8 * const _dest,zap_i02 const * const _src) { - zap_i8 * dest; - zap_i02 const * src; - for (dest = _dest,src = _src;;++src) { +void zap_utf8enc(zap_i8 * dest,zap_i02 const * src) { + for (;;++src) { zap_i02 const chr = *src; if (chr > 0xFFFFu) { /* Four octets. */ *dest = 0xF0u + (chr >> 0x12u); @@ -41,8 +39,6 @@ void zap_utf8enc(zap_i8 * const _dest,zap_i02 const * const _src) { /* One octet. */ *dest = chr; ++dest; - if (chr == 0x0u) { - break; - } + if (chr == 0x0u) break; } } diff --git a/zap/source/any/mem/utf8enclen.c b/zap/source/any/str/utf8enclen.c index c159653..f49031e 100644 --- a/zap/source/any/mem/utf8enclen.c +++ b/zap/source/any/str/utf8enclen.c @@ -4,16 +4,13 @@ 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/mem.h> +#include <zap/str.h> -zap_sz zap_utf8enclen(zap_i02 const * const _buf) { +zap_sz zap_utf8enclen(zap_i02 const * buf) { zap_sz len = 0x0u; - zap_i02 const * pos; - for (pos = _buf;;++pos) { - zap_i02 const chr = *pos; - if (chr == 0x0u) { - break; - } + for (;;++buf) { + zap_i02 const chr = *buf; + if (chr == 0x0u) break; if (chr >= 0x10000u) { len += 0x4u; continue; diff --git a/zap/source/any/mem/win1252dec.c b/zap/source/any/str/win1252dec.c index 7dc7067..0e29a5a 100644 --- a/zap/source/any/mem/win1252dec.c +++ b/zap/source/any/str/win1252dec.c @@ -4,16 +4,12 @@ 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/mem.h> +#include <zap/str.h> -void zap_win1252dec(zap_i02 * const _dest,zap_i8 const * const _src) { - zap_i02 * dest; - zap_i8 const * src; - for (dest = _dest,src = _src;;++src,++dest) { +void zap_win1252dec(zap_i02 * dest,zap_i8 const * src) { + for (;;++src,++dest) { zap_i8 const chr = *src; - if (chr == 0x0u) { - break; - } + if (chr == 0x0u) break; switch (chr) { default: *dest = *src; diff --git a/zap/source/any/mem/win1252enc.c b/zap/source/any/str/win1252enc.c index 8f80288..d7ae548 100644 --- a/zap/source/any/mem/win1252enc.c +++ b/zap/source/any/str/win1252enc.c @@ -4,16 +4,12 @@ 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/mem.h> +#include <zap/str.h> -void zap_win1252enc(zap_i8 * const _dest,zap_i02 const * const _src) { - zap_i8 * dest; - zap_i02 const * src; - for (dest = _dest,src = _src;;++src,++dest) { +void zap_win1252enc(zap_i8 * dest,zap_i02 const * src) { + for (;;++src,++dest) { zap_i02 const chr = *src; - if (chr == 0x0u) { - break; - } + if (chr == 0x0u) break; zap_i8 const bad = 0x3Fu; switch (chr) { default: |