5.28. kink/charset/CHARSET¶
Provides charset type, which represents character encoding.
5.28.1. CHARSET.for(Name ...[$config={}])¶
`for` tries to find a charset with the specified `Name`, from the charset repository provided by the runtime.
Config methods:
• C.on_success($success): default = VAL.identity.
• C.on_error($error): default = a fun which raises an exception.
If the specified charset is found, `for` tail-calls $success with the charset.
If the specified charset is not found, `for` tail-calls $error with no args.
Preconditions
• `Name` must be a `str`.
• $success must be a fun which takes a `charset` val.
• $error must be a fun which takes no arg.
5.28.2. type charset¶
A charset is an encoding system of a string by a byte sequence (bin).
5.28.2.1. Charset.name¶
Charset.name returns the name of the charset.
There is no guarantee that the name specfied to CHARSET.for is equal to the result of the method.
For example:
:CHARSET.require_from('kink/charset/')
:Utf16 <- CHARSET.for('utf16')
stdout.print_line(Utf16.name.repr) # => "UTF-16"
5.28.2.2. Charset.str_to_bin(Str)¶
“str_to_bin” converts the Str to a bin.
Precondition:
• Str must be a str.
Example:
:CHARSET.require_from('kink/charset/')
:Bin <- CHARSET.utf8.str_to_bin('Foo')
stdout.print_line(Bin.repr) # => BIN.of(0x46 0x6f 0x6f)
If a portion of the str cannot be converted by the charset, it is replaced by the replacement sequence default to the charset.
5.28.2.3. Charset.bin_to_str(Bin)¶
“bin_to_str” converts the Bin to a str.
Precondition:
• Bin must be a bin.
Example:
:CHARSET.require_from('kink/charset/')
:BIN.require_from('kink/')
:Str <- CHARSET.utf8.bin_to_str(BIN.of(0x46 0x6f 0x6f))
stdout.print_line(Str.repr) # => "Foo"
If a portion of the bin cannot be converted by the charset, it is replaced by the replacement sequence default to the charset.
5.28.2.4. X == Y, X != Y¶
Two charsets are equal when the names are equal.
5.28.2.5. Charset.repr¶
Charset.repr returns a str which represents the charset, such as "(charset UTF-16)".
5.28.3. CHARSET.is?(Val)¶
CHARSET.is? returns whether Val is a charset.
5.28.4. CHARSET.utf8¶
CHARSET.utf8 returns UTF-8 charset.
5.28.5. CHARSET.ascii¶
CHARSET.ascii returns ASCII charset.
5.28.6. CHARSET.default¶
CHARSET.default returns the charset default to the runtime.