diff options
Diffstat (limited to 'zap/source/any')
-rw-r--r-- | zap/source/any/mem/cp.c | 6 | ||||
-rw-r--r-- | zap/source/any/mem/eq.c | 12 | ||||
-rw-r--r-- | zap/source/any/mem/fill.c | 6 | ||||
-rw-r--r-- | zap/source/any/mem/srch.c | 6 | ||||
-rw-r--r-- | zap/source/any/mem/streq.c | 23 | ||||
-rw-r--r-- | zap/source/any/mem/strlen.c | 13 | ||||
-rw-r--r-- | zap/source/any/mem/utf8dec.c | 26 | ||||
-rw-r--r-- | zap/source/any/mem/utf8declen.c | 6 | ||||
-rw-r--r-- | zap/source/any/mem/utf8enc.c | 18 | ||||
-rw-r--r-- | zap/source/any/mem/utf8enclen.c | 6 | ||||
-rw-r--r-- | zap/source/any/mem/win1252dec.c | 8 | ||||
-rw-r--r-- | zap/source/any/mem/win1252enc.c | 10 |
12 files changed, 88 insertions, 52 deletions
diff --git a/zap/source/any/mem/cp.c b/zap/source/any/mem/cp.c index 9bfd895..2c1b265 100644 --- a/zap/source/any/mem/cp.c +++ b/zap/source/any/mem/cp.c @@ -7,9 +7,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_byte * dest; - zap_byte const * src; - zap_byte * const stop = (zap_byte *)_dest + _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; } diff --git a/zap/source/any/mem/eq.c b/zap/source/any/mem/eq.c index 0229fb6..3f6cd8e 100644 --- a/zap/source/any/mem/eq.c +++ b/zap/source/any/mem/eq.c @@ -6,14 +6,14 @@ #include <zap/mem.h> -zap_bool zap_eq(void const * const _lbuf,void const * const _rbuf,zap_sz const _num) { - zap_byte const * lbuf; - zap_byte const * rbuf; - zap_byte * const stop = (zap_byte *)_lbuf + _num; +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 zap_false; + return 0x0u; } } - return zap_true; + return 0x1u; } diff --git a/zap/source/any/mem/fill.c b/zap/source/any/mem/fill.c index 11f5b59..dc59263 100644 --- a/zap/source/any/mem/fill.c +++ b/zap/source/any/mem/fill.c @@ -6,9 +6,9 @@ #include <zap/mem.h> -void zap_fill(void * const _dest,zap_byte const _val,zap_sz const _num) { - zap_byte * dest; - zap_byte * const stop = (zap_byte *)_dest + _num; +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; } diff --git a/zap/source/any/mem/srch.c b/zap/source/any/mem/srch.c index 494e2d8..9f86634 100644 --- a/zap/source/any/mem/srch.c +++ b/zap/source/any/mem/srch.c @@ -6,9 +6,9 @@ #include <zap/mem.h> -void * zap_srch(void const * const _buf,zap_byte const _val,zap_sz const _num) { - zap_byte const * buf; - zap_byte * const stop = (zap_byte *)_buf + _num; +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; diff --git a/zap/source/any/mem/streq.c b/zap/source/any/mem/streq.c new file mode 100644 index 0000000..69c6bf6 --- /dev/null +++ b/zap/source/any/mem/streq.c @@ -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/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/mem/strlen.c b/zap/source/any/mem/strlen.c new file mode 100644 index 0000000..200269c --- /dev/null +++ b/zap/source/any/mem/strlen.c @@ -0,0 +1,13 @@ +/* + 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_sz zap_strlen(char const * const _str) { + char const * pos = _str; + for (;*pos != '\x0';++pos) {} + return (zap_sz)(pos - _str); +} diff --git a/zap/source/any/mem/utf8dec.c b/zap/source/any/mem/utf8dec.c index f9a0eac..6f3141a 100644 --- a/zap/source/any/mem/utf8dec.c +++ b/zap/source/any/mem/utf8dec.c @@ -6,40 +6,40 @@ #include <zap/mem.h> -void zap_utf8dec(zap_chr02 * const _dest,zap_chr8 const * const _src) { - zap_chr02 * dest; - zap_chr8 const * src; +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) { - zap_chr8 const oct = *src; + zap_i8 const oct = *src; if (oct == 0x0u) { break; } if (oct >= 0xF0u) { /* Four octets. */ - zap_chr02 chr = ((zap_chr02)oct ^ 0xF0u) << 0x12u; + zap_i02 chr = ((zap_i02)oct ^ 0xF0u) << 0x12u; ++src; - chr += ((zap_chr02)*src ^ 0x80u) << 0xCu; + chr += ((zap_i02)*src ^ 0x80u) << 0xCu; ++src; - chr += ((zap_chr02)*src ^ 0x80u) << 0x6u; + chr += ((zap_i02)*src ^ 0x80u) << 0x6u; ++src; - chr += (zap_chr02)*src ^ 0x80u; + chr += (zap_i02)*src ^ 0x80u; ++src; *dest = chr; continue; } if (oct >= 0xE0u) { /* Three octets. */ - zap_chr02 chr = ((zap_chr02)oct ^ 0xE0u) << 0xCu; + zap_i02 chr = ((zap_i02)oct ^ 0xE0u) << 0xCu; ++src; - chr += ((zap_chr02)*src ^ 0x80u) << 0x6u; + chr += ((zap_i02)*src ^ 0x80u) << 0x6u; ++src; - chr += (zap_chr02)*src ^ 0x80u; + chr += (zap_i02)*src ^ 0x80u; ++src; *dest = chr; continue; } if (oct >= 0xC0u) { /* Two octets. */ - zap_chr02 chr = ((zap_chr02)oct ^ 0xC0u) << 0x6u; + zap_i02 chr = ((zap_i02)oct ^ 0xC0u) << 0x6u; ++src; - chr += (zap_chr02)*src ^ 0x80u; + chr += (zap_i02)*src ^ 0x80u; ++src; *dest = chr; continue; diff --git a/zap/source/any/mem/utf8declen.c b/zap/source/any/mem/utf8declen.c index 81fd274..99c224b 100644 --- a/zap/source/any/mem/utf8declen.c +++ b/zap/source/any/mem/utf8declen.c @@ -6,11 +6,11 @@ #include <zap/mem.h> -zap_sz zap_utf8declen(zap_chr8 const * const _buf) { +zap_sz zap_utf8declen(zap_i8 const * const _buf) { zap_sz len = 0x0u; - zap_chr8 const * pos; + zap_i8 const * pos; for (pos = _buf;;++len) { - zap_chr8 const oct = *pos; + zap_i8 const oct = *pos; if (oct == 0x0u) { break; } diff --git a/zap/source/any/mem/utf8enc.c b/zap/source/any/mem/utf8enc.c index 04febb2..ea62d52 100644 --- a/zap/source/any/mem/utf8enc.c +++ b/zap/source/any/mem/utf8enc.c @@ -6,11 +6,11 @@ #include <zap/mem.h> -void zap_utf8enc(zap_chr8 * const _dest,zap_chr02 const * const _src) { - zap_chr8 * dest; - zap_chr02 const * src; +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) { - zap_chr02 const chr = *src; + zap_i02 const chr = *src; if (chr > 0xFFFFu) { /* Four octets. */ *dest = 0xF0u + (chr >> 0x12u); ++dest; @@ -23,18 +23,18 @@ void zap_utf8enc(zap_chr8 * const _dest,zap_chr02 const * const _src) { continue; } if (chr >= 0x7FFu) { /* Three octets. */ - *dest = 0xE0u + (zap_chr8)(chr >> 0xCu); + *dest = 0xE0u + (zap_i8)(chr >> 0xCu); ++dest; - *dest = 0x80u + (zap_chr8)(chr >> 0x6u & 0x3Fu); + *dest = 0x80u + (zap_i8)(chr >> 0x6u & 0x3Fu); ++dest; - *dest = 0x80u + (zap_chr8)(chr & 0x3Fu); + *dest = 0x80u + (zap_i8)(chr & 0x3Fu); ++dest; continue; } if (chr >= 0x7Fu) { /* Two octets. */ - *dest = 0xC0u + (zap_chr8)(chr >> 0x6u); + *dest = 0xC0u + (zap_i8)(chr >> 0x6u); ++dest; - *dest = 0x80u + (zap_chr8)(chr & 0x3Fu); + *dest = 0x80u + (zap_i8)(chr & 0x3Fu); ++dest; continue; } diff --git a/zap/source/any/mem/utf8enclen.c b/zap/source/any/mem/utf8enclen.c index 67d938d..c159653 100644 --- a/zap/source/any/mem/utf8enclen.c +++ b/zap/source/any/mem/utf8enclen.c @@ -6,11 +6,11 @@ #include <zap/mem.h> -zap_sz zap_utf8enclen(zap_chr02 const * const _buf) { +zap_sz zap_utf8enclen(zap_i02 const * const _buf) { zap_sz len = 0x0u; - zap_chr02 const * pos; + zap_i02 const * pos; for (pos = _buf;;++pos) { - zap_chr02 const chr = *pos; + zap_i02 const chr = *pos; if (chr == 0x0u) { break; } diff --git a/zap/source/any/mem/win1252dec.c b/zap/source/any/mem/win1252dec.c index b808c9b..7dc7067 100644 --- a/zap/source/any/mem/win1252dec.c +++ b/zap/source/any/mem/win1252dec.c @@ -6,11 +6,11 @@ #include <zap/mem.h> -void zap_win1252dec(zap_chr02 * const _dest,zap_chr8 const * const _src) { - zap_chr02 * dest; - zap_chr8 const * src; +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) { - zap_chr8 const chr = *src; + zap_i8 const chr = *src; if (chr == 0x0u) { break; } diff --git a/zap/source/any/mem/win1252enc.c b/zap/source/any/mem/win1252enc.c index f773540..8f80288 100644 --- a/zap/source/any/mem/win1252enc.c +++ b/zap/source/any/mem/win1252enc.c @@ -6,15 +6,15 @@ #include <zap/mem.h> -void zap_win1252enc(zap_chr8 * const _dest,zap_chr02 const * const _src) { - zap_chr8 * dest; - zap_chr02 const * src; +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) { - zap_chr02 const chr = *src; + zap_i02 const chr = *src; if (chr == 0x0u) { break; } - zap_chr8 const bad = 0x3Fu; + zap_i8 const bad = 0x3Fu; switch (chr) { default: if (chr > 0xFFu) { |