From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Panicz Maciej Godek Newsgroups: gmane.lisp.guile.user Subject: Converting a part of byte vector to UTF-8 string Date: Tue, 14 Jan 2014 00:17:33 +0100 Message-ID: NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/alternative; boundary=047d7bfd030ccf60dc04efe24737 X-Trace: ger.gmane.org 1389655066 6844 80.91.229.3 (13 Jan 2014 23:17:46 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 13 Jan 2014 23:17:46 +0000 (UTC) To: "guile-user@gnu.org" Original-X-From: guile-user-bounces+guile-user=m.gmane.org@gnu.org Tue Jan 14 00:17:54 2014 Return-path: Envelope-to: guile-user@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1W2qlU-0003lr-55 for guile-user@m.gmane.org; Tue, 14 Jan 2014 00:17:52 +0100 Original-Received: from localhost ([::1]:45568 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1W2qlT-0000Vj-O3 for guile-user@m.gmane.org; Mon, 13 Jan 2014 18:17:51 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:37950) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1W2qlF-0000Td-Qn for guile-user@gnu.org; Mon, 13 Jan 2014 18:17:38 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1W2qlD-00049J-48 for guile-user@gnu.org; Mon, 13 Jan 2014 18:17:37 -0500 Original-Received: from mail-wi0-x236.google.com ([2a00:1450:400c:c05::236]:54957) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1W2qlC-00048u-Tr for guile-user@gnu.org; Mon, 13 Jan 2014 18:17:35 -0500 Original-Received: by mail-wi0-f182.google.com with SMTP id ex4so6829wid.3 for ; Mon, 13 Jan 2014 15:17:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:date:message-id:subject:from:to:content-type; bh=vqr3NQKEZNt+u5BZxKmU3U2s9UTnImb4/ni4KxDgfzA=; b=R6YPgrSiHU4I38XJAfjY/T/J4TEDOxPeL2TMpMcHzp7AR2VxAYvKx3k8uamHWS82cw 7Piz6adQBLgNa30e1zJPQ9OtA4PBXnQUGm87/dSCEcxgAvlXn1x0WcuS3hUqNOwEcgV1 h0ppM/RJmPCphk0PnI13kgPk94XYft7OQ4pxikF3+mJKCjjZn46a8wjDVVioFKO8Z/q3 GvrASlKTQeqg2RcDdWf6Em65uCScSDz0B33B8v9ZXvuUqB7lcVZfzOlyKCUz/+HRtVEh xsmD2ZOkEHV6mwA6l72rinmKNUoHiw2UjUqMwxGeIGFexGmtSOmY05VgNvs+jKX0qLRo avfA== X-Received: by 10.194.92.109 with SMTP id cl13mr24406798wjb.13.1389655053261; Mon, 13 Jan 2014 15:17:33 -0800 (PST) Original-Received: by 10.194.178.134 with HTTP; Mon, 13 Jan 2014 15:17:33 -0800 (PST) X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2a00:1450:400c:c05::236 X-BeenThere: guile-user@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: General Guile related discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-user-bounces+guile-user=m.gmane.org@gnu.org Original-Sender: guile-user-bounces+guile-user=m.gmane.org@gnu.org Xref: news.gmane.org gmane.lisp.guile.user:10990 Archived-At: --047d7bfd030ccf60dc04efe24737 Content-Type: text/plain; charset=ISO-8859-1 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 --047d7bfd030ccf60dc04efe24737 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable
Hi,
what would be the best way to convert
on= ly a part of a byte vector (interpreted as
UTF-8) to string?

Let's say that I have a big buffer,
(def= ine 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 e= xpected byte-vector).

Another option would be to use
(substring (ut= f8->string buffer 0 n))

This one works, but acc= ording to the manual, the
string is "newly allocated", = so it's unnecessary overhead.

What would be the best solution?

TIA
M
--047d7bfd030ccf60dc04efe24737--