From: Panicz Maciej Godek <godek.maciek@gmail.com>
To: "guile-user@gnu.org" <guile-user@gnu.org>
Subject: Converting a part of byte vector to UTF-8 string
Date: Tue, 14 Jan 2014 00:17:33 +0100 [thread overview]
Message-ID: <CAMFYt2a77QRanD=p9viKsZLHpDLAvnB453r5QTdv3f699b-KTw@mail.gmail.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 724 bytes --]
Hi,
what would be the best way to convert
only a part of a byte vector (interpreted as
UTF-8) to string?
Let's say that I have a big buffer,
(define buffer (make-u8vector 1024))
which contains some message
(define n (recv! sock buffer))
I'd like to get only the first n bytes of buffer.
I initially thought that this would do:
(utf8->string (make-shared-array buffer list `(0 ,(- n 1))))
(the utf8->string comes from ((rnrs) #:version (6)) module)
However, it failed (having expected byte-vector).
Another option would be to use
(substring (utf8->string buffer 0 n))
This one works, but according to the manual, the
string is "newly allocated", so it's unnecessary overhead.
What would be the best solution?
TIA
M
[-- Attachment #2: Type: text/html, Size: 1115 bytes --]
next reply other threads:[~2014-01-13 23:17 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-01-13 23:17 Panicz Maciej Godek [this message]
2014-01-15 4:59 ` Converting a part of byte vector to UTF-8 string Nala Ginrut
2014-01-15 15:27 ` Panicz Maciej Godek
2014-01-15 18:29 ` Mark H Weaver
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='CAMFYt2a77QRanD=p9viKsZLHpDLAvnB453r5QTdv3f699b-KTw@mail.gmail.com' \
--to=godek.maciek@gmail.com \
--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).