Add utf8-pointer->string procedure.
authorDavid Thompson <dthompson2@worcester.edu>
Sun, 13 Jul 2014 13:09:25 +0000 (09:09 -0400)
committerDavid Thompson <dthompson2@worcester.edu>
Sun, 13 Jul 2014 13:09:25 +0000 (09:09 -0400)
* tox.scm (wrap-tox): Use it.
* tox/util.scm (utf8-pointer->string): New procedure.

tox.scm
tox/util.scm

diff --git a/tox.scm b/tox.scm
index f987105..7f1d511 100644 (file)
--- a/tox.scm
+++ b/tox.scm
@@ -131,7 +131,7 @@ transcoding the hexadecimal string ADDRESS."
         (run-hook (tox-message-hook tox)
                   tox
                   friend-number
-                  (utf8->string (pointer->bytevector message length))))
+                  (utf8-pointer->string message length)))
       (list '* int32 '* uint16 '*))
      %null-pointer)
     tox))
index f1fd943..d43d9eb 100644 (file)
 (define-module (tox util)
   #:use-module (ice-9 format)
   #:use-module (rnrs bytevectors)
+  #:use-module (system foreign)
   #:export (boolean->number
             one?
             define-enumeration
             hex-string->bytevector bytevector->hex-string
+            utf8-pointer->string
             bytevector-slice
             false-if-negative false-if-zero
             htons))
@@ -79,6 +81,11 @@ of the contents of the bytevector BV."
            (format #f "~x" n))
          (bytevector->u8-list bv)))))
 
+(define (utf8-pointer->string pointer length)
+  "Return a newly allocated string containing the characters within the UTF-8
+encoded foreign POINTER of LENGTH bytes."
+  (utf8->string (pointer->bytevector pointer length)))
+
 (define (bytevector-slice bv begin end)
   "Return a newly allocated bytevector containing the contents of BV from the
 index BEGIN, inclusive, to the index END, exclusive."