guile-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Converting a part of byte vector to UTF-8 string


From: Panicz Maciej Godek
Subject: Converting a part of byte vector to UTF-8 string
Date: Tue, 14 Jan 2014 00:17:33 +0100

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

reply via email to

[Prev in Thread] Current Thread [Next in Thread]