summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile13
-rw-r--r--README.md2
-rw-r--r--changelog.md9
-rw-r--r--include/u8c/fmt.h2
-rw-r--r--include/u8c/freeu32.h26
-rw-r--r--include/u8c/freeu8.h26
-rw-r--r--include/u8c/geterr.h2
-rw-r--r--include/u8c/isalnum.h2
-rw-r--r--include/u8c/isalpha.h2
-rw-r--r--include/u8c/iscntrl.h2
-rw-r--r--include/u8c/isdigit.h2
-rw-r--r--include/u8c/ispunct.h2
-rw-r--r--include/u8c/isspace.h2
-rw-r--r--include/u8c/print.h2
-rw-r--r--include/u8c/println.h2
-rw-r--r--include/u8c/seterr.h2
-rw-r--r--include/u8c/txt.h29
-rw-r--r--include/u8c/u32cmp.h2
-rw-r--r--include/u8c/u32cp.h2
-rw-r--r--include/u8c/u32sz.h2
-rw-r--r--include/u8c/u8dec.h2
-rw-r--r--include/u8c/u8enc.h2
-rw-r--r--include/u8c/ver.h2
-rw-r--r--include/u8c/vfmt.h2
-rw-r--r--include/u8c/vprint.h2
-rw-r--r--src/u8c/end.c3
-rw-r--r--src/u8c/err.c2
-rw-r--r--src/u8c/err.h2
-rw-r--r--src/u8c/fmt.c2
-rw-r--r--src/u8c/geterr.c2
-rw-r--r--src/u8c/isalnum.c2
-rw-r--r--src/u8c/isalpha.c2
-rw-r--r--src/u8c/iscntrl.c2
-rw-r--r--src/u8c/isdigit.c2
-rw-r--r--src/u8c/ispunct.c2
-rw-r--r--src/u8c/isspace.c2
-rw-r--r--src/u8c/print.c2
-rw-r--r--src/u8c/println.c2
-rw-r--r--src/u8c/seterr.c5
-rw-r--r--src/u8c/u32cmp.c2
-rw-r--r--src/u8c/u32cp.c7
-rw-r--r--src/u8c/u32sz.c2
-rw-r--r--src/u8c/u8dec.c13
-rw-r--r--src/u8c/u8enc.c2
-rw-r--r--src/u8c/vfmt.c2
-rw-r--r--src/u8c/vprint.c12
-rw-r--r--test.c32
-rw-r--r--txttolit.c2
48 files changed, 179 insertions, 70 deletions
diff --git a/Makefile b/Makefile
index 4274b2f..d5371fb 100644
--- a/Makefile
+++ b/Makefile
@@ -1,7 +1,5 @@
-CC = clang
-CFLAGS = -std=c17 -Weverything -Wno-c99-compat -Wno-format-nonliteral -Wpedantic -Iinclude -march=native -mtune=native -O3
-CFLAGS0 = $(CFLAGS) -g -L. -lu8c -o $@ $^
-CFLAGS += -fPIC
+CC = clang
+CFLAGS = -std=c17 -Wall -Wextra -Wpedantic -Iinclude -march=native -mtune=native -O3 -fPIC
ifneq ($(thrdsafe),0)
CFLAGS += -Du8c_bethrdsafe
endif
@@ -44,6 +42,8 @@ HDRS = \
include/u8c/end.h \
include/u8c/fmt.h \
include/u8c/fmttyp.h \
+ include/u8c/freeu32.h \
+ include/u8c/freeu8.h \
include/u8c/geterr.h \
include/u8c/init.h \
include/u8c/isalnum.h \
@@ -57,6 +57,7 @@ HDRS = \
include/u8c/seterr.h \
include/u8c/SIZE_C.h \
include/u8c/thrdsafe.h \
+ include/u8c/txt.h \
include/u8c/u32cmp.h \
include/u8c/u32cp.h \
include/u8c/u32sz.h \
@@ -87,9 +88,9 @@ purge:
runtest: test
export LD_LIBRARY_PATH=$(CURDIR) && ./$^
test: $(LIB) test.c
- $(CC) $(CFLAGS0)
+ $(CC) -std=c17 -Wall -Wextra -Wpedantic -Iinclude -march=native -mtune=native -O3 -g -L. -lu8c -o $@ [email protected]
txttolit: $(LIB) txttolit.c
- $(CC) $(CFLAGS0)
+ $(CC) -std=c17 -Wall -Wextra -Wpedantic -Iinclude -march=native -mtune=native -O3 -g -L. -lu8c -o $@ [email protected]
export LD_LIBRARY_PATH=$(CURDIR) && ./$@
uninstall:
rm --force --recursive $(DESTDIR)/include/u8c/
diff --git a/README.md b/README.md
index 94da579..b9e6a4e 100644
--- a/README.md
+++ b/README.md
@@ -1,6 +1,6 @@
# u8c
-[*u8c*](https://mandelbrot.dk/delta/u8c) is a free, open-source, and portable C-based library for transforming Unicode codepoints, as well as encoding them into UTF-8, even on implementations that use a different 32 bit encoding (I actually don't know what else it could be).
+[*u8c*](https://mandelbrot.dk/delta/u8c) is a cross-platform, free, and open-source library for transforming Unicode codepoints, as well as encoding them into UTF-8, even on implementations that use a different 32 bit encoding.
## Installing
diff --git a/changelog.md b/changelog.md
index 9daae68..6943821 100644
--- a/changelog.md
+++ b/changelog.md
@@ -1,3 +1,12 @@
+# 11
+
+* Update README.
+* Update Makefile.
+* Use constant variables more.
+* Create macro for creating human-readable UTF-32 strings; `u8c_txt`.
+* Add macros for deallocating UTF-32 and UTF-8 strings (use these instead of `free` og `std::free`); `u8c_freeu32` and `u8c_freeu8`.
+* Optimisations.
+
# 10
* Make `u8c_seterr` public.
diff --git a/include/u8c/fmt.h b/include/u8c/fmt.h
index 7f31528..61ee8b2 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 outsz,uint_least32_t * * const out,uint_least32_t * const in,...);
+extern uint_least8_t u8c_fmt(size_t * const outsz,uint_least32_t const * * const out,uint_least32_t const * const in,...);
# if defined(__cplusplus)
}
# endif
diff --git a/include/u8c/freeu32.h b/include/u8c/freeu32.h
new file mode 100644
index 0000000..99ac8c2
--- /dev/null
+++ b/include/u8c/freeu32.h
@@ -0,0 +1,26 @@
+/*
+ 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/>.
+*/
+/* Format */
+# if !defined(u8c_freeu32)
+# if defined(__cplusplus)
+# include <cstdlib>
+# define u8c_freeu32(u32) (std::free(const_cast<uint_least32_t *>(u32)))
+# else
+# include <stdint.h>
+# include <stdlib.h>
+# define u8c_freeu32(u32) (free((uint_least32_t *)u32))
+# endif
+# endif
diff --git a/include/u8c/freeu8.h b/include/u8c/freeu8.h
new file mode 100644
index 0000000..7ae7abd
--- /dev/null
+++ b/include/u8c/freeu8.h
@@ -0,0 +1,26 @@
+/*
+ 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/>.
+*/
+/* Format */
+# if !defined(u8c_freeu8)
+# if defined(__cplusplus)
+# include <cstdlib>
+# define u8c_freeu8(u8) (std::free(u8))
+# else
+# include <stdint.h>
+# include <stdlib.h>
+# define u8c_freeu8(u8) (free((uint_least8_t *)u8))
+# endif
+# endif
diff --git a/include/u8c/geterr.h b/include/u8c/geterr.h
index abc1fb6..45a25ac 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 sz,uint_least32_t * * const out);
+extern uint_least8_t u8c_geterr(size_t * const sz,uint_least32_t const * * const out);
# if defined(__cplusplus)
}
# endif
diff --git a/include/u8c/isalnum.h b/include/u8c/isalnum.h
index 7b8c7fa..0b61bfd 100644
--- a/include/u8c/isalnum.h
+++ b/include/u8c/isalnum.h
@@ -20,7 +20,7 @@
# if defined(__cplusplus)
extern "C" {
# endif
-extern uint_least8_t u8c_isalnum(uint_least8_t * const res,uint_least32_t chr);
+extern uint_least8_t u8c_isalnum(uint_least8_t * const res,uint_least32_t const chr);
# if defined(__cplusplus)
}
# endif
diff --git a/include/u8c/isalpha.h b/include/u8c/isalpha.h
index 1065414..3493dc0 100644
--- a/include/u8c/isalpha.h
+++ b/include/u8c/isalpha.h
@@ -20,7 +20,7 @@
# if defined(__cplusplus)
extern "C" {
# endif
-extern uint_least8_t u8c_isalpha(uint_least8_t * const res,uint_least32_t chr);
+extern uint_least8_t u8c_isalpha(uint_least8_t * const res,uint_least32_t const chr);
# if defined(__cplusplus)
}
# endif
diff --git a/include/u8c/iscntrl.h b/include/u8c/iscntrl.h
index 2e30d1c..0f52911 100644
--- a/include/u8c/iscntrl.h
+++ b/include/u8c/iscntrl.h
@@ -20,7 +20,7 @@
# if defined(__cplusplus)
extern "C" {
# endif
-extern uint_least8_t u8c_iscntrl(uint_least8_t * const res,uint_least32_t chr);
+extern uint_least8_t u8c_iscntrl(uint_least8_t * const res,uint_least32_t const chr);
# if defined(__cplusplus)
}
# endif
diff --git a/include/u8c/isdigit.h b/include/u8c/isdigit.h
index 4fdad4a..c2053c7 100644
--- a/include/u8c/isdigit.h
+++ b/include/u8c/isdigit.h
@@ -20,7 +20,7 @@
# if defined(__cplusplus)
extern "C" {
# endif
-extern uint_least8_t u8c_isdigit(uint_least8_t * const res,uint_least32_t chr);
+extern uint_least8_t u8c_isdigit(uint_least8_t * const res,uint_least32_t const chr);
# if defined(__cplusplus)
}
# endif
diff --git a/include/u8c/ispunct.h b/include/u8c/ispunct.h
index 68809f2..a4da5c9 100644
--- a/include/u8c/ispunct.h
+++ b/include/u8c/ispunct.h
@@ -20,7 +20,7 @@
# if defined(__cplusplus)
extern "C" {
# endif
-extern uint_least8_t u8c_ispunct(uint_least8_t * const res,uint_least32_t chr);
+extern uint_least8_t u8c_ispunct(uint_least8_t * const res,uint_least32_t const chr);
# if defined(__cplusplus)
}
# endif
diff --git a/include/u8c/isspace.h b/include/u8c/isspace.h
index 2fec0e0..35f9d4f 100644
--- a/include/u8c/isspace.h
+++ b/include/u8c/isspace.h
@@ -20,7 +20,7 @@
# if defined(__cplusplus)
extern "C" {
# endif
-extern uint_least8_t u8c_isspace(uint_least8_t * const res,uint_least32_t chr);
+extern uint_least8_t u8c_isspace(uint_least8_t * const res,uint_least32_t const chr);
# if defined(__cplusplus)
}
# endif
diff --git a/include/u8c/print.h b/include/u8c/print.h
index f30b485..f77875d 100644
--- a/include/u8c/print.h
+++ b/include/u8c/print.h
@@ -21,7 +21,7 @@
# if defined(__cplusplus)
extern "C" {
# endif
-extern uint_least8_t u8c_print(FILE * fp,uint_least32_t * const msg,...);
+extern uint_least8_t u8c_print(FILE * fp,uint_least32_t const * const msg,...);
# if defined(__cplusplus)
}
# endif
diff --git a/include/u8c/println.h b/include/u8c/println.h
index 2887726..d6874de 100644
--- a/include/u8c/println.h
+++ b/include/u8c/println.h
@@ -21,7 +21,7 @@
# if defined(__cplusplus)
extern "C" {
# endif
-extern uint_least8_t u8c_println(FILE * fp,uint_least32_t * const msg,...);
+extern uint_least8_t u8c_println(FILE * fp,uint_least32_t const * const msg,...);
# if defined(__cplusplus)
}
# endif
diff --git a/include/u8c/seterr.h b/include/u8c/seterr.h
index df3270f..ae2f534 100644
--- a/include/u8c/seterr.h
+++ b/include/u8c/seterr.h
@@ -17,5 +17,5 @@
# if !defined(u8c_sym_seterr)
# define u8c_sym_seterr
# include <stdint.h>
-extern uint_least8_t u8c_seterr(uint_least32_t * const msg);
+extern uint_least8_t u8c_seterr(uint_least32_t const * const msg);
# endif
diff --git a/include/u8c/txt.h b/include/u8c/txt.h
new file mode 100644
index 0000000..8b2ba45
--- /dev/null
+++ b/include/u8c/txt.h
@@ -0,0 +1,29 @@
+/*
+ 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/>.
+*/
+/* Text */
+# if !defined(__STDC_UTF_32__)
+# error UTF-32 is required to use u8c_txt.
+# else
+# if !defined(u8c_txt)
+# if defined(__cplusplus)
+# include <cstdint>
+# define u8c_txt(txt) (reinterpret_cast<std::uint_least32_t const *>(U ## txt ## ))
+# else
+# include <stdint.h>
+# define u8c_txt(txt) (uint_least32_t const *)U ## txt
+# endif
+# endif
+# endif
diff --git a/include/u8c/u32cmp.h b/include/u8c/u32cmp.h
index aa437f0..5ca3d5d 100644
--- a/include/u8c/u32cmp.h
+++ b/include/u8c/u32cmp.h
@@ -20,7 +20,7 @@
# 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);
+extern uint_least8_t u8c_u32cmp(uint_least8_t * const res,uint_least32_t const * const lstr,uint_least32_t const * const rstr);
# if defined(__cplusplus)
}
# endif
diff --git a/include/u8c/u32cp.h b/include/u8c/u32cp.h
index 4b2a66e..66cc870 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 sz,uint_least32_t * * const out,uint_least32_t * const in);
+extern uint_least8_t u8c_u32cp(size_t * const sz,uint_least32_t const * * const out,uint_least32_t const * const in);
# if defined(__cplusplus)
}
# endif
diff --git a/include/u8c/u32sz.h b/include/u8c/u32sz.h
index 1a763f7..b97ccdb 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 * sz,uint_least32_t * in);
+extern uint_least8_t u8c_u32sz(size_t * sz,uint_least32_t const * in);
# if defined(__cplusplus)
}
# endif
diff --git a/include/u8c/u8dec.h b/include/u8c/u8dec.h
index 45c7f72..eed43ae 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 sz,uint_least32_t * * const out,uint_least8_t * const in);
+extern uint_least8_t u8c_u8dec(size_t * const sz,uint_least32_t const * * const out,uint_least8_t const * const in);
# if defined(__cplusplus)
}
# endif
diff --git a/include/u8c/u8enc.h b/include/u8c/u8enc.h
index 5223898..8040f8d 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 sz,uint_least8_t * * const out,uint_least32_t * const in);
+extern uint_least8_t u8c_u8enc(size_t * const sz,uint_least8_t const * * const out,uint_least32_t const * const in);
# if defined(__cplusplus)
}
# endif
diff --git a/include/u8c/ver.h b/include/u8c/ver.h
index b2101af..3122392 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(0xC))
+# define u8c_ver (UINT64_C(0xD))
# endif
diff --git a/include/u8c/vfmt.h b/include/u8c/vfmt.h
index dc29311..d4ae9b0 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 sz,uint_least32_t * * const out,uint_least32_t * const in,va_list args);
+extern uint_least8_t u8c_vfmt(size_t * const sz,uint_least32_t const * * const out,uint_least32_t const * const in,va_list args);
# if defined(__cplusplus)
}
# endif
diff --git a/include/u8c/vprint.h b/include/u8c/vprint.h
index c2b292e..ace9612 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 msg,va_list args);
+extern uint_least8_t u8c_vprint(FILE * fp,uint_least32_t const * const msg,va_list args);
# if defined(__cplusplus)
}
# endif
diff --git a/src/u8c/end.c b/src/u8c/end.c
index 924540b..8cd243d 100644
--- a/src/u8c/end.c
+++ b/src/u8c/end.c
@@ -19,6 +19,7 @@
# include <stdint.h>
# include <stdlib.h>
# include <u8c/end.h>
+# include <u8c/freeu32.h>
# if defined(u8c_bethrdsafe)
# include <threads.h>
# endif
@@ -29,7 +30,7 @@ uint_least8_t u8c_end(void) {
# if defined(u8c_bethrdsafe)
mtx_destroy(&u8c_errlock);
# endif
- free(u8c_err);
+ u8c_freeu32(u8c_err);
u8c_stat = UINT8_C(0x1);
return UINT8_C(0x0);
}
diff --git a/src/u8c/err.c b/src/u8c/err.c
index 6c7a940..77a8221 100644
--- a/src/u8c/err.c
+++ b/src/u8c/err.c
@@ -16,4 +16,4 @@
# include "err.h"
# include <stddef.h>
# include <stdint.h>
-uint_least32_t * u8c_err = NULL;
+uint_least32_t const * u8c_err = NULL;
diff --git a/src/u8c/err.h b/src/u8c/err.h
index 895710d..1537701 100644
--- a/src/u8c/err.h
+++ b/src/u8c/err.h
@@ -16,5 +16,5 @@
# if !defined(u8c_sym_err)
# define u8c_sym_err
# include <stdint.h>
-extern uint_least32_t * u8c_err;
+extern uint_least32_t const * u8c_err;
# endif
diff --git a/src/u8c/fmt.c b/src/u8c/fmt.c
index fe59af6..67015da 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 _outsz,uint_least32_t * * const _out,uint_least32_t * const _in,...) {
+uint_least8_t u8c_fmt(size_t * const _outsz,uint_least32_t const * * const _out,uint_least32_t const * 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 88ec264..d18f696 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 _sz,uint_least32_t * * const _out) {
+uint_least8_t u8c_geterr(size_t * const _sz,uint_least32_t const * * const _out) {
# if defined(u8c_bethrdsafe)
mtx_lock(&u8c_errlock);
# endif
diff --git a/src/u8c/isalnum.c b/src/u8c/isalnum.c
index d2ab013..ae2e4c8 100644
--- a/src/u8c/isalnum.c
+++ b/src/u8c/isalnum.c
@@ -19,7 +19,7 @@
# include <u8c/isalnum.h>
# include <u8c/isalpha.h>
# include <u8c/isdigit.h>
-uint_least8_t u8c_isalnum(uint_least8_t * const _res,uint_least32_t _chr) {
+uint_least8_t u8c_isalnum(uint_least8_t * const _res,uint_least32_t const _chr) {
assert(_res != NULL);
uint_least8_t res = UINT8_C(0x0);
u8c_isalpha(&res,_chr);
diff --git a/src/u8c/isalpha.c b/src/u8c/isalpha.c
index 75f3586..bc6d5c0 100644
--- a/src/u8c/isalpha.c
+++ b/src/u8c/isalpha.c
@@ -17,7 +17,7 @@
# include <stddef.h>
# include <stdint.h>
# include <u8c/isalpha.h>
-uint_least8_t u8c_isalpha(uint_least8_t * const _res,uint_least32_t _chr) {
+uint_least8_t u8c_isalpha(uint_least8_t * const _res,uint_least32_t const _chr) {
assert(_res != NULL);
switch(_chr) {
default:
diff --git a/src/u8c/iscntrl.c b/src/u8c/iscntrl.c
index dfd82ed..75d3fa5 100644
--- a/src/u8c/iscntrl.c
+++ b/src/u8c/iscntrl.c
@@ -17,7 +17,7 @@
# include <stddef.h>
# include <stdint.h>
# include <u8c/iscntrl.h>
-uint_least8_t u8c_iscntrl(uint_least8_t * const _res,uint_least32_t _chr) {
+uint_least8_t u8c_iscntrl(uint_least8_t * const _res,uint_least32_t const _chr) {
assert(_res != NULL);
switch(_chr) {
default:
diff --git a/src/u8c/isdigit.c b/src/u8c/isdigit.c
index 1d5e35f..ebfd7c2 100644
--- a/src/u8c/isdigit.c
+++ b/src/u8c/isdigit.c
@@ -17,7 +17,7 @@
# include <stddef.h>
# include <stdint.h>
# include <u8c/isdigit.h>
-uint_least8_t u8c_isdigit(uint_least8_t * const _res,uint_least32_t _chr) {
+uint_least8_t u8c_isdigit(uint_least8_t * const _res,uint_least32_t const _chr) {
assert(_res != NULL);
switch(_chr) {
default:
diff --git a/src/u8c/ispunct.c b/src/u8c/ispunct.c
index 11a155a..abdd72b 100644
--- a/src/u8c/ispunct.c
+++ b/src/u8c/ispunct.c
@@ -17,7 +17,7 @@
# include <stddef.h>
# include <stdint.h>
# include <u8c/ispunct.h>
-uint_least8_t u8c_ispunct(uint_least8_t * const _res,uint_least32_t _chr) {
+uint_least8_t u8c_ispunct(uint_least8_t * const _res,uint_least32_t const _chr) {
assert(_res != NULL);
switch(_chr) {
default:
diff --git a/src/u8c/isspace.c b/src/u8c/isspace.c
index 3bd8b96..8b1ad9b 100644
--- a/src/u8c/isspace.c
+++ b/src/u8c/isspace.c
@@ -17,7 +17,7 @@
# include <stddef.h>
# include <stdint.h>
# include <u8c/isspace.h>
-uint_least8_t u8c_isspace(uint_least8_t * const _res,uint_least32_t _chr) {
+uint_least8_t u8c_isspace(uint_least8_t * const _res,uint_least32_t const _chr) {
assert(_res != NULL);
switch(_chr) {
default:
diff --git a/src/u8c/print.c b/src/u8c/print.c
index f982a25..d8fb7d7 100644
--- a/src/u8c/print.c
+++ b/src/u8c/print.c
@@ -17,7 +17,7 @@
# include <stdint.h>
# include <u8c/print.h>
# include <u8c/vprint.h>
-uint_least8_t u8c_print(FILE * _fp,uint_least32_t * const _msg,...) {
+uint_least8_t u8c_print(FILE * _fp,uint_least32_t const * const _msg,...) {
va_list args;
va_start(args,_msg);
uint_least8_t val = u8c_vprint(_fp,_msg,args);
diff --git a/src/u8c/println.c b/src/u8c/println.c
index f21bba0..dcf592d 100644
--- a/src/u8c/println.c
+++ b/src/u8c/println.c
@@ -20,7 +20,7 @@
# include <u8c/println.h>
# include <u8c/seterr.h>
# include <u8c/vprint.h>
-uint_least8_t u8c_println(FILE * _fp,uint_least32_t * const _msg,...) {
+uint_least8_t u8c_println(FILE * _fp,uint_least32_t const * const _msg,...) {
assert(_fp != NULL);
va_list args;
va_start(args,_msg);
diff --git a/src/u8c/seterr.c b/src/u8c/seterr.c
index c9fec04..5796683 100644
--- a/src/u8c/seterr.c
+++ b/src/u8c/seterr.c
@@ -19,18 +19,19 @@
# include <stdint.h>
# include <stdlib.h>
# include <u8c/dbgprint.h>
+# include <u8c/freeu32.h>
# include <u8c/seterr.h>
# include <u8c/u32cp.h>
# if defined(u8c_bethrdsafe)
# include <threads.h>
# endif
-uint_least8_t u8c_seterr(uint_least32_t * const _msg) {
+uint_least8_t u8c_seterr(uint_least32_t const * const _msg) {
assert(_msg != NULL);
u8c_dbgprint(_msg);
# if defined(u8c_bethrdsafe)
mtx_lock(&u8c_errlock);
# endif
- free(u8c_err);
+ u8c_freeu32(u8c_err);
u8c_u32cp(NULL,&u8c_err,_msg);
# if defined(u8c_bethrdsafe)
mtx_unlock(&u8c_errlock);
diff --git a/src/u8c/u32cmp.c b/src/u8c/u32cmp.c
index 138eb22..3f8e405 100644
--- a/src/u8c/u32cmp.c
+++ b/src/u8c/u32cmp.c
@@ -19,7 +19,7 @@
# include <u8c/seterr.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) {
+uint_least8_t u8c_u32cmp(uint_least8_t * const _res,uint_least32_t const * const _lstr,uint_least32_t const * const _rstr) {
assert(_res != NULL);
assert(_lstr != NULL);
assert(_rstr != NULL);
diff --git a/src/u8c/u32cp.c b/src/u8c/u32cp.c
index a91226c..35e8940 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 _sz,uint_least32_t * * const _out,uint_least32_t * const _in) {
+uint_least8_t u8c_u32cp(size_t * const _sz,uint_least32_t const * * const _out,uint_least32_t const * const _in) {
assert(_in != NULL);
size_t insz = SIZE_C(0x0);
u8c_u32sz(&insz,_in);
@@ -28,10 +28,11 @@ uint_least8_t u8c_u32cp(size_t * const _sz,uint_least32_t * * const _out,uint_le
if(_sz != NULL) {
*_sz = insz;
}
- if((*_out = calloc(sizeof(uint_least32_t),insz)) == NULL) {
+ uint_least32_t * out;
+ 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];
}
diff --git a/src/u8c/u32sz.c b/src/u8c/u32sz.c
index d0af24a..ca8b1be 100644
--- a/src/u8c/u32sz.c
+++ b/src/u8c/u32sz.c
@@ -19,7 +19,7 @@
# include <u8c/seterr.h>
# include <u8c/SIZE_C.h>
# include <u8c/u32sz.h>
-uint_least8_t u8c_u32sz(size_t * const _sz,uint_least32_t * const _u32) {
+uint_least8_t u8c_u32sz(size_t * const _sz,uint_least32_t const * const _u32) {
assert(_sz != NULL);
assert(_u32 != NULL);
for(register size_t n = SIZE_C(0x0);n <= SIZE_MAX;n += SIZE_C(0x1)) {
diff --git a/src/u8c/u8dec.c b/src/u8c/u8dec.c
index 98288a6..dfbfeaf 100644
--- a/src/u8c/u8dec.c
+++ b/src/u8c/u8dec.c
@@ -19,7 +19,7 @@
# include <u8c/seterr.h>
# include <u8c/u8dec.h>
# include <u8c/SIZE_C.h>
-uint_least8_t u8c_u8dec(size_t * const _sz,uint_least32_t * * const _out,uint_least8_t * const _in) {
+uint_least8_t u8c_u8dec(size_t * const _sz,uint_least32_t const * * const _out,uint_least8_t const * const _in) {
assert(_in != NULL);
register size_t insz = SIZE_C(0x0);
register size_t outsz = SIZE_C(0x1);
@@ -55,7 +55,7 @@ nottoobig:;
if(_sz != NULL) {
*_sz = outsz;
}
- *_out = calloc(sizeof(uint_least32_t),outsz);
+ uint_least32_t * out = calloc(sizeof(uint_least32_t),outsz);
for(register size_t n = SIZE_C(0x0),outn = SIZE_C(0x0);n < insz;outn += SIZE_C(0x1)) { /* Second pass: decode UTF-8. */
if(_in[n] >= UINT8_C(0xF0)) { /* Four byte. */
uint_least32_t codep = (_in[n] ^ UINT32_C(0xF0)) << UINT32_C(0x12);
@@ -66,7 +66,7 @@ nottoobig:;
n += SIZE_C(0x1);
codep += (uint_least32_t)(_in[n]) ^ SIZE_C(0x80);
n += SIZE_C(0x1);
- (*_out)[outn] = codep;
+ out[outn] = codep;
continue;
}
if(_in[n] >= UINT8_C(0xE0)) { /* Three bytes. */
@@ -76,7 +76,7 @@ nottoobig:;
n += SIZE_C(0x1);
codep += _in[n] ^ UINT32_C(0x80);
n += SIZE_C(0x1);
- (*_out)[outn] = codep;
+ out[outn] = codep;
continue;
}
if(_in[n] >= UINT8_C(0xC0)) { /* Two bytes. */
@@ -84,13 +84,14 @@ nottoobig:;
n += SIZE_C(0x1);
codep += _in[n] ^ UINT32_C(0x80);
n += SIZE_C(0x1);
- (*_out)[outn] = codep;
+ out[outn] = codep;
continue;
}
/* One byte. */
- (*_out)[outn] = (uint_least32_t)(_in[n]);
+ out[outn] = (uint_least32_t)(_in[n]);
n += SIZE_C(0x1);
continue;
}
+ *_out = out;
return UINT8_C(0x0);
}
diff --git a/src/u8c/u8enc.c b/src/u8c/u8enc.c
index 2ad8090..dda62d3 100644
--- a/src/u8c/u8enc.c
+++ b/src/u8c/u8enc.c
@@ -19,7 +19,7 @@
# include <u8c/seterr.h>
# include <u8c/u8enc.h>
# include <u8c/SIZE_C.h>
-uint_least8_t u8c_u8enc(size_t * const _sz,uint_least8_t * * const _out,uint_least32_t * const _in) {
+uint_least8_t u8c_u8enc(size_t * const _sz,uint_least8_t const * * const _out,uint_least32_t const * 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). */
diff --git a/src/u8c/vfmt.c b/src/u8c/vfmt.c
index 5afc6cf..e32b6fa 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 _sz,uint_least32_t * * const _out,uint_least32_t * const _in,va_list _args) {
+uint_least8_t u8c_vfmt(size_t * const _sz,uint_least32_t const * * const _out,uint_least32_t const * 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 a731cb2..2e418ca 100644
--- a/src/u8c/vprint.c
+++ b/src/u8c/vprint.c
@@ -18,24 +18,26 @@
# include <stdint.h>
# include <stdio.h>
# include <stdlib.h>
+# include <u8c/freeu32.h>
+# include <u8c/freeu8.h>
# include <u8c/seterr.h>
# include <u8c/u8enc.h>
# include <u8c/SIZE_C.h>
# include <u8c/vfmt.h>
# include <u8c/vprint.h>
-uint_least8_t u8c_vprint(FILE * _fp,uint_least32_t * const _msg,va_list _args) {
+uint_least8_t u8c_vprint(FILE * _fp,uint_least32_t const * const _msg,va_list _args) {
assert(_msg != NULL);
- uint_least32_t * str0 = NULL;
+ uint_least32_t const * str0 = NULL;
u8c_vfmt(NULL,&str0,_msg,_args);
size_t str1sz = SIZE_C(0x0);
- uint_least8_t * str1 = NULL;
+ uint_least8_t const * str1 = NULL;
u8c_u8enc(&str1sz,&str1,str0);
assert(str1sz > SIZE_C(0x0));
if(fwrite(str1,sizeof(uint_least8_t),str1sz - SIZE_C(0x1),_fp) < str1sz - SIZE_C(0x1)) {
u8c_seterr((uint_least32_t[]){UINT32_C(0x75),UINT32_C(0x38),UINT32_C(0x63),UINT32_C(0x5F),UINT32_C(0x76),UINT32_C(0x70),UINT32_C(0x72),UINT32_C(0x69),UINT32_C(0x6E),UINT32_C(0x74),UINT32_C(0x3A),UINT32_C(0x20),UINT32_C(0x66),UINT32_C(0x77),UINT32_C(0x72),UINT32_C(0x69),UINT32_C(0x74),UINT32_C(0x65),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(0x77),UINT32_C(0x72),UINT32_C(0x69),UINT32_C(0x74),UINT32_C(0x65),UINT32_C(0x20),UINT32_C(0x74),UINT32_C(0x6F),UINT32_C(0x20),UINT32_C(0x73),UINT32_C(0x74),UINT32_C(0x64),UINT32_C(0x6F),UINT32_C(0x75),UINT32_C(0x74),UINT32_C(0x2E),UINT32_C(0x0),}); /* u8c_vprint: fwrite: Unable to write to stdout. */
return UINT8_C(0x1);
}
- free(str0);
- free(str1);
+ u8c_freeu32(str0);
+ u8c_freeu8(str1);
return UINT8_C(0x0);
}
diff --git a/test.c b/test.c
index c408658..8887349 100644
--- a/test.c
+++ b/test.c
@@ -9,6 +9,8 @@
# include <u8c/end.h>
# include <u8c/fmt.h>
# include <u8c/fmttyp.h>
+# include <u8c/freeu32.h>
+# include <u8c/freeu8.h>
# include <u8c/geterr.h>
# include <u8c/init.h>
# include <u8c/isalnum.h>
@@ -30,6 +32,9 @@
# include <u8c/ver.h>
# include <u8c/vfmt.h>
# include <u8c/vprint.h>
+# if defined(__STDC_UTF_32__)
+# include <u8c/txt.h>
+# endif
static void testmsg(char const * fmt,...) {
va_list args;
va_start(args,fmt);
@@ -52,24 +57,24 @@ int main(void) {
uint_least8_t errcount1 = UINT8_C(0x0);
testmsg("Error messages");
{
- uint_least32_t * err = NULL;
+ uint_least32_t const * err = NULL;
errcount1 += u8c_geterr(NULL,&err);
errcount1 += u8c_println(stdout,err);
- free(err);
+ u8c_freeu32(err);
}
testmsgdone(&errcount0,&errcount1);
testmsg("UTF-8 encoding/decoding");
{
- uint_least32_t * msg0 = (uint_least32_t[]){UINT32_C(0xA2),UINT32_C(0x2C),UINT32_C(0x939),UINT32_C(0x2C),UINT32_C(0x10348),UINT32_C(0x2C),UINT32_C(0x20AC),UINT32_C(0x2C),UINT32_C(0x218A),UINT32_C(0x2C),UINT32_C(0x1F44B),UINT32_C(0x0)};
- uint_least8_t * msg1 = NULL;
+ uint_least32_t const * msg0 = (uint_least32_t[]){UINT32_C(0xA2),UINT32_C(0x2C),UINT32_C(0x939),UINT32_C(0x2C),UINT32_C(0x10348),UINT32_C(0x2C),UINT32_C(0x20AC),UINT32_C(0x2C),UINT32_C(0x218A),UINT32_C(0x2C),UINT32_C(0x1F44B),UINT32_C(0x0)};
+ uint_least8_t const * msg1 = NULL;
errcount1 += u8c_u8enc(NULL,&msg1,msg0);
printf("Encoded: %s\n",msg1);
errcount1 += u8c_u8dec(NULL,&msg0,msg1);
- free(msg1);
+ u8c_freeu8(msg1);
errcount1 += u8c_u8enc(NULL,&msg1,msg0);
printf("Encoded -> Decoded -> Encoded: %s\n",msg1);
- free(msg0);
- free(msg1);
+ u8c_freeu32(msg0);
+ u8c_freeu8(msg1);
}
testmsgdone(&errcount0,&errcount1);
testmsg("Printing (u8c_print)");
@@ -105,9 +110,9 @@ int main(void) {
testmsgdone(&errcount0,&errcount1);
testmsg("String comparison (UTF-32)");
{
- 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),};
+ uint_least32_t const * 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 const * 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 const * 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: ");
@@ -171,6 +176,13 @@ int main(void) {
errcount1 += u8c_println(stdout,(uint_least32_t[]){UINT32_C(0x0),});
}
testmsgdone(&errcount0,&errcount1);
+# if defined(__STDC_UTF_32__)
+ testmsg("UTF-32 string literals");
+ {
+ u8c_println(stdout,u8c_txt("Can you see this?"));
+ }
+ testmsgdone(&errcount0,&errcount1);
+# endif
printf("\n");
printf("Test done!\n");
printf("Total number of errors: %" PRIuLEAST32 ".\n",errcount0);
diff --git a/txttolit.c b/txttolit.c
index 4afcde5..24f196b 100644
--- a/txttolit.c
+++ b/txttolit.c
@@ -15,7 +15,7 @@
int main(void) {
u8c_init();
size_t u32sz = SIZE_C(0x0);
- uint_least32_t * u32 = U"Hello ðere!"; /* Place string here. */
+ uint_least32_t const * u32 = U"Hello ðere!"; /* Place string here. */
u8c_u32sz(&u32sz,u32);
printf("Arrray:\n{");
for(size_t n = SIZE_C(0x0);n < u32sz;n += SIZE_C(0x1)) {