diff options
Diffstat (limited to 'include')
-rw-r--r-- | include/u8c/SIZE_C.h | 2 | ||||
-rw-r--r-- | include/u8c/chk.h | 76 | ||||
-rw-r--r-- | include/u8c/err.h | 36 | ||||
-rw-r--r-- | include/u8c/fmt.h | 37 | ||||
-rw-r--r-- | include/u8c/intern.h | 31 | ||||
-rw-r--r-- | include/u8c/is.h | 34 | ||||
-rw-r--r-- | include/u8c/main.h | 37 | ||||
-rw-r--r-- | include/u8c/str.h | 81 | ||||
-rw-r--r-- | include/u8c/u16.h | 13 | ||||
-rw-r--r-- | include/u8c/u32.h | 39 | ||||
-rw-r--r-- | include/u8c/u8.h | 27 |
11 files changed, 287 insertions, 126 deletions
diff --git a/include/u8c/SIZE_C.h b/include/u8c/SIZE_C.h index 542ddfd..be253f3 100644 --- a/include/u8c/SIZE_C.h +++ b/include/u8c/SIZE_C.h @@ -21,7 +21,7 @@ # elif SIZE_MAX == UINT_LEAST16_MAX # define SIZE_C(val) UINT16_C(val) # elif SIZE_MAX == UINT_LEAST32_MAX -# define SIZE_C(val) UINT32s_C(val) +# define SIZE_C(val) UINT32_C(val) # elif SIZE_MAX == UINT_LEAST64_MAX # define SIZE_C(val) UINT64_C(val) # else diff --git a/include/u8c/chk.h b/include/u8c/chk.h new file mode 100644 index 0000000..03e4ff2 --- /dev/null +++ b/include/u8c/chk.h @@ -0,0 +1,76 @@ +/* + 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/>. +*/ +# if !defined(u8c_hdr_chk) +# define u8c_hdr_chk +# include <stdbool.h> +# include <uchar.h> +/* Enumerations: */ +/* Type definitions: */ +/* Structures: */ +struct u8c_isalnum_tuple { + bool res; + bool stat; +}; +struct u8c_isalpha_tuple { + bool res; + bool stat; +}; +struct u8c_iscntrl_tuple { + bool res; + bool stat; +}; +struct u8c_isdigit_tuple { + bool res; + bool stat; +}; +struct u8c_islower_tuple { + bool res; + bool stat; +}; +struct u8c_ispunct_tuple { + bool res; + bool stat; +}; +struct u8c_isspace_tuple { + bool res; + bool stat; +}; +struct u8c_issurro_tuple { + bool res; + bool stat; +}; +struct u8c_isupper_tuple { + bool res; + bool stat; +}; +struct u8c_isxdigit_tuple { + bool res; + bool stat; +}; +/* Functions: */ +extern struct u8c_isalnum_tuple u8c_isalnum( char32_t const chr); /* Is alphanumeric */ +extern struct u8c_isalpha_tuple u8c_isalpha( char32_t const chr); /* Is alphabetic */ +extern struct u8c_iscntrl_tuple u8c_iscntrl( char32_t const chr); /* Is control character */ +extern struct u8c_isdigit_tuple u8c_isdigit( char32_t const chr); /* Is digit */ +extern struct u8c_islower_tuple u8c_islower( char32_t const chr); /* Is lowercase */ +extern struct u8c_ispunct_tuple u8c_ispunct( char32_t const chr); /* Is punctuation */ +extern struct u8c_isspace_tuple u8c_isspace( char32_t const chr); /* Is space */ +extern struct u8c_issurro_tuple u8c_issurro( char32_t const chr); /* Is surrogate point */ +extern struct u8c_isupper_tuple u8c_isupper( char32_t const chr); /* Is uppercase */ +extern struct u8c_isxdigit_tuple u8c_isxdigit(char32_t const chr); /* Is hexadecimal digit */ +/* Constants & Variables: */ +/* Macros: */ +# endif diff --git a/include/u8c/err.h b/include/u8c/err.h index c6b0f9f..26d4b2f 100644 --- a/include/u8c/err.h +++ b/include/u8c/err.h @@ -20,22 +20,32 @@ # include <uchar.h> /* Enumerations: */ enum u8c_errtyp { - u8c_errtyp_badalloc, /* Bad allocation */ - u8c_errtyp_badio, /* Bad input or output */ - u8c_errtyp_u32oor, /* UTF-32 out of range */ - u8c_errtyp_u8oor, /* UTF-8 out of range */ - u8c_errtyp_deferr, /* Default error */ - u8c_errtyp_untermin, /* Unterminated input */ - u8c_errtyp_maxerrtyp, /* Maximum error type */ - u8c_errtyp_all, /* All */ + u8c_errtyp_badalloc, /* Bad allocation */ + u8c_errtyp_badio, /* Bad input or output */ + u8c_errtyp_stroor, /* UTF-32 out of range */ + u8c_errtyp_u8oor, /* UTF-8 out of range */ + u8c_errtyp_deferr, /* Default error */ + u8c_errtyp_untermin, /* Unterminated input */ + u8c_errtyp_all, /* All */ }; /* Type definitions: */ -typedef void (* u8c_errhandltyp)(enum u8c_errtyp); +typedef void (* u8c_errhandltyp)(enum u8c_errtyp); /* Error handler type */ /* Structures: */ -/* Functions */ -extern bool u8c_geterr( size_t * const sz, char32_t const * * const out); -extern bool u8c_regerrhandl(enum u8c_errtyp typ,u8c_errhandltyp errhandl); -extern bool u8c_seterr( char32_t const * const msg,enum u8c_errtyp typ); +struct u8c_geterr_tuple { + char32_t const * err; + size_t errsz; + bool stat; +}; +struct u8c_regerrhandl_tuple { + bool stat; +}; +struct u8c_seterr_tuple { + bool stat; +}; +/* Functions: */ +extern struct u8c_geterr_tuple u8c_geterr( void); /* Get error */ +extern struct u8c_regerrhandl_tuple u8c_regerrhandl(enum u8c_errtyp typ,u8c_errhandltyp errhandl); /* Register error handler */ +extern struct u8c_seterr_tuple u8c_seterr( enum u8c_errtyp typ,char32_t const * const restrict msg); /* Set error */ /* Constants & Variables: */ /* Macros: */ # endif diff --git a/include/u8c/fmt.h b/include/u8c/fmt.h index 138acd6..5ddfb02 100644 --- a/include/u8c/fmt.h +++ b/include/u8c/fmt.h @@ -54,13 +54,35 @@ enum u8c_fmttyp { }; /* Type definitions: */ /* Structures: */ -/* Functions */ -extern bool u8c_fmt( size_t * const outsz,char32_t const * * const out, char32_t const * const in,...); -extern bool u8c_print( FILE * fp, char32_t const * const msg, ...); -extern bool u8c_println(FILE * fp, char32_t const * const msg, ...); -extern bool u8c_setfmt( uint_least8_t const base, uint_least8_t const endian); -extern bool u8c_vfmt( size_t * const sz, char32_t const * * const out, char32_t const * const in,va_list args); -extern bool u8c_vprint( FILE * fp, char32_t const * const msg, va_list args); +struct u8c_fmt_tuple { + char32_t const * str; + size_t strsz; + bool stat; +}; +struct u8c_print_tuple { + bool stat; +}; +struct u8c_println_tuple { + bool stat; +}; +struct u8c_setfmt_tuple { + bool stat; +}; +struct u8c_vfmt_tuple { + char32_t const * str; + size_t strsz; + bool stat; +}; +struct u8c_vprint_tuple { + bool stat; +}; +/* Functions: */ +extern struct u8c_fmt_tuple u8c_fmt( char32_t const * const restrict in, ...); /* Format */ +extern struct u8c_print_tuple u8c_print( FILE * restrict fp, char32_t const * const restrict msg, ...); /* Print */ +extern struct u8c_println_tuple u8c_println(FILE * restrict fp, char32_t const * const restrict msg, ...); /* Print line */ +extern struct u8c_setfmt_tuple u8c_setfmt( uint_least8_t const base,bool const endian); /* Set format */ +extern struct u8c_vfmt_tuple u8c_vfmt( char32_t const * const restrict in, va_list args); /* Variadic format */ +extern struct u8c_vprint_tuple u8c_vprint( FILE * restrict fp, char32_t const * const restrict msg, va_list args); /* Variadic print */ /* Constants & Variables: */ static uint_least32_t const u8c_col_azure = UINT32_C(0x3DA9E1); static uint_least32_t const u8c_col_ash = UINT32_C(0xD2D2CC); @@ -80,6 +102,7 @@ static uint_least32_t const u8c_col_white = UINT32_C(0xF8F8F1); static uint_least32_t const u8c_col_yellow = UINT32_C(0xE1E13D); /* Macros: */ # if defined(NDEBUG) +/* Debug print */ # define u8c_dbgprint(...) ((void)0x0) # else # define u8c_dbgprint(...) u8c_println(stderr,__VA_ARGS__) diff --git a/include/u8c/intern.h b/include/u8c/intern.h index 6aeaee2..4549337 100644 --- a/include/u8c/intern.h +++ b/include/u8c/intern.h @@ -15,34 +15,35 @@ */ # if !defined(u8c_sym_dattyp) # define u8c_sym_dattyp -# include <stdalign.h> +# if defined(u8c_bethrdsafe) && defined(__STDC_NO_THREADS__) +# error u8c is set to be thread-safe, but the implementation does not support multithreading. +# endif # include <stdbool.h> # include <stddef.h> # include <stdint.h> -# include <u8c/SIZE_C.h> -# include <u8c/err.h> # include <uchar.h> +# include <u8c/err.h> # if defined(u8c_bethrdsafe) # include <threads.h> # endif /* Enumerations: */ /* Type definitions: */ /* Structures: */ -struct u8c_dattyp { - char32_t const * err; - u8c_errhandltyp errhandls[(size_t)u8c_errtyp_maxerrtyp]; - uint_least8_t fmtbase; - bool fmtendian; - uint_least8_t stat; +struct u8c_dattyp { /* Data type */ + char32_t const * err; /* Error */ + u8c_errhandltyp errhandls[(size_t)u8c_errtyp_all]; /* Error handlers */ + uint_least8_t fmtbase; /* Format base */ + bool fmtendian; /* Format endian */ + uint_least8_t stat; /* Status */ # if defined(u8c_bethrdsafe) - mtx_t errlock; - mtx_t errhandlslock; - mtx_t fmtlock; - mtx_t outlock; + mtx_t errhandlslock; /* Error handlers lock */ + mtx_t errlock; /* Error lock */ + mtx_t fmtlock; /* Format lock */ + mtx_t outlock; /* Output lock */ # endif }; -/* Functions */ +/* Functions: */ /* Constants & Variables: */ -extern struct u8c_dattyp u8c_dat; +extern struct u8c_dattyp u8c_dat; /* Data */ /* Macros: */ # endif diff --git a/include/u8c/is.h b/include/u8c/is.h deleted file mode 100644 index 20097cf..0000000 --- a/include/u8c/is.h +++ /dev/null @@ -1,34 +0,0 @@ -/* - 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/>. -*/ -# if !defined(u8c_hdr_is) -# define u8c_hdr_is -# include <stdbool.h> -# include <stdint.h> -# include <uchar.h> -/* Enumerations: */ -/* Type definitions: */ -/* Structures: */ -/* Functions */ -extern bool u8c_isalnum( uint_least8_t * const res,char32_t const chr); -extern bool u8c_isalpha( uint_least8_t * const res,char32_t const chr); -extern bool u8c_iscntrl( uint_least8_t * const res,char32_t const chr); -extern bool u8c_isdigit( uint_least8_t * const res,char32_t const chr); -extern bool u8c_ispunct( uint_least8_t * const res,char32_t const chr); -extern bool u8c_isspace( uint_least8_t * const res,char32_t const chr); -extern bool u8c_isxdigit(uint_least8_t * const res,char32_t const chr); -/* Constants & Variables: */ -/* Macros: */ -# endif diff --git a/include/u8c/main.h b/include/u8c/main.h index 2a13cc0..4004550 100644 --- a/include/u8c/main.h +++ b/include/u8c/main.h @@ -13,24 +13,43 @@ If not, see <https://www.gnu.org/licenses/>. */ -/* Abort */ # if !defined(u8c_hdr_main) # define u8c_hdr_main # include <stdbool.h> +# include <stddef.h> # include <stdint.h> # include <stdnoreturn.h> # include <uchar.h> /* Enumerations: */ /* Type definitions: */ /* Structures: */ -/* Functions */ -extern noreturn bool u8c_abrtfn(char const * const fl,long const ln,char const * const fn,char const * const why); -extern bool u8c_end( void); -extern bool u8c_init( void); +struct u8c_end_tuple { + bool stat; +}; +struct u8c_init_tuple { + bool stat; +}; +struct u8c_uniblk_tuple { + char32_t const * blk; + size_t blksz; + bool stat; +}; +struct u8c_uninm_tuple { + char32_t const * nm; + size_t nmsz; + bool stat; +}; +/* Functions: */ +noreturn extern void u8c_abrtfn(char const * const restrict fl, long const ln,char const * const restrict fn,char const * const restrict why); /* Abort function */ +extern struct u8c_end_tuple u8c_end( void); /* End */ +extern struct u8c_init_tuple u8c_init( void); /* Initialise */ +extern struct u8c_uniblk_tuple u8c_uniblk(char32_t const chr); /* Unicode block */ +extern struct u8c_uninm_tuple u8c_uninm( char32_t const chr); /* Unicode name */ /* Constants & Variables: */ -extern bool const u8c_dbg; -extern bool const u8c_thrdsafe; -static uint_least64_t const u8c_ver = UINT64_C(0x19); +extern bool const u8c_dbg; /* Debug */ +extern bool const u8c_thrdsafe; /* Thread-safe */ +static char32_t const u8c_unimax = U'\U0010FFFF'; /* Unicode maximum */ +static uint_least64_t const u8c_ver = UINT64_C(0x1A); /* Version */ /* Macros: */ -# define u8c_abrt(why) u8c_abrtfn(__FILE__,(long)__LINE__,__func__,why) +# define u8c_abrt(why) u8c_abrtfn(__FILE__,(long)__LINE__,__func__,why) /* Abort */ # endif diff --git a/include/u8c/str.h b/include/u8c/str.h new file mode 100644 index 0000000..eecea26 --- /dev/null +++ b/include/u8c/str.h @@ -0,0 +1,81 @@ +/* + 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/>. +*/ +# if !defined(u8c_hdr_str) +# define u8c_hdr_str +# include <stdbool.h> +# include <stddef.h> +# include <stdint.h> +# include <uchar.h> +/* Enumerations: */ +/* Type definitions: */ +/* Structures: */ +struct u8c_stralloc_tuple { + bool stat; + char32_t * str; +}; +struct u8c_strcat_tuple { + bool stat; + char32_t const * str; + size_t strsz; +}; +struct u8c_strcmp_tuple { + bool stat; + uint_least8_t res; +}; +struct u8c_strcp_tuple { + bool stat; + char32_t const * str; + size_t strsz; +}; +struct u8c_strfndchr_tuple { + size_t pos; + bool stat; +}; +struct u8c_strfndpat_tuple { + size_t pos; + bool stat; +}; +struct u8c_strfree_tuple { + bool stat; +}; +struct u8c_strins_tuple { + bool stat; + char32_t const * str; + size_t strsz; +}; +struct u8c_strsubstr_tuple { + bool stat; + char32_t const * str; + size_t strsz; +}; +struct u8c_strsz_tuple { + bool stat; + size_t sz; +}; +/* Functions: */ +extern struct u8c_stralloc_tuple u8c_stralloc( size_t const sz); /* String allocate */ +extern struct u8c_strcat_tuple u8c_strcat( char32_t const * const restrict str, char32_t const * const rstr); /* String concatenate */ +extern struct u8c_strcmp_tuple u8c_strcmp( char32_t const * const restrict lstr,char32_t const * const restrict rstr); /* String compare */ +extern struct u8c_strcp_tuple u8c_strcp( char32_t const * const restrict in); /* String copy */ +extern struct u8c_strfndchr_tuple u8c_strfndchr(char32_t const * const restrict in, char32_t const chr); /* String find character */ +extern struct u8c_strfndpat_tuple u8c_strfndpat(char32_t const * const restrict in, char32_t const * const restrict pat); /* String find pattern */ +extern struct u8c_strfree_tuple u8c_strfree( char32_t const * const restrict str); /* String free */ +extern struct u8c_strins_tuple u8c_strins( size_t const pos, char32_t const * const restrict str0,char32_t const * const restrict str1); /* String insert */ +extern struct u8c_strsubstr_tuple u8c_strsubstr(size_t const start,size_t const len, char32_t const * const restrict in); /* String sub-string */ +extern struct u8c_strsz_tuple u8c_strsz( char32_t const * const restrict in); /* String size */ +/* Constants & Variables: */ +/* Macros: */ +# endif diff --git a/include/u8c/u16.h b/include/u8c/u16.h index 8d81784..629d39a 100644 --- a/include/u8c/u16.h +++ b/include/u8c/u16.h @@ -21,9 +21,16 @@ /* Enumerations: */ /* Type definitions: */ /* Structures: */ -/* Functions */ -extern bool u8c_u16alloc(char16_t * * const u16,size_t const sz); -extern bool u8c_u16free( char16_t const * * const u16); +struct u8c_u16alloc_tuple { + bool stat; + char16_t * u16; +}; +struct u8c_u16free_tuple { + bool stat; +}; +/* Functions: */ +extern struct u8c_u16alloc_tuple u8c_u16alloc(size_t const sz); /* UTF-16 allocate */ +extern struct u8c_u16free_tuple u8c_u16free( char16_t const * const restrict u16); /* UTF-16 free */ /* Constants & Variables: */ /* Macros: */ # endif diff --git a/include/u8c/u32.h b/include/u8c/u32.h deleted file mode 100644 index e5567e7..0000000 --- a/include/u8c/u32.h +++ /dev/null @@ -1,39 +0,0 @@ -/* - 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/>. -*/ -# if !defined(u8c_hdr_u32) -# define u8c_hdr_u32 -# include <stdbool.h> -# include <stddef.h> -# include <stdint.h> -# include <uchar.h> -/* Enumerations: */ -/* Type definitions: */ -/* Structures: */ -/* Functions */ -extern bool u8c_u32alloc( char32_t * * const u32,size_t const sz); -extern bool u8c_u32cat( size_t * const sz, char32_t const * * const out, char32_t const * const lstr,char32_t const * const rstr); -extern bool u8c_u32cmp( uint_least8_t * const res,char32_t const * const lstr, char32_t const * const rstr); -extern bool u8c_u32cp( size_t * const sz, char32_t const * * const out, char32_t const * const in); -extern bool u8c_u32fndchr(size_t * const pos,char32_t const * const in, char32_t const chr); -extern bool u8c_u32fndpat(size_t * const pos,char32_t const * const in, char32_t const * const pat); -extern bool u8c_u32free( char32_t const * * const u32); -extern bool u8c_u32ins( size_t * const sz, char32_t const * * const out, size_t const pos, char32_t const * const str0,char32_t const * const str1); -extern bool u8c_u32substr(char32_t const * * const out,size_t const start,size_t const len, char32_t const * const in); -extern bool u8c_u32sz( size_t * sz, char32_t const * in); -/* Constants & Variables: */ -static char32_t const u8c_u32max = U'\x10FFFF'; -/* Macros: */ -# endif diff --git a/include/u8c/u8.h b/include/u8c/u8.h index f47666b..c7b6cc5 100644 --- a/include/u8c/u8.h +++ b/include/u8c/u8.h @@ -21,11 +21,28 @@ /* Enumerations: */ /* Type definitions: */ /* Structures: */ -/* Functions */ -extern bool u8c_u8alloc(unsigned char * * const u32,size_t const sz); -extern bool u8c_u8dec( size_t * const sz, char32_t const * * const out,unsigned char const * const in); -extern bool u8c_u8enc( size_t * const sz, unsigned char const * * const out,char32_t const * const in); -extern bool u8c_u8free( unsigned char const * * const u8); +struct u8c_u8alloc_tuple { + bool stat; + unsigned char * u8; +}; +struct u8c_u8dec_tuple { + bool stat; + char32_t const * str; + size_t strsz; +}; +struct u8c_u8enc_tuple { + bool stat; + unsigned char const * u8; + size_t u8sz; +}; +struct u8c_u8free_tuple { + bool stat; +}; +/* Functions: */ +extern struct u8c_u8alloc_tuple u8c_u8alloc(size_t const sz); /* UTF-8 allocate */ +extern struct u8c_u8dec_tuple u8c_u8dec( unsigned char const * const restrict u8); /* UTF-8 decode */ +extern struct u8c_u8enc_tuple u8c_u8enc( char32_t const * const restrict u8); /* UTF-8 encode */ +extern struct u8c_u8free_tuple u8c_u8free( unsigned char const * const restrict u8); /* UTF-8 free */ /* Constants & Variables: */ /* Macros: */ # endif |