<commit_before>! Copyright (C) 2008 <NAME>.
! See http://factorcode.org/license.txt for BSD license.
USING: help.markup help.syntax byte-arrays strings ;
IN: io.encodings.string

ARTICLE: "io.encodings.string" "Encoding and decoding strings"
"Strings can be encoded or decoded to and from byte arrays through an encoding by passing "
{ $link "encodings-descriptors" } " to the following words:"
{ $subsections
    encode
    decode
} ;

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" } ;

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." } ;<commit_msg>Add examples to encode/decode docs.<commit_after>! Copyright (C) 2008,2011 <NAME>, <NAME>.
! See http://factorcode.org/license.txt for BSD license.
USING: byte-arrays help.markup help.syntax io.encodings.string
strings ;
IN: io.encodings.string

ARTICLE: "io.encodings.string" "Encoding and decoding strings"
"Strings can be encoded or decoded to and from byte arrays through an encoding by passing "
{ $link "encodings-descriptors" } " to the following words:"
{ $subsections
    encode
    decode
} ;

HELP: decode
{ $values { "byte-array" byte-array } { "encoding" "an encoding descriptor" }
    { "string" 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 "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 }"
    }
} ;
{'fraction_non_alphanumeric': 0.12297734627831715, 'fraction_numerical': 0.032362459546925564, 'mean_word_length': 4.115839243498818, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2225092', 'n_tokens_mistral': 741, 'n_tokens_neox': 664, 'n_words': 245}