diff options
author | Jacob Moody <moody@posixcafe.org> | 2023-03-27 03:45:32 +0000 |
---|---|---|
committer | Jacob Moody <moody@posixcafe.org> | 2023-03-27 03:45:32 +0000 |
commit | d2753b4d5f877b14426b55554945863364b0fbbf (patch) | |
tree | e9e4adb115c54c6ee14062d7a109fd9e1e49f72a /sys/src/cmd/tcs/utf.c | |
parent | e0d114547c7f54ebd32b69f922e7d6538a63636e (diff) |
tcs: add nfc and nfd output formats
Diffstat (limited to 'sys/src/cmd/tcs/utf.c')
-rw-r--r-- | sys/src/cmd/tcs/utf.c | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/sys/src/cmd/tcs/utf.c b/sys/src/cmd/tcs/utf.c index 16438daf5..40ef65b2d 100644 --- a/sys/src/cmd/tcs/utf.c +++ b/sys/src/cmd/tcs/utf.c @@ -69,6 +69,46 @@ utf_out(Rune *base, int n, long *) } void +utfnorm_out(Rune *base, int n, int (*fn)(Rune*,Rune*,int)) +{ + static Rune rbuf[32]; + static int nremain = 0; + Rune src[N + 1 + nelem(rbuf)]; + Rune dst[N + 1 + nelem(rbuf)]; + Rune *p, *p2, *e; + int i; + + e = base+n; + for(i = 0; i < nremain; i++,n++) + src[i] = rbuf[i]; + nremain = 0; + for(p2 = p = base; n > 0;){ + p2 = fullrunenorm(p, n); + if(p == p2) + break; + n -= p2-p; + for(;p < p2; p++) + src[i++] = *p; + } + src[i] = 0; + utf_out(dst, fn(dst, src, sizeof dst), nil); + for(; p2 < e; p2++) + rbuf[nremain++] = *p2; +} + +void +utfnfc_out(Rune *base, int n, long *) +{ + utfnorm_out(base, n, runecomp); +} + +void +utfnfd_out(Rune *base, int n, long *) +{ + utfnorm_out(base, n, runedecomp); +} + +void isoutf_in(int fd, long *, struct convert *out) { char buf[N]; |