From: ludo@gnu.org (Ludovic Courtès)
To: David Kastrup <dak@gnu.org>
Cc: 18520@debbugs.gnu.org
Subject: bug#18520: string ports should not have an encoding
Date: Tue, 23 Sep 2014 18:01:28 +0200 [thread overview]
Message-ID: <87tx3yfhrb.fsf@gnu.org> (raw)
In-Reply-To: <87d2amjxq9.fsf@fencepost.gnu.org> (David Kastrup's message of "Tue, 23 Sep 2014 15:02:54 +0200")
David Kastrup <dak@gnu.org> skribis:
> They result in code like
>
> // we do our own utf8 encoding and verification in the parser, so we
> // use the no-conversion equivalent of latin1
> SCM str = scm_from_latin1_string (c_str ());
> scm_dynwind_begin ((scm_t_dynwind_flags)0);
> // Why doesn't scm_set_port_encoding_x work here?
> scm_dynwind_fluid (ly_lily_module_constant ("%default-port-encoding"), SCM_BOOL_F);
> str_port_ = scm_open_input_string (str);
> scm_dynwind_end ();
> scm_set_port_filename_x (str_port_, ly_string2scm (name_));
> }
So here ‘c_str’ returns a char * that is a UTF-8-encoded string, right?
In that case, it should be enough to do:
/* Get a Scheme string from its UTF-8 representation. */
str = scm_from_utf8_string (c_str ());
/* Create an input string port. ‘read-char’ & co. will return each
character from STR, one at a time. */
str_port = open_input_string (str);
scm_set_port_filename_x (str_port, file);
As long as textual I/O procedures are used on ‘str_port’, there’s no
need to worry about its encoding.
Now, to be able to use ‘ftell’ and assume it returns the position as a
number of bytes in the UTF-8 sequence, something like this should work
(for 2.0; for 2.2 nothing special is needed):
/* Get a Scheme string from its UTF-8 representation. */
str = scm_from_utf8_string (c_str ());
scm_dynwind_begin (0);
/* Make sure the following string port uses UTF-8 as the internal
encoding of its buffer. */
scm_dynwind_fluid (scm_public_ref ("guile", "%default-port-encoding"),
scm_from_latin1_string ("UTF-8"));
/* Create an input string port. ‘read-char’ & co. will return each
character from STR, one at a time. */
str_port = open_input_string (str);
scm_dynwind_end ();
scm_set_port_filename_x (str_port, file);
Does this help for LilyPond?
Ludo’.
next prev parent reply other threads:[~2014-09-23 16:01 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-09-21 23:34 bug#18520: string ports should not have an encoding David Kastrup
2014-09-22 11:54 ` Ludovic Courtès
2014-09-22 13:09 ` David Kastrup
2014-09-22 12:21 ` Ludovic Courtès
2014-09-22 13:34 ` David Kastrup
2014-09-22 17:08 ` Ludovic Courtès
2014-09-22 17:20 ` David Kastrup
2014-09-22 20:39 ` Ludovic Courtès
2014-09-22 22:12 ` David Kastrup
2014-09-23 8:25 ` Ludovic Courtès
2014-09-23 9:00 ` David Kastrup
2014-09-23 9:45 ` Ludovic Courtès
2014-09-23 11:54 ` David Kastrup
2014-09-23 12:13 ` Ludovic Courtès
2014-09-23 13:02 ` David Kastrup
2014-09-23 16:01 ` Ludovic Courtès [this message]
2014-09-23 16:21 ` David Kastrup
2014-09-23 19:33 ` Ludovic Courtès
2014-09-24 5:30 ` Mark H Weaver
2014-09-24 12:00 ` David Kastrup
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
List information: https://www.gnu.org/software/guile/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87tx3yfhrb.fsf@gnu.org \
--to=ludo@gnu.org \
--cc=18520@debbugs.gnu.org \
--cc=dak@gnu.org \
/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 read-only IMAP folder(s) and NNTP newsgroup(s).