summaryrefslogtreecommitdiff
path: root/zap/source/any/mem
diff options
context:
space:
mode:
Diffstat (limited to 'zap/source/any/mem')
-rw-r--r--zap/source/any/mem/cp.c12
-rw-r--r--zap/source/any/mem/eq.c14
-rw-r--r--zap/source/any/mem/fill.c10
-rw-r--r--zap/source/any/mem/srch.c13
-rw-r--r--zap/source/any/mem/streq.c23
-rw-r--r--zap/source/any/mem/strlen.c13
-rw-r--r--zap/source/any/mem/utf8dec.c51
-rw-r--r--zap/source/any/mem/utf8declen.c32
-rw-r--r--zap/source/any/mem/utf8enc.c48
-rw-r--r--zap/source/any/mem/utf8enclen.c32
-rw-r--r--zap/source/any/mem/win1252dec.c111
-rw-r--r--zap/source/any/mem/win1252enc.c113
12 files changed, 20 insertions, 452 deletions
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/mem/strlen.c b/zap/source/any/mem/strlen.c
deleted file mode 100644
index 200269c..0000000
--- a/zap/source/any/mem/strlen.c
+++ /dev/null
@@ -1,13 +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_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
deleted file mode 100644
index 6f3141a..0000000
--- a/zap/source/any/mem/utf8dec.c
+++ /dev/null
@@ -1,51 +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>
-
-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_i8 const oct = *src;
- if (oct == 0x0u) {
- break;
- }
- if (oct >= 0xF0u) { /* Four octets. */
- zap_i02 chr = ((zap_i02)oct ^ 0xF0u) << 0x12u;
- ++src;
- chr += ((zap_i02)*src ^ 0x80u) << 0xCu;
- ++src;
- chr += ((zap_i02)*src ^ 0x80u) << 0x6u;
- ++src;
- chr += (zap_i02)*src ^ 0x80u;
- ++src;
- *dest = chr;
- continue;
- }
- if (oct >= 0xE0u) { /* Three octets. */
- zap_i02 chr = ((zap_i02)oct ^ 0xE0u) << 0xCu;
- ++src;
- chr += ((zap_i02)*src ^ 0x80u) << 0x6u;
- ++src;
- chr += (zap_i02)*src ^ 0x80u;
- ++src;
- *dest = chr;
- continue;
- }
- if (oct >= 0xC0u) { /* Two octets. */
- zap_i02 chr = ((zap_i02)oct ^ 0xC0u) << 0x6u;
- ++src;
- chr += (zap_i02)*src ^ 0x80u;
- ++src;
- *dest = chr;
- continue;
- }
- /* One octet. */
- *dest = oct;
- ++src;
- }
-}
diff --git a/zap/source/any/mem/utf8declen.c b/zap/source/any/mem/utf8declen.c
deleted file mode 100644
index 99c224b..0000000
--- a/zap/source/any/mem/utf8declen.c
+++ /dev/null
@@ -1,32 +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_sz zap_utf8declen(zap_i8 const * const _buf) {
- zap_sz len = 0x0u;
- zap_i8 const * pos;
- for (pos = _buf;;++len) {
- zap_i8 const oct = *pos;
- if (oct == 0x0u) {
- break;
- }
- if (oct >= 0xF0u) {
- pos += 0x4u;
- continue;
- }
- if (oct >= 0xE0u) {
- pos += 0x3u;
- continue;
- }
- if (oct >= 0xC0u) {
- pos += 0x2u;
- continue;
- }
- ++pos;
- }
- return len;
-}
diff --git a/zap/source/any/mem/utf8enc.c b/zap/source/any/mem/utf8enc.c
deleted file mode 100644
index ea62d52..0000000
--- a/zap/source/any/mem/utf8enc.c
+++ /dev/null
@@ -1,48 +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>
-
-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_i02 const chr = *src;
- if (chr > 0xFFFFu) { /* Four octets. */
- *dest = 0xF0u + (chr >> 0x12u);
- ++dest;
- *dest = 0x80u + (chr >> 0xCu & 0x3Fu);
- ++dest;
- *dest = 0x80u + (chr >> 0x6u & 0x3Fu);
- ++dest;
- *dest = 0x80u + (chr & 0x3Fu);
- ++dest;
- continue;
- }
- if (chr >= 0x7FFu) { /* Three octets. */
- *dest = 0xE0u + (zap_i8)(chr >> 0xCu);
- ++dest;
- *dest = 0x80u + (zap_i8)(chr >> 0x6u & 0x3Fu);
- ++dest;
- *dest = 0x80u + (zap_i8)(chr & 0x3Fu);
- ++dest;
- continue;
- }
- if (chr >= 0x7Fu) { /* Two octets. */
- *dest = 0xC0u + (zap_i8)(chr >> 0x6u);
- ++dest;
- *dest = 0x80u + (zap_i8)(chr & 0x3Fu);
- ++dest;
- continue;
- }
- /* One octet. */
- *dest = chr;
- ++dest;
- if (chr == 0x0u) {
- break;
- }
- }
-}
diff --git a/zap/source/any/mem/utf8enclen.c b/zap/source/any/mem/utf8enclen.c
deleted file mode 100644
index c159653..0000000
--- a/zap/source/any/mem/utf8enclen.c
+++ /dev/null
@@ -1,32 +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_sz zap_utf8enclen(zap_i02 const * const _buf) {
- zap_sz len = 0x0u;
- zap_i02 const * pos;
- for (pos = _buf;;++pos) {
- zap_i02 const chr = *pos;
- if (chr == 0x0u) {
- break;
- }
- if (chr >= 0x10000u) {
- len += 0x4u;
- continue;
- }
- if (chr >= 0x800u) {
- len += 0x3u;
- continue;
- }
- if (chr >= 0x80u) {
- len += 0x2u;
- continue;
- }
- ++len;
- }
- return len;
-}
diff --git a/zap/source/any/mem/win1252dec.c b/zap/source/any/mem/win1252dec.c
deleted file mode 100644
index 7dc7067..0000000
--- a/zap/source/any/mem/win1252dec.c
+++ /dev/null
@@ -1,111 +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>
-
-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_i8 const chr = *src;
- if (chr == 0x0u) {
- break;
- }
- switch (chr) {
- default:
- *dest = *src;
- break;
- case 0x81: /* Bad characters. */
- case 0x8D:
- case 0x8F:
- case 0x90:
- case 0x9D:
- *dest = 0xFFFDu; /* REPLACEMENT CHARACTER */
- break;
- case 0x80:
- *dest = 0x20ACu;
- break;
- case 0x82:
- *dest = 0x201Au;
- break;
- case 0x83:
- *dest = 0x192u;
- break;
- case 0x84:
- *dest = 0x201Eu;
- break;
- case 0x85:
- *dest = 0x2026u;
- break;
- case 0x86:
- *dest = 0x2020u;
- break;
- case 0x87:
- *dest = 0x2021u;
- break;
- case 0x88:
- *dest = 0x2C6u;
- break;
- case 0x89:
- *dest = 0x2030u;
- break;
- case 0x8A:
- *dest = 0x160u;
- break;
- case 0x8B:
- *dest = 0x2039u;
- break;
- case 0x8C:
- *dest = 0x152u;
- break;
- case 0x8E:
- *dest = 0x17Du;
- break;
- case 0x91:
- *dest = 0x2018u;
- break;
- case 0x92:
- *dest = 0x2019u;
- break;
- case 0x93:
- *dest = 0x201Cu;
- break;
- case 0x94:
- *dest = 0x201Du;
- break;
- case 0x95:
- *dest = 0x2022u;
- break;
- case 0x96:
- *dest = 0x2013u;
- break;
- case 0x97:
- *dest = 0x2014u;
- break;
- case 0x98:
- *dest = 0x2DCu;
- break;
- case 0x99:
- *dest = 0x2122u;
- break;
- case 0x9A:
- *dest = 0x161u;
- break;
- case 0x9B:
- *dest = 0x203Au;
- break;
- case 0x9C:
- *dest = 0x153u;
- break;
- case 0x9E:
- *dest = 0x17Eu;
- break;
- case 0x9F:
- *dest = 0x178u;
- break;
- }
- }
-}
diff --git a/zap/source/any/mem/win1252enc.c b/zap/source/any/mem/win1252enc.c
deleted file mode 100644
index 8f80288..0000000
--- a/zap/source/any/mem/win1252enc.c
+++ /dev/null
@@ -1,113 +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>
-
-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_i02 const chr = *src;
- if (chr == 0x0u) {
- break;
- }
- zap_i8 const bad = 0x3Fu;
- switch (chr) {
- default:
- if (chr > 0xFFu) {
- *dest = bad;
- break;
- }
- if (chr >= 0x80u && chr <= 0x9Fu) {
- *dest = bad;
- break;
- }
- *dest = *src;
- break;
- case 0x20ACu:
- *dest = 0x80u;
- break;
- case 0x201Au:
- *dest = 0x82u;
- break;
- case 0x192u:
- *dest = 0x83u;
- break;
- case 0x201Eu:
- *dest = 0x84u;
- break;
- case 0x2026u:
- *dest = 0x85u;
- break;
- case 0x2020u:
- *dest = 0x86u;
- break;
- case 0x2021u:
- *dest = 0x87u;
- break;
- case 0x2C6u:
- *dest = 0x88u;
- break;
- case 0x2030u:
- *dest = 0x89u;
- break;
- case 0x160u:
- *dest = 0x8Au;
- break;
- case 0x2039u:
- *dest = 0x8Bu;
- break;
- case 0x152u:
- *dest = 0x8Cu;
- break;
- case 0x17Du:
- *dest = 0x8Eu;
- break;
- case 0x2018u:
- *dest = 0x91u;
- break;
- case 0x2019u:
- *dest = 0x92u;
- break;
- case 0x201Cu:
- *dest = 0x93u;
- break;
- case 0x201Du:
- *dest = 0x94u;
- break;
- case 0x2022u:
- *dest = 0x95u;
- break;
- case 0x2013u:
- *dest = 0x96u;
- break;
- case 0x2014u:
- *dest = 0x97u;
- break;
- case 0x2DCu:
- *dest = 0x98u;
- break;
- case 0x2122u:
- *dest = 0x99u;
- break;
- case 0x161u:
- *dest = 0x9Au;
- break;
- case 0x203Au:
- *dest = 0x9Bu;
- break;
- case 0x153u:
- *dest = 0x9Cu;
- break;
- case 0x17Eu:
- *dest = 0x9Eu;
- break;
- case 0x178u:
- *dest = 0x9Fu;
- break;
- }
- }
-}