9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
* [9fans] s_putc and Runes
@ 2007-02-05  2:41 Joel Salomon
  2007-02-05  3:25 ` Russ Cox
  0 siblings, 1 reply; 8+ messages in thread
From: Joel Salomon @ 2007-02-05  2:41 UTC (permalink / raw)
  To: 9fans

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



^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2007-02-06  6:23 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-02-05  2:41 [9fans] s_putc and Runes Joel Salomon
2007-02-05  3:25 ` Russ Cox
2007-02-05  9:41   ` Bruce Ellis
2007-02-05 12:25   ` erik quanstrom
2007-02-05 19:52   ` Joel Salomon
2007-02-05 21:42     ` Paul Lalonde
2007-02-05 23:57       ` Joel Salomon
2007-02-06  6:23         ` Bruce Ellis

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).