[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
bug#14109: No code for 'bytevector->string' and 'string->bytevector'
From: |
Mark H Weaver |
Subject: |
bug#14109: No code for 'bytevector->string' and 'string->bytevector' |
Date: |
Mon, 01 Apr 2013 12:38:12 -0400 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) |
Ian Price <address@hidden> writes:
> Nikita Karetnikov <address@hidden> writes:
>
>> The mentioned functions are documented [1]. However, I'll get the
>> "Unbound variable" error if I try to import them:
>>
>> scheme@(guile-user)> ,use (rnrs io ports)
>> scheme@(guile-user)> string->bytevector
>> ;;; <unknown-location>: warning: possibly unbound variable
>> `string->bytevector'
>> ERROR: In procedure #<procedure 8ab8bc0 ()>:
>> ERROR: In procedure module-lookup: Unbound variable: string->bytevector
>
> Even if they were available, it wouldn't do you much good, because the
> general transcoder functionality on ports isn't implemented.
Indeed, it would be good to implement this at some point.
> For the moment, the (rnrs bytevectors) module has string->utf8,
> string->utf16, and string->utf32 which are implemented. Though, this
> doesn't let you specify eol-style or handling-mode.
There's also Andy's shiny new (ice-9 iconv) module, which provides more
general iconv functionality and will make its debut in 2.0.8. It
contains 'string->bytevector' and 'bytevector->string', though beware
that they're not the same as the R6RS procedures, despite their names.
These are documented in section 6.6.5.13 of the manual in stable-2.0,
but were not in the index due to some broken texinfo markup which I just
fixed.
Mark
-- Scheme Procedure: string->bytevector string encoding
[conversion-strategy]
Encode STRING as a sequence of bytes.
The string will be encoded in the character set specified by the
ENCODING string. If the string has characters that cannot be
represented in the encoding, by default this procedure raises an
`encoding-error'. Pass a CONVERSION-STRATEGY argument to specify
other behaviors.
The return value is a bytevector. *Note Bytevectors::, for more on
bytevectors. *Note Ports::, for more on character encodings and
conversion strategies.
-- Scheme Procedure: bytevector->string bytevector encoding
[conversion-strategy]
Decode BYTEVECTOR into a string.
The bytes will be decoded from the character set by the ENCODING
string. If the bytes do not form a valid encoding, by default this
procedure raises an `decoding-error'. As with
`string->bytevector', pass the optional CONVERSION-STRATEGY
argument to modify this behavior. *Note Ports::, for more on
character encodings and conversion strategies.
-- Scheme Procedure: call-with-output-encoded-string encoding proc
[conversion-strategy]
Like `call-with-output-string', but instead of returning a string,
returns a encoding of the string according to ENCODING, as a
bytevector. This procedure can be more efficient than collecting a
string and then converting it via `string->bytevector'.