diff options
Diffstat (limited to 'src/u8c')
-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 |
13 files changed, 71 insertions, 26 deletions
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); |