Utf16
Description
Container class containing UTF-16 platform-endian encoding.
@see Class Comments in <EsUnicodeEncoding> for usage examples.
Class Methods
asUnicodeString:repair:
  Answer a new unicode string instance using utf16 bytes from @aByteOrWordObject
     If @repair is true, then invalid utf16 will be replaced with the unicode replacement character U+FFFD.
     
     Examples:
        'Grinning Face (U+16r1F600) in platform endian'.
        self assert: [
            (System bigEndian
                ifTrue: [(Utf16 asUnicodeString: #[216 61 222 0] repair: false) first name = 'GRINNING FACE']
                ifFalse: [(Utf16 asUnicodeString: #[61 216 0 222] repair: false) first name = 'GRINNING FACE'])].
        
      'Invalid because of isolated surrogate - 16rD800'.
      self assert: [(Utf16LE asUnicodeString: (Utf16LE with:16rD800) repair: true) = UnicodeScalar replacementCharacter asUnicodeString].
    
     Arguments:
        aByteOrWordObject - <ByteArray | Utf16>
        repair - <Boolean>
     Answers:
        <UnicodeString>
     Raises:
        <Exception> EsPrimErrValueOutOfRange if @anObject contains invalid bytes and @repair is false
Instance Methods
isValid
  Answer true if the content of the container represents valid UTF-16 data
     encoded in the endian type defined by the container.
     
     Examples:
        'Grinning Face (U+1F600) in platform endian'.
        self assert: [
            System bigEndian
                ifTrue: [(Utf16 with: 16r3DD8 with: 16r00DE) isValid]
                ifFalse: [(Utf16 with: 16rD83D with: 16rDE00) isValid]].
        
        'Invalid because of isolated surrogate - 16rD800'.
        self assert: [(Utf16LE with: 16rD83D with: 16rD800) isValid not]
     
     Answers:
        <Boolean> true if valid, false if invalid
Last modified date: 01/06/2026