diff options
-rw-r--r-- | Makefile | 2 | ||||
-rw-r--r-- | changelog.md | 6 | ||||
-rw-r--r-- | include/u8c/fmt.h | 2 | ||||
-rw-r--r-- | include/u8c/geterr.h | 2 | ||||
-rw-r--r-- | include/u8c/u32cmp.h | 27 | ||||
-rw-r--r-- | include/u8c/u32cp.h | 2 | ||||
-rw-r--r-- | include/u8c/u32sz.h | 2 | ||||
-rw-r--r-- | include/u8c/u8dec.h | 2 | ||||
-rw-r--r-- | include/u8c/u8enc.h | 2 | ||||
-rw-r--r-- | include/u8c/ver.h | 2 | ||||
-rw-r--r-- | include/u8c/vfmt.h | 2 | ||||
-rw-r--r-- | include/u8c/vprint.h | 2 | ||||
-rw-r--r-- | src/u8c/errlock.h | 1 | ||||
-rw-r--r-- | src/u8c/fmt.c | 2 | ||||
-rw-r--r-- | src/u8c/geterr.c | 2 | ||||
-rw-r--r-- | src/u8c/seterr.c | 2 | ||||
-rw-r--r-- | src/u8c/seterr.h | 3 | ||||
-rw-r--r-- | src/u8c/stat.h | 1 | ||||
-rw-r--r-- | src/u8c/u32cmp.c | 40 | ||||
-rw-r--r-- | src/u8c/u32cp.c | 7 | ||||
-rw-r--r-- | src/u8c/u32sz.c | 4 | ||||
-rw-r--r-- | src/u8c/u8dec.c | 2 | ||||
-rw-r--r-- | src/u8c/u8enc.c | 29 | ||||
-rw-r--r-- | src/u8c/vfmt.c | 2 | ||||
-rw-r--r-- | src/u8c/vprint.c | 2 | ||||
-rw-r--r-- | test.c | 23 | ||||
-rw-r--r-- | txttolit.c | 2 |
27 files changed, 139 insertions, 36 deletions
@@ -24,6 +24,7 @@ SRCS = \ src/u8c/seterr.c \ src/u8c/stat.c \ src/u8c/thrdsafe.c \ + src/u8c/u32cmp.c \ src/u8c/u32cp.c \ src/u8c/u32sz.c \ src/u8c/u8dec.c \ @@ -43,6 +44,7 @@ HDRS = \ include/u8c/println.h \ include/u8c/SIZE_C.h \ include/u8c/thrdsafe.h \ + include/u8c/u32cmp.h \ include/u8c/u32cp.h \ include/u8c/u32sz.h \ include/u8c/u8dec.h \ diff --git a/changelog.md b/changelog.md index cea8833..fc15a35 100644 --- a/changelog.md +++ b/changelog.md @@ -1,3 +1,9 @@ +# 9 + +* Optimisations. +* Remove some optimisations, as they prevent C++ compatibility. +* Fix memory leak in test program. + # 8 * Optimisations. diff --git a/include/u8c/fmt.h b/include/u8c/fmt.h index 70aea51..7f31528 100644 --- a/include/u8c/fmt.h +++ b/include/u8c/fmt.h @@ -21,7 +21,7 @@ # if defined(__cplusplus) extern "C" { # endif -extern uint_least8_t u8c_fmt(size_t * const restrict outsz,uint_least32_t * restrict * const restrict out,uint_least32_t * const restrict in,...); +extern uint_least8_t u8c_fmt(size_t * const outsz,uint_least32_t * * const out,uint_least32_t * const in,...); # if defined(__cplusplus) } # endif diff --git a/include/u8c/geterr.h b/include/u8c/geterr.h index fe0a51d..abc1fb6 100644 --- a/include/u8c/geterr.h +++ b/include/u8c/geterr.h @@ -21,7 +21,7 @@ # if defined(__cplusplus) extern "C" { # endif -extern uint_least8_t u8c_geterr(size_t * const restrict sz,uint_least32_t * restrict * const restrict out); +extern uint_least8_t u8c_geterr(size_t * const sz,uint_least32_t * * const out); # if defined(__cplusplus) } # endif diff --git a/include/u8c/u32cmp.h b/include/u8c/u32cmp.h new file mode 100644 index 0000000..aa437f0 --- /dev/null +++ b/include/u8c/u32cmp.h @@ -0,0 +1,27 @@ +/* + Copyright 2021 Gabriel Jensen + + This file is part of u8c. + + u8c is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. + + u8c is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + + See the GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License along with u8c. + + If not, see <https://www.gnu.org/licenses/>. +*/ +/* UTF-32 compare */ +# if !defined(luma_sym_u32cmp) +# define luma_sym_u32cmp +# include <stdint.h> +# if defined(__cplusplus) +extern "C" { +# endif +extern uint_least8_t u8c_u32cmp(uint_least8_t * const res,uint_least32_t * const lstr,uint_least32_t * const rstr); +# if defined(__cplusplus) +} +# endif +# endif diff --git a/include/u8c/u32cp.h b/include/u8c/u32cp.h index 8ec1864..4b2a66e 100644 --- a/include/u8c/u32cp.h +++ b/include/u8c/u32cp.h @@ -21,7 +21,7 @@ # if defined(__cplusplus) extern "C" { # endif -extern uint_least8_t u8c_u32cp(size_t * const restrict sz,uint_least32_t * restrict * const restrict out,uint_least32_t * const restrict in); +extern uint_least8_t u8c_u32cp(size_t * const sz,uint_least32_t * * const out,uint_least32_t * const in); # if defined(__cplusplus) } # endif diff --git a/include/u8c/u32sz.h b/include/u8c/u32sz.h index 5b39393..1a763f7 100644 --- a/include/u8c/u32sz.h +++ b/include/u8c/u32sz.h @@ -21,7 +21,7 @@ # if defined(__cplusplus) extern "C" { # endif -extern uint_least8_t u8c_u32sz(size_t * restrict sz,uint_least32_t * restrict in); +extern uint_least8_t u8c_u32sz(size_t * sz,uint_least32_t * in); # if defined(__cplusplus) } # endif diff --git a/include/u8c/u8dec.h b/include/u8c/u8dec.h index 851cc4c..45c7f72 100644 --- a/include/u8c/u8dec.h +++ b/include/u8c/u8dec.h @@ -21,7 +21,7 @@ # if defined(__cplusplus) extern "C" { # endif -extern uint_least8_t u8c_u8dec(size_t * const restrict sz,uint_least32_t * restrict * const restrict out,uint_least8_t * const restrict in); +extern uint_least8_t u8c_u8dec(size_t * const sz,uint_least32_t * * const out,uint_least8_t * const in); # if defined(__cplusplus) } # endif diff --git a/include/u8c/u8enc.h b/include/u8c/u8enc.h index 72710a1..5223898 100644 --- a/include/u8c/u8enc.h +++ b/include/u8c/u8enc.h @@ -21,7 +21,7 @@ # if defined(__cplusplus) extern "C" { # endif -extern uint_least8_t u8c_u8enc(size_t * const restrict sz,uint_least8_t * restrict * const restrict out,uint_least32_t * const restrict in); +extern uint_least8_t u8c_u8enc(size_t * const sz,uint_least8_t * * const out,uint_least32_t * const in); # if defined(__cplusplus) } # endif diff --git a/include/u8c/ver.h b/include/u8c/ver.h index eb02d7c..d2e8314 100644 --- a/include/u8c/ver.h +++ b/include/u8c/ver.h @@ -16,5 +16,5 @@ /* Version */ # if !defined(u8c_ver) # include <stdint.h> -# define u8c_ver (UINT64_C(0x8)) +# define u8c_ver (UINT64_C(0x9)) # endif diff --git a/include/u8c/vfmt.h b/include/u8c/vfmt.h index 60e744e..dc29311 100644 --- a/include/u8c/vfmt.h +++ b/include/u8c/vfmt.h @@ -22,7 +22,7 @@ # if defined(__cplusplus) extern "C" { # endif -extern uint_least8_t u8c_vfmt(size_t * const restrict sz,uint_least32_t * restrict * const restrict out,uint_least32_t * const restrict in,va_list args); +extern uint_least8_t u8c_vfmt(size_t * const sz,uint_least32_t * * const out,uint_least32_t * const in,va_list args); # if defined(__cplusplus) } # endif diff --git a/include/u8c/vprint.h b/include/u8c/vprint.h index a10a50a..c2b292e 100644 --- a/include/u8c/vprint.h +++ b/include/u8c/vprint.h @@ -22,7 +22,7 @@ # if defined(__cplusplus) extern "C" { # endif -extern uint_least8_t u8c_vprint(FILE * fp,uint_least32_t * const restrict msg,va_list args); +extern uint_least8_t u8c_vprint(FILE * fp,uint_least32_t * const msg,va_list args); # if defined(__cplusplus) } # endif diff --git a/src/u8c/errlock.h b/src/u8c/errlock.h index d1d380c..a77ade5 100644 --- a/src/u8c/errlock.h +++ b/src/u8c/errlock.h @@ -13,6 +13,7 @@ If not, see <https://www.gnu.org/licenses/>. */ +/* Error lock */ # if !defined(u8c_sym_errlock) # define u8c_sym_errlock # if defined(u8c_bethrdsafe) diff --git a/src/u8c/fmt.c b/src/u8c/fmt.c index 1f1f63a..fe59af6 100644 --- a/src/u8c/fmt.c +++ b/src/u8c/fmt.c @@ -18,7 +18,7 @@ # include <stdint.h> # include <u8c/fmt.h> # include <u8c/vfmt.h> -uint_least8_t u8c_fmt(size_t * const restrict _outsz,uint_least32_t * restrict * const restrict _out,uint_least32_t * const restrict _in,...) { +uint_least8_t u8c_fmt(size_t * const _outsz,uint_least32_t * * const _out,uint_least32_t * const _in,...) { va_list args; va_start(args,_in); uint_least8_t val = u8c_vfmt(_outsz,_out,_in,args); diff --git a/src/u8c/geterr.c b/src/u8c/geterr.c index b2005b2..88ec264 100644 --- a/src/u8c/geterr.c +++ b/src/u8c/geterr.c @@ -19,7 +19,7 @@ # include <stdint.h> # include <u8c/geterr.h> # include <u8c/u32cp.h> -uint_least8_t u8c_geterr(size_t * const restrict _sz,uint_least32_t * restrict * const restrict _out) { +uint_least8_t u8c_geterr(size_t * const _sz,uint_least32_t * * const _out) { # if defined(u8c_bethrdsafe) mtx_lock(&u8c_errlock); # endif diff --git a/src/u8c/seterr.c b/src/u8c/seterr.c index 3efbb14..56967af 100644 --- a/src/u8c/seterr.c +++ b/src/u8c/seterr.c @@ -24,7 +24,7 @@ # if defined(u8c_bethrdsafe) # include <threads.h> # endif -uint_least8_t u8c_seterr(uint_least32_t * const restrict _msg) { +uint_least8_t u8c_seterr(uint_least32_t * const _msg) { assert(_msg != NULL); u8c_dbgprint(_msg); # if defined(u8c_bethrdsafe) diff --git a/src/u8c/seterr.h b/src/u8c/seterr.h index 0aee4e6..df3270f 100644 --- a/src/u8c/seterr.h +++ b/src/u8c/seterr.h @@ -13,8 +13,9 @@ If not, see <https://www.gnu.org/licenses/>. */ +/* Set error */ # if !defined(u8c_sym_seterr) # define u8c_sym_seterr # include <stdint.h> -extern uint_least8_t u8c_seterr(uint_least32_t * const restrict msg); +extern uint_least8_t u8c_seterr(uint_least32_t * const msg); # endif diff --git a/src/u8c/stat.h b/src/u8c/stat.h index 644f345..8ca005e 100644 --- a/src/u8c/stat.h +++ b/src/u8c/stat.h @@ -13,6 +13,7 @@ If not, see <https://www.gnu.org/licenses/>. */ +/* Status */ # if !defined(u8c_sym_stat) # define u8c_sym_stat # include <stdint.h> diff --git a/src/u8c/u32cmp.c b/src/u8c/u32cmp.c new file mode 100644 index 0000000..1c69d16 --- /dev/null +++ b/src/u8c/u32cmp.c @@ -0,0 +1,40 @@ +/* + Copyright 2021 Gabriel Jensen + + This file is part of u8c. + + u8c is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. + + u8c is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + + See the GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License along with u8c. + + If not, see <https://www.gnu.org/licenses/>. +*/ +# include "seterr.h" +# include <stddef.h> +# include <stdint.h> +# include <u8c/SIZE_C.h> +# include <u8c/u32cmp.h> +uint_least8_t u8c_u32cmp(uint_least8_t * const _res,uint_least32_t * const _lstr,uint_least32_t * const _rstr) { + for(register size_t n = SIZE_C(0x0);n <= SIZE_MAX;n += SIZE_C(0x1)) { + register uint_least32_t const lchr = _lstr[n]; + register uint_least32_t const rchr = _rstr[n]; + if(lchr != rchr) { + if(lchr < rchr) { + *_res = UINT8_C(0x0); + return UINT8_C(0x0); + } + *_res = UINT8_C(0x2); + return UINT8_C(0x0); + } + if(lchr == UINT32_C(0x0)) { + *_res = UINT8_C(0x1); + return UINT8_C(0x0); + } + } + u8c_seterr((uint_least32_t[]){UINT32_C(0x75),UINT32_C(0x38),UINT32_C(0x63),UINT32_C(0x5F),UINT32_C(0x75),UINT32_C(0x33),UINT32_C(0x32),UINT32_C(0x63),UINT32_C(0x6D),UINT32_C(0x70),UINT32_C(0x3A),UINT32_C(0x20),UINT32_C(0x55),UINT32_C(0x6E),UINT32_C(0x74),UINT32_C(0x65),UINT32_C(0x72),UINT32_C(0x6D),UINT32_C(0x69),UINT32_C(0x6E),UINT32_C(0x61),UINT32_C(0x74),UINT32_C(0x65),UINT32_C(0x64),UINT32_C(0x20),UINT32_C(0x69),UINT32_C(0x6E),UINT32_C(0x70),UINT32_C(0x75),UINT32_C(0x74),UINT32_C(0x2E),UINT32_C(0x0),}); + return UINT8_C(0x1); +} diff --git a/src/u8c/u32cp.c b/src/u8c/u32cp.c index 6b00021..978b445 100644 --- a/src/u8c/u32cp.c +++ b/src/u8c/u32cp.c @@ -20,7 +20,7 @@ # include <u8c/SIZE_C.h> # include <u8c/u32cp.h> # include <u8c/u32sz.h> -uint_least8_t u8c_u32cp(size_t * const restrict _sz,uint_least32_t * restrict * const restrict _out,uint_least32_t * const restrict _in) { +uint_least8_t u8c_u32cp(size_t * const _sz,uint_least32_t * * const _out,uint_least32_t * const _in) { assert(_in != NULL); size_t insz = SIZE_C(0x0); u8c_u32sz(&insz,_in); @@ -31,9 +31,10 @@ uint_least8_t u8c_u32cp(size_t * const restrict _sz,uint_least32_t * restrict * if((*_out = calloc(sizeof(uint_least32_t),insz)) == NULL) { u8c_seterr((uint_least32_t[]){UINT32_C(0x75),UINT32_C(0x38),UINT32_C(0x63),UINT32_C(0x5F),UINT32_C(0x75),UINT32_C(0x33),UINT32_C(0x32),UINT32_C(0x63),UINT32_C(0x70),UINT32_C(0x3A),UINT32_C(0x20),UINT32_C(0x55),UINT32_C(0x6E),UINT32_C(0x61),UINT32_C(0x62),UINT32_C(0x6C),UINT32_C(0x65),UINT32_C(0x20),UINT32_C(0x74),UINT32_C(0x6F),UINT32_C(0x20),UINT32_C(0x61),UINT32_C(0x6C),UINT32_C(0x6C),UINT32_C(0x6F),UINT32_C(0x63),UINT32_C(0x61),UINT32_C(0x74),UINT32_C(0x65),UINT32_C(0x20),UINT32_C(0x72),UINT32_C(0x65),UINT32_C(0x73),UINT32_C(0x6F),UINT32_C(0x75),UINT32_C(0x72),UINT32_C(0x63),UINT32_C(0x65),UINT32_C(0x73),UINT32_C(0x2E),UINT32_C(0x0),}); /* u8c_u32cp: Unable to allocate resources. */ return UINT8_C(0x1); - } + }uint_least32_t * const out = *_out; for(register size_t n = SIZE_C(0x0);n < insz;n += SIZE_C(0x1)) { - (*_out)[n] = _in[n]; + out[n] = _in[n]; } + *_out = out; return UINT8_C(0x0); } diff --git a/src/u8c/u32sz.c b/src/u8c/u32sz.c index 3404a42..aec4dd2 100644 --- a/src/u8c/u32sz.c +++ b/src/u8c/u32sz.c @@ -19,10 +19,10 @@ # include <stdint.h> # include <u8c/SIZE_C.h> # include <u8c/u32sz.h> -uint_least8_t u8c_u32sz(size_t * const restrict _sz,uint_least32_t * const restrict _u32) { +uint_least8_t u8c_u32sz(size_t * const _sz,uint_least32_t * const _u32) { assert(_sz != NULL); assert(_u32 != NULL); - for(size_t n = SIZE_C(0x0);n <= SIZE_MAX;n += SIZE_C(0x1)) { + for(register size_t n = SIZE_C(0x0);n <= SIZE_MAX;n += SIZE_C(0x1)) { if(_u32[n] == UINT32_C(0x0)) { *_sz = n + SIZE_C(0x1); return UINT8_C(0x0); diff --git a/src/u8c/u8dec.c b/src/u8c/u8dec.c index 763adad..516e025 100644 --- a/src/u8c/u8dec.c +++ b/src/u8c/u8dec.c @@ -19,7 +19,7 @@ # include <stdlib.h> # include <u8c/u8dec.h> # include <u8c/SIZE_C.h> -uint_least8_t u8c_u8dec(size_t * const restrict _sz,uint_least32_t * restrict * const restrict _out,uint_least8_t * const restrict _in) { +uint_least8_t u8c_u8dec(size_t * const _sz,uint_least32_t * * const _out,uint_least8_t * const _in) { assert(_in != NULL); register size_t insz = SIZE_C(0x0); register size_t outsz = SIZE_C(0x1); diff --git a/src/u8c/u8enc.c b/src/u8c/u8enc.c index e49a6c3..8e5432d 100644 --- a/src/u8c/u8enc.c +++ b/src/u8c/u8enc.c @@ -19,11 +19,11 @@ # include <stdlib.h> # include <u8c/u8enc.h> # include <u8c/SIZE_C.h> -uint_least8_t u8c_u8enc(size_t * const restrict _sz,uint_least8_t * restrict * const restrict _out,uint_least32_t * const restrict _in) { +uint_least8_t u8c_u8enc(size_t * const _sz,uint_least8_t * * const _out,uint_least32_t * const _in) { assert(_in != NULL); size_t insz = SIZE_C(0x0); /* Size of input array (bytes). */ size_t outsz = SIZE_C(0x0); /* Size of output array /bytes). */ - for(size_t n = SIZE_C(0x0);n <= SIZE_MAX;n += SIZE_C(0x1)) { /* First pass: get size of input array, and determine size of output array. */ + for(register size_t n = SIZE_C(0x0);n <= SIZE_MAX;n += SIZE_C(0x1)) { /* First pass: get size of input array, and determine size of output array. */ register uint_least32_t const tmp = _in[n]; if(tmp >= UINT32_C(0x110000)) { /* Codepoint out of range. */ u8c_seterr((uint_least32_t[]){UINT32_C(0x75),UINT32_C(0x38),UINT32_C(0x63),UINT32_C(0x5F),UINT32_C(0x75),UINT32_C(0x38),UINT32_C(0x65),UINT32_C(0x6E),UINT32_C(0x63),UINT32_C(0x3A),UINT32_C(0x20),UINT32_C(0x43),UINT32_C(0x6F),UINT32_C(0x64),UINT32_C(0x65),UINT32_C(0x70),UINT32_C(0x6F),UINT32_C(0x69),UINT32_C(0x6E),UINT32_C(0x74),UINT32_C(0x20),UINT32_C(0x6F),UINT32_C(0x75),UINT32_C(0x74),UINT32_C(0x20),UINT32_C(0x6F),UINT32_C(0x66),UINT32_C(0x20),UINT32_C(0x72),UINT32_C(0x61),UINT32_C(0x6E),UINT32_C(0x67),UINT32_C(0x65),UINT32_C(0x20),UINT32_C(0x28),UINT32_C(0x74),UINT32_C(0x6F),UINT32_C(0x6F),UINT32_C(0x20),UINT32_C(0x62),UINT32_C(0x69),UINT32_C(0x67),UINT32_C(0x29),UINT32_C(0x2E),UINT32_C(0x0),}); /* u8c_u8enc: Codepoint out of range (too big). */ @@ -54,35 +54,36 @@ nottoobig:; if(_sz != NULL) { *_sz = outsz; } - *_out = calloc(sizeof(uint_least8_t),outsz); /* Allocate space for output array. */ - for(size_t n = SIZE_C(0x0), outn = SIZE_C(0x0);n < insz;n += SIZE_C(0x1),outn += SIZE_C(0x1)) { /* Second pass: encode each codepoint into UTF-8. */ + uint_least8_t * out = calloc(sizeof(uint_least8_t),outsz); /* Allocate space for output array. */ + for(register size_t n = SIZE_C(0x0), outn = SIZE_C(0x0);n < insz;n += SIZE_C(0x1),outn += SIZE_C(0x1)) { /* Second pass: encode each codepoint into UTF-8. */ register uint_least32_t const tmp = _in[n]; if(tmp >= UINT32_C(0x10000)) { // Four bytes. - (*_out)[outn] = UINT8_C(0xF0) + (uint_least8_t)(tmp >> UINT32_C(0x12)); + out[outn] = UINT8_C(0xF0) + (uint_least8_t)(tmp >> UINT32_C(0x12)); outn += SIZE_C(0x1); - (*_out)[outn] = UINT8_C(0x80) + (uint_least8_t)(tmp >> UINT32_C(0xC) & UINT8_C(0x3F)); + out[outn] = UINT8_C(0x80) + (uint_least8_t)(tmp >> UINT32_C(0xC) & UINT8_C(0x3F)); outn += SIZE_C(0x1); - (*_out)[outn] = UINT8_C(0x80) + (uint_least8_t)(tmp >> UINT32_C(0x6) & UINT8_C(0x3F)); + out[outn] = UINT8_C(0x80) + (uint_least8_t)(tmp >> UINT32_C(0x6) & UINT8_C(0x3F)); outn += SIZE_C(0x1); - (*_out)[outn] = UINT8_C(0x80) + (uint_least8_t)(tmp & UINT32_C(0x3F)); + out[outn] = UINT8_C(0x80) + (uint_least8_t)(tmp & UINT32_C(0x3F)); continue; } if(tmp >= UINT32_C(0x800)) { /* Three bytes. */ - (*_out)[outn] = UINT8_C(0xE0) + (uint_least8_t)(tmp >> UINT32_C(0xC)); + out[outn] = UINT8_C(0xE0) + (uint_least8_t)(tmp >> UINT32_C(0xC)); outn += SIZE_C(0x1); - (*_out)[outn] = UINT8_C(0x80) + (uint_least8_t)(tmp >> UINT32_C(0x6) & UINT8_C(0x3F)); + out[outn] = UINT8_C(0x80) + (uint_least8_t)(tmp >> UINT32_C(0x6) & UINT8_C(0x3F)); outn += SIZE_C(0x1); - (*_out)[outn] = UINT8_C(0x80) + (uint_least8_t)(tmp & UINT32_C(0x3F)); + out[outn] = UINT8_C(0x80) + (uint_least8_t)(tmp & UINT32_C(0x3F)); continue; } if(tmp >= UINT32_C(0x80)) { /* Two bytes. */ - (*_out)[outn] = UINT8_C(0xC0) + (uint_least8_t)(tmp >> UINT8_C(0x6)); + out[outn] = UINT8_C(0xC0) + (uint_least8_t)(tmp >> UINT8_C(0x6)); outn += SIZE_C(0x1); - (*_out)[outn] = UINT8_C(0x80) + (uint_least8_t)(tmp & UINT8_C(0x3F)); + out[outn] = UINT8_C(0x80) + (uint_least8_t)(tmp & UINT8_C(0x3F)); continue; } /* One byte. */ - (*_out)[outn] = (uint_least8_t)tmp; + out[outn] = (uint_least8_t)tmp; } + *_out = out; return UINT8_C(0x0); } diff --git a/src/u8c/vfmt.c b/src/u8c/vfmt.c index c1a7fc8..5afc6cf 100644 --- a/src/u8c/vfmt.c +++ b/src/u8c/vfmt.c @@ -17,7 +17,7 @@ # include <stdint.h> # include <u8c/u32cp.h> # include <u8c/vfmt.h> -uint_least8_t u8c_vfmt(size_t * const restrict _sz,uint_least32_t * restrict * const restrict _out,uint_least32_t * const restrict _in,va_list _args) { +uint_least8_t u8c_vfmt(size_t * const _sz,uint_least32_t * * const _out,uint_least32_t * const _in,va_list _args) { /* To be added. */ return u8c_u32cp(_sz,_out,_in); } diff --git a/src/u8c/vprint.c b/src/u8c/vprint.c index 3b78f4c..7d1a4df 100644 --- a/src/u8c/vprint.c +++ b/src/u8c/vprint.c @@ -23,7 +23,7 @@ # include <u8c/SIZE_C.h> # include <u8c/vfmt.h> # include <u8c/vprint.h> -uint_least8_t u8c_vprint(FILE * _fp,uint_least32_t * const restrict _msg,va_list _args) { +uint_least8_t u8c_vprint(FILE * _fp,uint_least32_t * const _msg,va_list _args) { assert(_msg != NULL); uint_least32_t * str0 = NULL; u8c_vfmt(NULL,&str0,_msg,_args); @@ -15,6 +15,7 @@ # include <u8c/println.h> # include <u8c/SIZE_C.h> # include <u8c/thrdsafe.h> +# include <u8c/u32cmp.h> # include <u8c/u32cp.h> # include <u8c/u32sz.h> # include <u8c/u8dec.h> @@ -58,6 +59,7 @@ int main(void) { errcount1 += u8c_u8enc(NULL,&msg1,msg0); printf("Encoded: %s\n",msg1); errcount1 += u8c_u8dec(NULL,&msg0,msg1); + free(msg1); errcount1 += u8c_u8enc(NULL,&msg1,msg0); printf("Encoded -> Decoded -> Encoded: %s\n",msg1); free(msg0); @@ -101,6 +103,27 @@ int main(void) { break; } testmsgdone(&errcount0,&errcount1); + testmsg("String comparison (UTF-32)"); + while(!errcount1) { + uint_least32_t * str0 = (uint_least32_t[]){UINT32_C(0x48),UINT32_C(0x65),UINT32_C(0x6C),UINT32_C(0x6C),UINT32_C(0x6F),UINT32_C(0x0),}; + uint_least32_t * str1 = (uint_least32_t[]){UINT32_C(0x48),UINT32_C(0x65),UINT32_C(0x6C),UINT32_C(0x6C),UINT32_C(0x6F),UINT32_C(0x0),}; + uint_least32_t * str2 = (uint_least32_t[]){UINT32_C(0x47),UINT32_C(0x6F),UINT32_C(0x6F),UINT32_C(0x64),UINT32_C(0x62),UINT32_C(0x79),UINT32_C(0x65),UINT32_C(0x0),}; + printf("str0: "); + u8c_println(stdout,str0); + printf("str1: "); + u8c_println(stdout,str1); + printf("str2: "); + u8c_println(stdout,str2); + uint_least8_t res = UINT8_C(0x0); + errcount1 += u8c_u32cmp(&res,str0,str1); + printf("str0,str1: %" PRIXLEAST8 ".\n",res); + errcount1 += u8c_u32cmp(&res,str1,str2); + printf("str0,str2: %" PRIXLEAST8 ".\n",res); + errcount1 += u8c_u32cmp(&res,str2,str1); + printf("str2,str1: %" PRIXLEAST8 ".\n",res); + break; + } + testmsgdone(&errcount0,&errcount1); printf("\n"); printf("Test done!\n"); printf("Total number of errors: %" PRIuLEAST32 ".\n",errcount0); @@ -15,7 +15,7 @@ int main(void) { u8c_init(); size_t u32sz = SIZE_C(0x0); - uint_least32_t * u32 = U"u8c_u32sz: Unterminated input."; /* Place string here. */ + uint_least32_t * u32 = U"Goodbye"; /* Place string here. */ u8c_u32sz(&u32sz,u32); printf("Arrray:\n{"); for(size_t n = SIZE_C(0x0);n < u32sz;n += SIZE_C(0x1)) { |