I’ve been appending single Runes to Strings, so I checked
/n/sources/plan9/sys/src/libString/s_putc.c to see if it handled
Runes.  Is there a reason it doesn’t, or that s_putrune doesn’t exist?

Here’s my implementation, using none of String internals:

void
s_putrune(String *s, Rune r)
{
        char rbuf[UTFmax];
        s_nappend(s, rbuf, runetochar(rbuf, &r));
}

or as part of the library (where I’m a bit shakier on the semantics):

void
s_putrune(String *s, Rune r)
{
        char rbuf[UTFmax];
        int n;
        if(s->ref > 1)
                sysfatal("can't s_putc a shared string");
        if (s->ptr >= s->end - n=runelen(r))
                s_grow(s, n+1);
        (s->ptr) += runetochar(s->ptr, &r);
}

--Joel

Reply via email to