diff options
| author | Mattias Andrée <m@maandree.se> | 2025-12-21 15:16:20 +0100 |
|---|---|---|
| committer | Mattias Andrée <m@maandree.se> | 2025-12-21 15:16:39 +0100 |
| commit | 83f32ab6a37ce137cb0ac7c9ffc3f8e66a6fe104 (patch) | |
| tree | f9895565a5811d1fae9b8487b430335eea7328da | |
| parent | Add documentation (diff) | |
| download | libcmap-83f32ab6a37ce137cb0ac7c9ffc3f8e66a6fe104.tar.gz libcmap-83f32ab6a37ce137cb0ac7c9ffc3f8e66a6fe104.tar.bz2 libcmap-83f32ab6a37ce137cb0ac7c9ffc3f8e66a6fe104.tar.xz | |
Add libcmap_fprint_range, libcmap_print_range, libcmap_dprint_range
Signed-off-by: Mattias Andrée <m@maandree.se>
| -rw-r--r-- | Makefile | 5 | ||||
| -rw-r--r-- | common.h | 1 | ||||
| -rw-r--r-- | libcmap.h | 50 | ||||
| -rw-r--r-- | libcmap_dprint_range.c | 12 | ||||
| -rw-r--r-- | libcmap_fprint_range.c | 12 | ||||
| -rw-r--r-- | libcmap_print_range.c | 9 |
6 files changed, 85 insertions, 4 deletions
@@ -27,7 +27,10 @@ OBJ =\ libcmap_find_block.o\ libcmap_find_script.o\ libcmap_sprint_range.o\ - libcmap_snprint_range.o + libcmap_snprint_range.o\ + libcmap_fprint_range.o\ + libcmap_print_range.o\ + libcmap_dprint_range.o HDR =\ libcmap.h\ @@ -1,7 +1,6 @@ /* See LICENSE file for copyright and license details. */ #include "libcmap.h" #include <limits.h> -#include <stdio.h> #define SINGLETON_RANGE_FMT "U+%04lX" @@ -4,6 +4,8 @@ #include <stddef.h> #include <stdint.h> +#include <stdio.h> + #if defined(__GNUC__) # define LIBCMAP_PURE_ __attribute__((__pure__)) @@ -224,6 +226,7 @@ const struct libcmap_block *libcmap_find_block(uint32_t codepoint, size_t *offse */ const struct libcmap_script *libcmap_find_script(uint32_t codepoint, size_t *offset_out, size_t *subrange_out); + /** * Print a string representing a Unicode codepoint range * @@ -233,7 +236,9 @@ const struct libcmap_script *libcmap_find_script(uint32_t codepoint, size_t *off * @param endash Desired delimiter between the first and the last * codepoint, or `NULL` for the default (not ASCII) * @return The number of bytes in the string, excluding the - * terminating NUL byte + * terminating NUL byte, -1 on failure + * + * @throws Any error specified for sprintf(3) * * A NUL byte will added to the end of the string, but this byte * will not be counted in the return value @@ -250,7 +255,9 @@ int libcmap_sprint_range(char *buf, const struct libcmap_range *range, const cha * @param endash Desired delimiter between the first and the last * codepoint, or `NULL` for the default (not ASCII) * @return The number of bytes in the string, excluding the - * terminating NUL byte + * terminating NUL byte, -1 on failure + * + * @throws Any error specified for snprintf(3) * * A NUL byte will added to the end of the string, but this byte * will not be counted in the return value @@ -268,6 +275,45 @@ int libcmap_sprint_range(char *buf, const struct libcmap_range *range, const cha */ int libcmap_snprint_range(char *buf, size_t bufsize, const struct libcmap_range *range, const char *endash); +/** + * Print a string representing a Unicode codepoint range + * + * @param fp The file to write to + * @param range The range to print a representation of + * @param endash Desired delimiter between the first and the last + * codepoint, or `NULL` for the default (not ASCII) + * @return The number of bytes in the string, -1 on failure + * + * @throws Any error specified for fprintf(3) + */ +int libcmap_fprint_range(FILE *fp, const struct libcmap_range *range, const char *endash); + +/** + * Print, to standard output, a string representing a + * Unicode codepoint range + * + * @param range The range to print a representation of + * @param endash Desired delimiter between the first and the last + * codepoint, or `NULL` for the default (not ASCII) + * @return The number of bytes in the string, -1 on failure + * + * @throws Any error specified for fprintf(3) + */ +int libcmap_print_range(const struct libcmap_range *range, const char *endash); + +/** + * Print a string representing a Unicode codepoint range + * + * @param fd The file descriptor + * @param range The range to print a representation of + * @param endash Desired delimiter between the first and the last + * codepoint, or `NULL` for the default (not ASCII) + * @return The number of bytes in the string, -1 on failure + * + * @throws Any error specified for dprintf(3) + */ +int libcmap_dprint_range(int fd, const struct libcmap_range *range, const char *endash); + #undef LIBCMAP_PURE_ #undef LIBCMAP_CONST_ diff --git a/libcmap_dprint_range.c b/libcmap_dprint_range.c new file mode 100644 index 0000000..7047871 --- /dev/null +++ b/libcmap_dprint_range.c @@ -0,0 +1,12 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" + + +int +libcmap_dprint_range(int fd, const struct libcmap_range *range, const char *endash) +{ + if (range->first == range->last) + return dprintf(fd, SINGLETON_RANGE_FMT, SINGLETON_RANGE_ARGS(range)); + else + return dprintf(fd, RANGE_FMT, RANGE_ARGS(range, endash)); +} diff --git a/libcmap_fprint_range.c b/libcmap_fprint_range.c new file mode 100644 index 0000000..35c68c5 --- /dev/null +++ b/libcmap_fprint_range.c @@ -0,0 +1,12 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" + + +int +libcmap_fprint_range(FILE *fp, const struct libcmap_range *range, const char *endash) +{ + if (range->first == range->last) + return fprintf(fp, SINGLETON_RANGE_FMT, SINGLETON_RANGE_ARGS(range)); + else + return fprintf(fp, RANGE_FMT, RANGE_ARGS(range, endash)); +} diff --git a/libcmap_print_range.c b/libcmap_print_range.c new file mode 100644 index 0000000..868549e --- /dev/null +++ b/libcmap_print_range.c @@ -0,0 +1,9 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" + + +int +libcmap_print_range(const struct libcmap_range *range, const char *endash) +{ + return libcmap_fprint_range(stdout, range, endash); +} |
