role Encoding
ErrorsCollection

role Encoding

Support for character encodings.

role Encoding { ... }

The Encoding role is implemented by classes that provide a character encoding, such as ASCII or UTF-8. Besides being used by the built-in character encodings, it may also be implemented by users to provide new encodings. Instances of objects doing this role are typically obtained using Encoding::Registry. For a list of supported encodings, see IO::Handle.

All methods provided by this role are stubs; they should be implemented by consumers of the role.

Methods

method name

method name(--> Str)

Abstract method that would return the primary name of the encoding.

method alternative-names

method alternative-names()

Abstract methods that should get a list of alternative names for the encoding.

method decoder

method decoder(*%options --> Encoding::Decoder)

Should get a character decoder instance for this encoding, configured with the provided options. Options vary by encoding. The built-in encodings all support translate-nl, which if True will translate \r\n into \n while decoding.

method encoder

method encoder(*%options --> Encoding::Encoder)

Gets a character encoder instance for this encoding, configured with the provided options. Options vary by encoding. The built-in encodings all support both replacement (either a Str replacement sequence or True to use a default replacement sequence for unencodable characters) and translate-nl (when set to True, turns \n into \r\n if the current platform is Windows).