Interface TranscodingErrorHandler
- Functional Interface:
- This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
An error handler for transcoding operations such as
TruffleString.SwitchEncodingNode
.- Since:
- 23.1
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic final record
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final TranscodingErrorHandler
The default transcoding error handler.static final TranscodingErrorHandler
Same asDEFAULT
, but also keepsUTF-16 surrogate values
in UTF-8. -
Method Summary
Modifier and TypeMethodDescriptionapply
(AbstractTruffleString sourceString, int byteIndex, int estimatedByteLength, TruffleString.Encoding sourceEncoding, TruffleString.Encoding targetEncoding) Transcoding error handler implementation.
-
Field Details
-
DEFAULT
The default transcoding error handler. In UTF encodings, it replaces invalid codepoints with0xfffd
, in all other encodings it uses'?'
instead. Exceptions: in UTF-16 and UTF-32, it keepsUTF-16 surrogate values
.- Since:
- 23.1
-
DEFAULT_KEEP_SURROGATES_IN_UTF8
Same asDEFAULT
, but also keepsUTF-16 surrogate values
in UTF-8.- Since:
- 23.1
-
-
Method Details
-
apply
TranscodingErrorHandler.ReplacementString apply(AbstractTruffleString sourceString, int byteIndex, int estimatedByteLength, TruffleString.Encoding sourceEncoding, TruffleString.Encoding targetEncoding) Transcoding error handler implementation. This method is called once for every byte region that could not be transcoded fromsourceEncoding
totargetEncoding
.- Parameters:
sourceString
- the string currently being transcoded.byteIndex
- starting index of region that could not be transcoded.estimatedByteLength
- estimated byte length of erroneous region.sourceEncoding
- the source string's encoding.targetEncoding
- the target encoding.- Returns:
- a string to use instead of the invalid region.
- Since:
- 23.1
-