CharacterEncoding

Description

[ShutdownSurvive]
abstract class Tinman.Core.Formatting.CharacterEncoding

Extended by

CharacterEncodingSimple abstract

Base class for single-byte and multi-byte character encodings.

Only non-surrogate (see CharacterCategory.OtherSurrogate) Unicode characters in the range [0..65535] may be encoded to resp. decoded from a byte sequence. All other characters will result in Unprintables.

Public / Constants

Simple​Http


[ShutdownSurvive]
public static readonly attribute SimpleHttp → (ISimpleHttpText)

A ISimpleHttpText object that uses the built-in character encoding to decode text data.

See also

ISimpleHttp

Unprintable


public constant Unprintable → ((char) 0xFDFF:char)

The unprintable character.

UTF_16_​BE


public static readonly attribute UTF_16_BE → (CharacterEncoding)

Character encoding UTF-16 (big-endian).

UTF_16_​LE


public static readonly attribute UTF_16_LE → (CharacterEncoding)

Character encoding UTF-16 (little-endian).

UTF_8


public static readonly attribute UTF_8 → (CharacterEncoding)

Character encoding UTF-8.

Public / Constructors

For


public static method For → (2)

name in : string

The name or null.

defaultEncoding opt : CharacterEncoding = null

The default encoding to return in case name in is not recognized. Defaults to null.

returns → CharacterEncoding

The found encoding or null.

Returns a character encoding by its name.

The given name is normalized before trying to find a character encoding: First, the name is converted to lower-case. Then, all characters that are neither letters nor digits are removed (i.e. only '0'..'9', 'a'..'z' are retained). The resulting normalized name is then tested against the following values in order to find a character encoding:

Public / Methods

Decode

2 overloads


public abstract method Decode1 → (1)

input in : ByteBuffer

[not-null]
The input buffer.

returns → int32

The decoded unicode character or -1 if the given buffer does not contain any more characters.

Decodes a single unicode character.


public abstract method Decode2 → (1)

input in : IDataStream

[not-null]
The input buffer.

returns → int32

The decoded unicode character or -1 if the given buffer does not contain any more characters.

Decodes a single unicode character.

IOException

If an I/O error has occurred.

Decode​String


public method DecodeString → (1)

bytes in : ByteBuffer

The single-byte encoded string.

returns → string

The unicode string or null iff bytes in is null.

Converts the given encoded string to unicode.

Encode

2 overloads


public abstract method Encode1 → (2)

character in : char

The unicode character.

output in : ByteBuffer

[not-null]
The output buffer.

returns → int32

The number of bytes that have been written to output in if there was enough space left; -n if the buffer does not have enough space left, where n is then the number of bytes that would have been written.

Encodes the given unicode character.

Characters that cannot be encoded will be replaced with '?'.


public abstract method Encode2 → (2)

character in : char

The unicode character.

output in : IDataStream

[not-null]
The output buffer.

returns → int32

The number of bytes that have been written to output in.

Encodes the given unicode character.

Characters that cannot be encoded will be replaced with '?'.

IOException

If an I/O error has occurred.

Encode​Count


public abstract method EncodeCount → (1)

character in : char

The unicode character.

returns → int32

The number of bytes that would have been written to an output buffer.

Encodes the given unicode character.

Characters that cannot be encoded will be replaced with '?'.

Encode​String


[OwnerReturn]
public method EncodeString → (2)

str in : string

The unicode string.

bytes opt : ByteBuffer own = null

The output buffer (can be null).

returns → ByteBuffer

The resulting buffer or null iff str in is null.

Converts the given unicode string to this encoding.

The encoded bytes will be written to bytes opt beginning at the current buffer position. Before returning, this method sets the ByteBuffer.Position and ByteBuffer.Limit to the range of encoded bytes that have been output.

Get​Byte​Count

4 overloads


public method GetByteCount1 → (1)

str in : char [ ]

[not-null]
The string.

returns → int32

The number of encoded bytes.

Returns the number of encoded bytes for the given string.


public method GetByteCount2 → (1)

str in : string

[not-null]
The string.

returns → int32

The number of encoded bytes.

Returns the number of encoded bytes for the given string.


public method GetByteCount3 → (3)

str in : char [ ]

[not-null]
The string.

offset in : int32

[>=0]
Offset to first character in string.

count in : int32

[>=0]
Number of characters in string.

returns → int32

The number of encoded bytes.

Returns the number of encoded bytes for the given string.


public method GetByteCount4 → (3)

str in : string

[not-null]
The string.

offset in : int32

[>=0]
Offset to first character in string.

count in : int32

[>=0]
Number of characters in string.

returns → int32

The number of encoded bytes.

Returns the number of encoded bytes for the given string.

Public / Attributes

Bytes​Per​Character


public abstract attribute BytesPerCharacter → (get)

value : int32

[>=0]
The number of bytes per character or 0 if this encoding uses variable byte counts (e.g. UTF-8).

Returns the number of bytes per character.

Name


public abstract attribute Name → (get)

value : string

[not-null]
The encoding name.

Returns the name of this character encoding.