unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
* Converting a part of byte vector to UTF-8 string
@ 2014-01-13 23:17 Panicz Maciej Godek
  2014-01-15  4:59 ` Nala Ginrut
  0 siblings, 1 reply; 4+ messages in thread
From: Panicz Maciej Godek @ 2014-01-13 23:17 UTC (permalink / raw)
  To: guile-user@gnu.org

[-- 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 --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2014-01-15 18:29 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-01-13 23:17 Converting a part of byte vector to UTF-8 string Panicz Maciej Godek
2014-01-15  4:59 ` Nala Ginrut
2014-01-15 15:27   ` Panicz Maciej Godek
2014-01-15 18:29     ` Mark H Weaver

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).