Add examples to encode/decode docs.

db4
Doug Coleman 2011-10-06 10:53:25 -07:00
parent e7e6191df9
commit 2402345794
1 changed files with 17 additions and 4 deletions

View File

@ -1,6 +1,7 @@
! Copyright (C) 2008 Daniel Ehrenberg.
! Copyright (C) 2008,2011 Daniel Ehrenberg, Doug Coleman.
! See http://factorcode.org/license.txt for BSD license.
USING: help.markup help.syntax byte-arrays strings ;
USING: byte-arrays help.markup help.syntax io.encodings.string
strings ;
IN: io.encodings.string
ARTICLE: "io.encodings.string" "Encoding and decoding strings"
@ -14,8 +15,20 @@ ARTICLE: "io.encodings.string" "Encoding and decoding strings"
HELP: decode
{ $values { "byte-array" byte-array } { "encoding" "an encoding descriptor" }
{ "string" string } }
{ $description "Decodes the byte array using the given encoding, outputting a string" } ;
{ $description "Converts an array of bytes to a string, interpreting that array of bytes as a string with the given encoding." }
{ $examples
{ $example """USING: io.encodings.string io.encodings.utf8 prettyprint ;
B{ 230 136 145 231 136 177 228 189 160 } utf8 decode ."""
""""我爱你""""
}
} ;
HELP: encode
{ $values { "string" string } { "encoding" "an encoding descriptor" } { "byte-array" byte-array } }
{ $description "Encodes the given string into a byte array with the given encoding." } ;
{ $description "Converts a string into a byte array, interpreting that string with the given encoding." }
{ $examples
{ $example """USING: io.encodings.string io.encodings.utf8 prettyprint ;
"我爱你" utf8 encode ."""
"B{ 230 136 145 231 136 177 228 189 160 }"
}
} ;