aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMattias Andrée <m@maandree.se>2025-12-21 13:27:17 +0100
committerMattias Andrée <m@maandree.se>2025-12-21 13:27:17 +0100
commit3c801c0e2eeb3fbf0b7029296143de869c893bfb (patch)
treed75044f785bfd6a2d1526e1b26699bd3ef59c182
parentImplement script and block listing (diff)
downloadlibcmap-3c801c0e2eeb3fbf0b7029296143de869c893bfb.tar.gz
libcmap-3c801c0e2eeb3fbf0b7029296143de869c893bfb.tar.bz2
libcmap-3c801c0e2eeb3fbf0b7029296143de869c893bfb.tar.xz
Add range print functions
Signed-off-by: Mattias Andrée <m@maandree.se>
-rw-r--r--Makefile6
-rw-r--r--libcmap.h3
-rw-r--r--libcmap_snprint_range.c16
-rw-r--r--libcmap_sprint_range.c10
4 files changed, 34 insertions, 1 deletions
diff --git a/Makefile b/Makefile
index 5b9f09b..8f20ec3 100644
--- a/Makefile
+++ b/Makefile
@@ -16,6 +16,8 @@ LIB_VERSION = $(LIB_MAJOR).$(LIB_MINOR)
LIB_NAME = cmap
UNICODE_VERSION = 17.0.0
+# Before updating, remember to check downloaded files
+# changes in how unlisted codepoints should be treated
OBJ =\
@@ -23,7 +25,9 @@ OBJ =\
libcmap_script_list.o\
libcmap_find_in_no_block.o\
libcmap_find_block.o\
- libcmap_find_script.o
+ libcmap_find_script.o\
+ libcmap_sprint_range.o\
+ libcmap_snprint_range.o
HDR =\
libcmap.h
diff --git a/libcmap.h b/libcmap.h
index 7ee5d74..e849ffb 100644
--- a/libcmap.h
+++ b/libcmap.h
@@ -43,6 +43,9 @@ int libcmap_find_in_no_block(uint32_t codepoint, size_t *offset_out, size_t *sub
const struct libcmap_block *libcmap_find_block(uint32_t codepoint, size_t *offset_out);
const struct libcmap_script *libcmap_find_script(uint32_t codepoint, size_t *offset_out, size_t *subrange_out);
+int libcmap_sprint_range(char *buf, const struct libcmap_range *range, const char *endash);
+int libcmap_snprint_range(char *buf, size_t bufsize, const struct libcmap_range *range, const char *endash);
+
#undef LIBCMAP_PURE_
#undef LIBCMAP_CONST_
diff --git a/libcmap_snprint_range.c b/libcmap_snprint_range.c
new file mode 100644
index 0000000..268a80e
--- /dev/null
+++ b/libcmap_snprint_range.c
@@ -0,0 +1,16 @@
+/* See LICENSE file for copyright and license details. */
+#include "libcmap.h"
+#include <stdio.h>
+
+
+int
+libcmap_snprint_range(char *buf, size_t bufsize, const struct libcmap_range *range, const char *endash)
+{
+ unsigned long int first = (unsigned long int)range->first;
+ unsigned long int last = (unsigned long int)range->last;
+
+ if (first == last)
+ return snprintf(buf, bufsize, "U+%04lX", first);
+ else
+ return snprintf(buf, bufsize, "U+%04lX%sU+%04lX", first, endash ? endash : "–", last);
+}
diff --git a/libcmap_sprint_range.c b/libcmap_sprint_range.c
new file mode 100644
index 0000000..800fee5
--- /dev/null
+++ b/libcmap_sprint_range.c
@@ -0,0 +1,10 @@
+/* See LICENSE file for copyright and license details. */
+#include "libcmap.h"
+#include <limits.h>
+
+
+int
+libcmap_sprint_range(char *buf, const struct libcmap_range *range, const char *endash)
+{
+ return libcmap_snprint_range(buf, buf ? SIZE_MAX : (size_t)0, range, endash);
+}