diff options
| author | Mattias Andrée <m@maandree.se> | 2026-01-25 10:48:36 +0100 |
|---|---|---|
| committer | Mattias Andrée <m@maandree.se> | 2026-01-25 10:48:36 +0100 |
| commit | 931bbb77e11f0403f51fe1e9c18ef4f5e16a3fcf (patch) | |
| tree | 24e2ecb39218678ecf577108af9938962985151a | |
| parent | Add braille (diff) | |
| download | charconv-931bbb77e11f0403f51fe1e9c18ef4f5e16a3fcf.tar.gz charconv-931bbb77e11f0403f51fe1e9c18ef4f5e16a3fcf.tar.bz2 charconv-931bbb77e11f0403f51fe1e9c18ef4f5e16a3fcf.tar.xz | |
Add lisu
Signed-off-by: Mattias Andrée <m@maandree.se>
Diffstat (limited to '')
| -rw-r--r-- | Makefile | 6 | ||||
| -rw-r--r-- | convert-to-lisu.c | 18 | ||||
| -rw-r--r-- | libcharconv.h | 32 | ||||
| -rw-r--r-- | libcharconv_latin.c | 13 | ||||
| -rw-r--r-- | libcharconv_lisu.c | 115 |
5 files changed, 182 insertions, 2 deletions
@@ -53,7 +53,8 @@ BIN =\ convert-to-clock-faces\ convert-to-ocr\ convert-to-crop-marks\ - convert-to-braille + convert-to-braille\ + convert-to-lisu LIBOBJ =\ libcharconv_decode_utf8_.o\ @@ -95,7 +96,8 @@ LIBOBJ =\ libcharconv_clock_faces.o\ libcharconv_ocr.o\ libcharconv_crop_marks.o\ - libcharconv_braille.o + libcharconv_braille.o\ + libcharconv_lisu.o LOBJ = $(LIBOBJ:.o=.lo) diff --git a/convert-to-lisu.c b/convert-to-lisu.c new file mode 100644 index 0000000..3a8320a --- /dev/null +++ b/convert-to-lisu.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" + +USAGE(""); + + +int +main(int argc, char *argv[]) +{ + ARGBEGIN { + default: + usage(); + } ARGEND; + if (argc) + usage(); + + return convert(&libcharconv_lisu); +} diff --git a/libcharconv.h b/libcharconv.h index 613ef1b..9c77b1f 100644 --- a/libcharconv.h +++ b/libcharconv.h @@ -1313,4 +1313,36 @@ enum libcharconv_result libcharconv_crop_marks(const char *s, size_t slen, size_ enum libcharconv_result libcharconv_braille(const char *s, size_t slen, size_t *n, uint_least32_t *cp, size_t *ncp); +/** + * Preforms convertion from Latin to Lisu + * + * @param s Text to convert + * @param slen The number of bytes available in `s` + * @param n Output parameter for the number of consumed bytes + * @param cp Output buffer for the codepoints + * @param ncp Input parameter for the number of codepoints that + * fit in `cp`, and output parameter for the number + * of output codepoints (if it exceeds the original + * value of `ncp`, a larger buffer is needed) + * @return LIBCHARCONV_NO_CONVERT: + * `*n` is the number of bytes from the beginning + * of `s` that cannot be converted + * LIBCHARCONV_CONVERTED: + * `*n` is the number of bytes from the beginning + * of `s` that was converted to a codepoint which + * is stored in `*cp` + * LIBCHARCONV_INDETERMINATE: + * If all text has been input, no more can be + * converted, otherwise more of the text most + * be made available before the function can + * determine whether the beginning of `s` can be + * converted or what it should be converted to + * LIBCHARCONV_CONVERT_IF_END: + * As LIBCHARCONV_CONVERTED the entire text has + * been input, as LIBCHARCONV_INDETERMINATE + * otherwise + */ +enum libcharconv_result libcharconv_lisu(const char *s, size_t slen, size_t *n, uint_least32_t *cp, size_t *ncp); + + #endif diff --git a/libcharconv_latin.c b/libcharconv_latin.c index 5124c53..9dc81cf 100644 --- a/libcharconv_latin.c +++ b/libcharconv_latin.c @@ -382,7 +382,15 @@ libcharconv_latin(const char *s, size_t slen, size_t *n, uint_least32_t *cp, siz *ncp = i; return ret; + } else if (UINT32_C(0xA4D0) <= c && c <= UINT32_C(0xA4FF)) { + /* lisu */ + c1 = "bpPdtYgkKjcCzfFmnlsrRVvhGJwxyBaAeEiouULD., ;:-="[c - UINT32_C(0xA4D0)]; + if (c1 == ' ') + goto use_switch; + goto conv1; + } else { + use_switch: switch (c) { /* shogi */ case UINT32_C(0x2616): c = (uint_least32_t)'w'; goto conv; @@ -529,6 +537,11 @@ libcharconv_latin(const char *s, size_t slen, size_t *n, uint_least32_t *cp, siz case UINT32_C(0x230E): c1 = '|'; c2 = '_'; goto conv2; case UINT32_C(0x230F): c1 = '_'; c2 = '|'; goto conv2; + /* lisu */ + case UINT32_C(0xA4FB): c1 = '.'; c2 = ','; goto conv2; + case UINT32_C(0xA4FA): c1 = '.'; c2 = '.'; goto conv2; + case UINT32_C(0x11FB0): c1 = 'Y'; goto conv1; + default: no_match: *n += clen; diff --git a/libcharconv_lisu.c b/libcharconv_lisu.c new file mode 100644 index 0000000..2a0293a --- /dev/null +++ b/libcharconv_lisu.c @@ -0,0 +1,115 @@ +/* See LICENSE file for copyright and license details. */ +#include "lib-common.h" + + +static struct { + unsigned char cp_low; + char latin; +} lisu[] = { + {0xEE, 'a'}, + {0xD0, 'b'}, + {0xDA, 'c'}, + {0xD3, 'd'}, + {0xF0, 'e'}, + {0xDD, 'f'}, + {0xD6, 'g'}, + {0xE7, 'h'}, + {0xF2, 'i'}, + {0xD9, 'j'}, + {0xD7, 'k'}, + {0xE1, 'l'}, + {0xDF, 'm'}, + {0xE0, 'n'}, + {0xF3, 'o'}, + {0xD1, 'p'}, + {0xE3, 'r'}, + {0xE2, 's'}, + {0xD4, 't'}, + {0xF4, 'u'}, + {0xE6, 'v'}, + {0xEA, 'w'}, + {0xEB, 'x'}, + {0xEC, 'y'}, + {0xDC, 'z'}, + {0xEF, 'A'}, + {0xED, 'B'}, + {0xDB, 'C'}, + {0xF7, 'D'}, + {0xF1, 'E'}, + {0xDE, 'F'}, + {0xE8, 'G'}, + {0xE7, 'H'}, /* symmetry */ + {0xF2, 'I'}, /* symmetry */ + {0xE9, 'J'}, + {0xD8, 'K'}, + {0xF6, 'L'}, + {0xEA, 'M'}, /* W */ + {0xE0, 'N'}, /* symmetry */ + {0xF3, 'O'}, /* symmetry */ + {0xD2, 'P'}, + {0xE4, 'R'}, + {0xE2, 'S'}, /* symmetry */ + {0xD5, 'Y'}, + {0xF5, 'U'}, + {0xE5, 'V'}, + {0xDF, 'W'}, /* M */ + {0xEB, 'X'}, /* symmetry */ + {0xDC, 'Z'}, /* symmetry */ + {0xFE, '-'}, + {0xFF, '='}, + {0xFD, ':'}, + {0xFC, ';'}, + {0xF9, ','} +}; + + +enum libcharconv_result +libcharconv_lisu(const char *s, size_t slen, size_t *n, uint_least32_t *cp, size_t *ncp) +{ + uint_least32_t c; + size_t i; + *n = 0; + for (; slen--; s++) { + if (*s == 'Y') { + c = UINT32_C(0x11FB0); + goto conv; + } else if (*s == '.') { + if (*n) + goto no_conv; + if (*ncp) + *cp = UINT32_C(0xA4F8); + *n += 1u; + *ncp = 1u; + if (!slen--) + return LIBCHARCONV_CONVERT_IF_END; + if (s[1] == '.') { + if (*ncp) + *cp = UINT32_C(0xA4FA); + *n += 1u; + } else if (s[1] == ',') { + if (*ncp) + *cp = UINT32_C(0xA4FB); + *n += 1u; + } + return LIBCHARCONV_CONVERTED; + } else { + for (i = 0u; i < sizeof(lisu) / sizeof(*lisu); i++) + if (*s == lisu[i].latin) + goto conv_listed; + *n += 1u; + } + } +no_conv: + return LIBCHARCONV_NO_CONVERT; + +conv_listed: + c = (uint_least32_t)(UINT32_C(0xA400) | lisu[i].cp_low); +conv: + if (*n) + goto no_conv; + if (*ncp) + *cp = c; + *n += 1u; + *ncp = 1u; + return LIBCHARCONV_CONVERTED; +} |
