9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
From: Joel Salomon <JoelCSalomon@Gmail.com>
To: 9fans@cse.psu.edu
Subject: [9fans] s_putc and Runes
Date: Sun,  4 Feb 2007 21:41:40 -0500	[thread overview]
Message-ID: <fc7d8c1bc0687a5996c00867bfbda23b@plan9.jp> (raw)

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	other threads:[~2007-02-05  2:41 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-02-05  2:41 Joel Salomon [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=fc7d8c1bc0687a5996c00867bfbda23b@plan9.jp \
    --to=joelcsalomon@gmail.com \
    --cc=9fans@cse.psu.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).