Factor Documentation
|
Home
|
Glossary
|
Search
factorcode.org
encode ( string encoding -- byte-array )
Factor documentation
>
Factor handbook
>
Input and output
>
I/O encodings
>
Encoding and decoding strings
Next:
decode ( byte-array encoding -- string )
Vocabulary
io.encodings.string
Inputs and outputs
string
a
string
encoding
an encoding descriptor
byte-array
a
byte-array
Word description
Converts a string into a byte array, interpreting that string with the given encoding.
Examples
USING: io.encodings.string io.encodings.utf8 prettyprint ; "我爱你" utf8 encode .
B{ 230 136 145 231 136 177 228 189 160 }
Definition
USING:
byte-vectors
io
io.encodings
io.encodings.binary
kernel
locals
sequences
;
IN:
io.encodings.string
::
encode
( string encoding -- byte-array )
encoding
binary
eq?
[
string
]
[
string
length
encoding
guess-encoded-length
<byte-vector>
:>
vec string vec encoding
<encoder>
stream-write
vec
B{
}
like
]
if
;
inline