entities 9.0.0
class HtmlEntityDecoder extends EntityDecoderBase

Defined in decode.ts:982

Streaming decoder for HTML entities.

When the entity fits inside the current chunk (the common case), the lookup runs directly on the chunk via the same length-probe scheme as the synchronous decoder; chunk-boundary runs use a reusable character buffer.

Constructors

new HtmlEntityDecoder(emitCodePoint: (cp: number, consumed: number) => void, errors?: EntityErrorProducer | undefined): HtmlEntityDecoder

Parameters

emitCodePoint: (cp: number, consumed: number) => void

The function that is called when a codepoint is decoded.

For multi-byte named entities, this will be called multiple times, with the second codepoint, and the same consumed value.

errors?: EntityErrorProducer | undefined

An object that is used to produce errors.

Returns

HtmlEntityDecoder

Inherited from EntityDecoderBase.constructor

Properties

protected consumed: number

Characters that were consumed while parsing an entity.

Inherited from EntityDecoderBase.consumed

protected decodeMode: DecodingMode

The mode in which the decoder is operating.

Inherited from EntityDecoderBase.decodeMode

emitCodePoint protected readonly

decode.ts:741
protected readonly emitCodePoint: (cp: number, consumed: number) => void

The function that is called when a codepoint is decoded.

For multi-byte named entities, this will be called multiple times, with the second codepoint, and the same consumed value.

Parameters

cp: number
consumed: number

The number of bytes consumed by the decoder.

Returns

void

Inherited from EntityDecoderBase.emitCodePoint

errors protected readonly optional

decode.ts:746
protected readonly errors?: EntityErrorProducer | undefined

An object that is used to produce errors.

Inherited from EntityDecoderBase.errors

protected readonly replaceNumericCodePoint: (codePoint: number) => number

Replacement rules for numeric character references.

Parameters

codePoint: number

Returns

number

Inherited from EntityDecoderBase.replaceNumericCodePoint

protected result: number

Accumulated numeric code point, or a packed partial XML name.

Inherited from EntityDecoderBase.result

protected state: number

The current state of the decoder.

Inherited from EntityDecoderBase.state

Methods

end(): number

Signal to the parser that the end of the input was reached.

Remaining data will be emitted and relevant errors will be produced.

Returns

number

The number of characters consumed.

Inherited from EntityDecoderBase.end

protected endNamedEntity(): number

Resolve a named entity that was still incomplete when the input ended.

Returns

number

The number of characters that were consumed.

Overrides EntityDecoderBase.endNamedEntity

startEntity(decodeMode: DecodingMode): void

Resets the instance to make it reusable.

Parameters

decodeMode: DecodingMode

Entity decoding mode to use.

Returns

void

Overrides EntityDecoderBase.startEntity

protected stateNamedEntity(input: string, offset: number): number

Decode a named entity.

Parameters

input: string

The string containing the entity (or a continuation of the entity).

offset: number

The current offset.

Returns

number

The number of characters that were consumed, or -1 if the entity is incomplete.

Overrides EntityDecoderBase.stateNamedEntity

write(input: string, offset: number): number

Write an entity to the decoder. This can be called multiple times with partial entities. If the entity is incomplete, the decoder will return -1.

Parameters

input: string

The string containing the entity (or a continuation of the entity).

offset: number

The offset at which the entity begins. Should be 0 if this is not the first call.

Returns

number

The number of characters that were consumed, or -1 if the entity is incomplete.

Inherited from EntityDecoderBase.write