morpheus-base

morpheus base system
git clone git://git.2f30.org/morpheus-base
Log | Files | Refs

chartorunearr.c (587B)


      1 /* See LICENSE file for copyright and license details. */
      2 #include <stdlib.h>
      3 #include <string.h>
      4 
      5 #include "../util.h"
      6 #include "../utf.h"
      7 
      8 int
      9 chartorunearr(const char *str, Rune **r)
     10 {
     11 	size_t len = strlen(str), rlen, roff, ret = 1, i;
     12 	Rune s;
     13 
     14 	for (rlen = 0, roff = 0; roff < len && ret; rlen++) {
     15 		ret = charntorune(&s, str + roff, MAX(UTFmax, len - roff));
     16 		roff += ret;
     17 	}
     18 
     19 	*r = emalloc(rlen * sizeof(Rune) + 1);
     20 	(*r)[rlen] = 0;
     21 
     22 	for (i = 0, roff = 0; roff < len && i < rlen; i++) {
     23 		roff += charntorune(&(*r)[i], str + roff, MAX(UTFmax, len - roff));
     24 	}
     25 
     26 	return rlen;
     27 }