Hi FRIGN, It's been a while since I posted to this list. I do still maintain libutf, though -- glad to hear it's still being of use.
It sounds like it might be a good idea to add these to the library. However, I have some simplification suggestions, especially to avoid memory allocation inside libutf. I've attached a file illustrating the functions as I think they should be (albeit untested). Your 'chartorunearr' could, in this case, be implemented like so: > Rune *p = emalloc((utflen(s) + 1) * sizeof *p); > utftorunestr(s, p); Does this seem alright to you? I don't have strong opinions on the 'where to put them' question. I suppose we could split out every function into its own file, as others have suggested. On the other hand, if 'utftorunestr' were to go in a larger file of functions then I would actually suggest a runestr.c, which doesn't exist yet but may as well; see runestrcat(3). Thanks, cls
/* See LICENSE file for copyright and license details. */ #include <stdio.h> #include "utf.h" int utftorunestr(const char *s, Rune *p) { int i, n; for(i = 0; (n = chartorune(&p[i], s)), p[i] != 0; i++) s += n; return i; } int fgetrune(Rune *p, FILE *fp) { char buf[UTFmax]; int c, i = 0; do { if((c = fgetc(fp)) == EOF) break; buf[i++] = c; } while(!fullrune(buf, i)); if(i == 0) return EOF; return charntorune(p, buf, i); } int fputrune(const Rune *p, FILE *fp) { char buf[UTFmax]; return fwrite(buf, runetochar(buf, p), 1, fp); }