enum

Mica::Core::Encoding

Inherits Enum < Comparable < Value < Object

The character encodings Mica decodes in Crystal (no iconv).

UTF-8 is read in place; the others go through Core::Transcoder, which turns them into UTF-8 for the format's scanner.

Constants

UTF8 = 0
UTF16LE = 1
UTF16BE = 2
UTF32LE = 3
UTF32BE = 4
ISO8859_1 = 5
USASCII = 6

Class methods

from_byte_order_mark(bytes : Bytes) : Tuple(Encoding, Int32) | Nil

Returns the encoding a byte order mark announces at the start of bytes and the mark's size, or nil. UTF-32LE wins over UTF-16LE when the four bytes FF FE 00 00 are present.

Mica::Core::Encoding.from_byte_order_mark(Bytes[0xFE, 0xFF, 0, 0x3C]) # => {Mica::Core::Encoding::UTF16BE, 2}
Source
from_label(name : String) : Encoding | Nil

Looks up an encoding by name, ignoring ASCII case. Accepts the IANA names and common aliases. "UTF-16" and "UTF-32" (no byte order) map to the big-endian form, which is what they mean without a byte order mark; formats that read a mark compare it separately.

Source

Instance methods

iso8859_1?

Returns true if this enum value equals ISO8859_1

Source
label

Returns the canonical name ("UTF-8", "UTF-16LE", ...).

Source
transcoded?

Returns true when the encoding must go through a Transcoder.

Source
usascii?

Returns true if this enum value equals USASCII

Source
utf16?

Returns true for the UTF-16 forms.

Source
utf16_be?

Returns true if this enum value equals UTF16BE

Source
utf16_le?

Returns true if this enum value equals UTF16LE

Source
utf32?

Returns true for the UTF-32 forms.

Source
utf32_be?

Returns true if this enum value equals UTF32BE

Source
utf32_le?

Returns true if this enum value equals UTF32LE

Source
utf8?

Returns true if this enum value equals UTF8

Source