unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
From: Jean Abou Samra <jean@abou-samra.fr>
To: Guile User <guile-user@gnu.org>
Subject: UTF16 encoding adds BOM everywhere?
Date: Thu, 14 Jul 2022 21:16:44 +0200	[thread overview]
Message-ID: <63f03f91-58d8-c247-2d2a-78848c2e5ca9@abou-samra.fr> (raw)

Hi,

With this code:

(let ((p (open-output-file "x.txt")))
   (set-port-encoding! p "UTF16")
   (display "ABC" p)
   (close-port p))

the sequence of bytes in the output file x.txt is

['FF', 'FE', '41', '0', 'FF', 'FE', '42', '0', 'FF', 'FE', '43', '0']

FFE is a little-endian Byte Order Mark (BOM), fine.
But why is Guile adding it before every character
instead of just at the beginning of the string?
Is that expected?

This is a curiosity question; since what I want is
big endian, I just used "UTF16BE", which outputs
big endian, and doesn't add the BOM -- I can then just
add a BOM manually. Still, I'm puzzled by this
behavior.

Thanks,
Jean




             reply	other threads:[~2022-07-14 19:16 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-14 19:16 Jean Abou Samra [this message]
2022-07-20 20:42 ` UTF16 encoding adds BOM everywhere? Mark H Weaver
2022-07-20 21:45   ` Jean Abou Samra

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=63f03f91-58d8-c247-2d2a-78848c2e5ca9@abou-samra.fr \
    --to=jean@abou-samra.fr \
    --cc=guile-user@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).