diff options
Diffstat (limited to 'src/u8c/str.h.d')
-rw-r--r-- | src/u8c/str.h.d/stralloc.c | 33 | ||||
-rw-r--r-- | src/u8c/str.h.d/strcat.c | 46 | ||||
-rw-r--r-- | src/u8c/str.h.d/strcmp.c | 45 | ||||
-rw-r--r-- | src/u8c/str.h.d/strcp.c | 40 | ||||
-rw-r--r-- | src/u8c/str.h.d/strfndchr.c | 45 | ||||
-rw-r--r-- | src/u8c/str.h.d/strfndpat.c | 43 | ||||
-rw-r--r-- | src/u8c/str.h.d/strfree.c | 26 | ||||
-rw-r--r-- | src/u8c/str.h.d/strins.c | 38 | ||||
-rw-r--r-- | src/u8c/str.h.d/strsubstr.c | 48 | ||||
-rw-r--r-- | src/u8c/str.h.d/strsz.c | 35 |
10 files changed, 0 insertions, 399 deletions
diff --git a/src/u8c/str.h.d/stralloc.c b/src/u8c/str.h.d/stralloc.c deleted file mode 100644 index f9addcd..0000000 --- a/src/u8c/str.h.d/stralloc.c +++ /dev/null @@ -1,33 +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/>. -*/ -# include <stdbool.h> -# include <stdlib.h> -# include <u8c/err.h> -# include <u8c/str.h> -# include <uchar.h> -struct u8c_stralloc_tuple u8c_stralloc(size_t const _sz) { - struct u8c_stralloc_tuple ret = { - .stat = false, - }; - char32_t * arr = NULL; - if((arr = calloc(sizeof *arr,_sz)) == NULL) { - u8c_seterr(u8c_errtyp_badalloc,U"u8c_stralloc: Unable to allocate resources (not enough memory?)."); - ret.stat = true; - return ret; - } - ret.str = arr; - return ret; -} diff --git a/src/u8c/str.h.d/strcat.c b/src/u8c/str.h.d/strcat.c deleted file mode 100644 index 5e5f693..0000000 --- a/src/u8c/str.h.d/strcat.c +++ /dev/null @@ -1,46 +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/>. -*/ -# include <stdbool.h> -# include <stdlib.h> -# include <u8c/SIZE_C.h> -# include <u8c/err.h> -# include <u8c/str.h> -# include <uchar.h> -struct u8c_strcat_tuple u8c_strcat(char32_t const * const restrict _lstr,char32_t const * const restrict _rstr) { - struct u8c_strcat_tuple ret = { - .stat = false, - }; - size_t lsz = u8c_strsz(_lstr).sz; - size_t rsz = u8c_strsz(_rstr).sz; - ret.strsz = lsz + rsz; - char32_t * out = NULL; - { - struct u8c_stralloc_tuple const tuple = u8c_stralloc(ret.strsz + SIZE_C(0x1)); - if(tuple.stat) { - ret.stat = true; - return ret; - } - out = tuple.str; - } - for(register size_t n = SIZE_C(0x0);n < lsz;n += SIZE_C(0x1)) { - out[n] = _lstr[n]; - } - for(register size_t n = SIZE_C(0x0);n < rsz;n += SIZE_C(0x1)) { - out[n + lsz] = _rstr[n]; - } - ret.str = out; - return ret; -} diff --git a/src/u8c/str.h.d/strcmp.c b/src/u8c/str.h.d/strcmp.c deleted file mode 100644 index 31654d0..0000000 --- a/src/u8c/str.h.d/strcmp.c +++ /dev/null @@ -1,45 +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/>. -*/ -# include <stdbool.h> -# include <stddef.h> -# include <stdint.h> -# include <u8c/SIZE_C.h> -# include <u8c/err.h> -# include <u8c/str.h> -struct u8c_strcmp_tuple u8c_strcmp(char32_t const * const restrict _lstr,char32_t const * const restrict _rstr) { - struct u8c_strcmp_tuple ret = { - .stat = false, - }; - for(register size_t n = SIZE_C(0x0);n <= SIZE_MAX;n += SIZE_C(0x1)) { - register char32_t const lchr = _lstr[n]; - register char32_t const rchr = _rstr[n]; - if(lchr != rchr) { - if(lchr < rchr) { - ret.res = UINT8_C(0x0); - return ret; - } - ret.res = UINT8_C(0x2); - return ret; - } - if(lchr == U'\x0') { - ret.res = UINT8_C(0x1); - return ret; - } - } - u8c_seterr(u8c_errtyp_untermin,U"u8c_strcmp: Unterminated input."); - ret.stat = true; - return ret; -} diff --git a/src/u8c/str.h.d/strcp.c b/src/u8c/str.h.d/strcp.c deleted file mode 100644 index 1343bf1..0000000 --- a/src/u8c/str.h.d/strcp.c +++ /dev/null @@ -1,40 +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/>. -*/ -# include <stdbool.h> -# include <stdlib.h> -# include <u8c/SIZE_C.h> -# include <u8c/err.h> -# include <u8c/str.h> -struct u8c_strcp_tuple u8c_strcp(char32_t const * const restrict _in) { - struct u8c_strcp_tuple ret = { - .stat = false, - }; - ret.strsz = u8c_strsz(_in).sz; - uint_least32_t * out = NULL; - { - struct u8c_stralloc_tuple const tuple = u8c_stralloc(ret.strsz + SIZE_C(0x1)); - if(tuple.stat) { - ret.stat = true; - return ret; - } - out = tuple.str; - } - for(register size_t n = SIZE_C(0x0);n < ret.strsz;n += SIZE_C(0x1)) { - out[n] = _in[n]; - } - ret.str = out; - return ret; -} diff --git a/src/u8c/str.h.d/strfndchr.c b/src/u8c/str.h.d/strfndchr.c deleted file mode 100644 index 93bb77c..0000000 --- a/src/u8c/str.h.d/strfndchr.c +++ /dev/null @@ -1,45 +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/>. -*/ -# include <stdbool.h> -# include <stddef.h> -# include <stdint.h> -# include <u8c/SIZE_C.h> -# include <u8c/err.h> -# include <u8c/str.h> -struct u8c_strfndchr_tuple u8c_strfndchr(char32_t const * const restrict _in,char32_t const _chr) { - struct u8c_strfndchr_tuple ret = { - .stat = false, - }; - for(register size_t n = SIZE_C(0x0);n <= SIZE_MAX;n += SIZE_C(0x1)) { - register uint_least32_t const tmp = _in[n]; - if(tmp == U'\x0') { - if(_chr == U'\x0') { - ret.pos = n; - return ret; - } - ret.pos = SIZE_C(-0x1); - return ret; - } - if(tmp == _chr) { - ret.pos = n; - return ret; - } - } - u8c_seterr(u8c_errtyp_untermin,U"u8c_strfndchr: Unterminated input."); - ret.pos = SIZE_C(-0x1); - ret.stat = true; - return ret; -} diff --git a/src/u8c/str.h.d/strfndpat.c b/src/u8c/str.h.d/strfndpat.c deleted file mode 100644 index 1091238..0000000 --- a/src/u8c/str.h.d/strfndpat.c +++ /dev/null @@ -1,43 +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/>. -*/ -# include <stdbool.h> -# include <stddef.h> -# include <stdint.h> -# include <u8c/SIZE_C.h> -# include <u8c/err.h> -# include <u8c/str.h> -struct u8c_strfndpat_tuple u8c_strfndpat(char32_t const * const restrict _in,char32_t const * const restrict _pat) { - struct u8c_strfndpat_tuple ret = { - .stat = false, - }; - size_t insz = u8c_strsz(_in).sz; - size_t patsz = u8c_strsz(_pat).sz; - if(insz == SIZE_C(0x1) || insz < patsz) { - ret.pos = SIZE_C(-0x1); - return ret; - } - for(register size_t n = SIZE_C(0x0);n < insz - patsz;n += SIZE_C(0x1)) { - char32_t const * str = u8c_strsubstr(n,patsz - SIZE_C(0x1),_in).str; - uint_least8_t const cmpres = u8c_strcmp(str,_pat).res; - u8c_strfree(str); - if(cmpres == UINT8_C(0x1)) { - ret.pos = n; - return ret; - } - } - ret.pos = SIZE_C(-0x1); - return ret; -} diff --git a/src/u8c/str.h.d/strfree.c b/src/u8c/str.h.d/strfree.c deleted file mode 100644 index bf6d477..0000000 --- a/src/u8c/str.h.d/strfree.c +++ /dev/null @@ -1,26 +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/>. -*/ -# include <stdbool.h> -# include <stdint.h> -# include <stdlib.h> -# include <u8c/str.h> -struct u8c_strfree_tuple u8c_strfree(char32_t const * const restrict _str) { - struct u8c_strfree_tuple ret = { - .stat = false, - }; - free((char32_t *)_str); /* This cast does indeed discard a const-qualifier, but it is not undefined behaviour, as the array must have been allocated by calloc or malloc, meaning it's original type is not const-qualified. */ - return ret; -} diff --git a/src/u8c/str.h.d/strins.c b/src/u8c/str.h.d/strins.c deleted file mode 100644 index 89173ae..0000000 --- a/src/u8c/str.h.d/strins.c +++ /dev/null @@ -1,38 +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/>. -*/ -# include <stdbool.h> -# include <stddef.h> -# include <u8c/SIZE_C.h> -# include <u8c/str.h> -# include <uchar.h> -struct u8c_strins_tuple u8c_strins(size_t const _pos,char32_t const * const restrict _str0,char32_t const * const restrict _str1) { - struct u8c_strins_tuple ret = { - .stat = false, - }; - char32_t const * lstr = u8c_strsubstr(SIZE_C(0x0),_pos - SIZE_C(0x1),_str0).str; - char32_t const * rstr = u8c_strsubstr(_pos,SIZE_C(0x0),_str0).str; - ret.strsz = SIZE_C(0x0); - char32_t const * out = NULL; - { - char32_t const * tmp = u8c_strcat(lstr,_str1).str; - u8c_strfree(lstr); - out = u8c_strcat(tmp,rstr).str; - u8c_strfree(rstr); - u8c_strfree(tmp); - } - ret.str = out; - return ret; -} diff --git a/src/u8c/str.h.d/strsubstr.c b/src/u8c/str.h.d/strsubstr.c deleted file mode 100644 index b9daac5..0000000 --- a/src/u8c/str.h.d/strsubstr.c +++ /dev/null @@ -1,48 +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/>. -*/ -# include <stdbool.h> -# include <stdlib.h> -# include <u8c/SIZE_C.h> -# include <u8c/str.h> -# include <uchar.h> -struct u8c_strsubstr_tuple u8c_strsubstr(size_t const _start,size_t const _len,char32_t const * const restrict _in) { - struct u8c_strsubstr_tuple ret = { - .stat = false, - }; - size_t insz = u8c_strsz(_in).sz; - size_t len = _len; - if(_len == SIZE_C(0x0)) { - len = insz - _start; - } - if(insz < _start + len) { - return ret; - } - size_t const outsz = len + SIZE_C(0x2); - char32_t * out = NULL; - { - struct u8c_stralloc_tuple const tuple = u8c_stralloc(outsz); - if(tuple.stat) { - ret.stat = true; - return ret; - } - out = tuple.str; - } - for(register size_t n = SIZE_C(0x0);n <= len;n += SIZE_C(0x1)) { - out[n] = _in[n + _start]; - } - ret.str = out; - return ret; -} diff --git a/src/u8c/str.h.d/strsz.c b/src/u8c/str.h.d/strsz.c deleted file mode 100644 index f1b348a..0000000 --- a/src/u8c/str.h.d/strsz.c +++ /dev/null @@ -1,35 +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/>. -*/ -# include <stdbool.h> -# include <stddef.h> -# include <stdint.h> -# include <u8c/SIZE_C.h> -# include <u8c/str.h> -# include <uchar.h> -struct u8c_strsz_tuple u8c_strsz(char32_t const * const restrict _in) { - struct u8c_strsz_tuple ret = { - .stat = false, - }; - { - struct u8c_strfndchr_tuple const tuple = u8c_strfndchr(_in,UINT8_C(0x0)); - if(tuple.stat) { - ret.stat = true; - return ret; - } - ret.sz = tuple.pos; - } - return ret; -} |