6.56. kink/io/INPUT_SCANNER

Provides a `scanner` implementation wrapping `input`.

6.56.1. INPUT_SCANNER.new(Input Charset ...[$config={}])

`new` makes a `scanner` which also support `input` methods. The created scanner reads bytes from `Input` and converts them to strings using `Charset`. Methods of `input` type are delegated to `Input`.

Config method:

• C.replace_conversion_error

When `scan_line` or `scan` methods detect malformed byte sequence or a character which cannot be mapped to Unicode, those methods tail-call $error by default. If C.replace_conversion_error is called, `scan` and `scan_line` insert replacement character sequence into the string instead of calling $error.

Preconditions

`Input` must be `input` type.

`Charset` must be `charset` type.

Example

:INPUT_SCANNER.require_from('kink/io/')
:BIN_INPUT.require_from('kink/io/')
:BIN.require_from('kink/')
:CHARSET.require_from('kink/')

:In <- BIN_INPUT.new(BIN.of(102 111 111 10))
:S <- INPUT_SCANNER.new(In CHARSET.utf8)

# the result suppors input
stdout.print_line(S.read(1).repr) # => (bin 0x66)

# the result suppors scanner
stdout.print_line(S.scan_line.repr) # => "oo\n"