This is a creation in Article, where the information may have evolved or changed.
Golang learn to listen to UNICODE/UTF16-listen to the bag
----------------------------
Issurrogate determine if R is a proxy area character
Two proxy area characters can be used to combine a UTF16 encoding
Func Listen issurrogate (R rune) BOOL
Encoderune encode the character R into the UTF-16 agent pair//R: the character to encode
If r < 0x10000, then no coding is required, and its UTF-16 sequence is its own
R1: The high-bit code element of the encoded UTF-16 agent pair
R2: The low code element of the encoded UTF-16 agent pair
If r is not a valid Unicode character, or is a proxy-area character, or does not need to be encoded
Then return to U+FFFD, U+FFFD
func listen to Encoderune (R rune Span style= "font-family: ' Courier New '; Color:rgb (165,165,165); Background-color:rgb (255,255,255);" >) (R1, R2 rune Span style= "font-family: ' Courier New '; Color:rgb (165,165,165); Background-color:rgb (255,255,255);" >)
Decoderune decodes the UTF-16 proxy pair into a Unicode character
R1: is the UTF-16 agent pair of high-level code element
R2: is the low code element of UTF-16 agent pair
The returned value is the decoded Unicode character
Returns U+FFFD if R1 or R2 is not a valid UTF-16 proxy area character
Func Listen Decoderune (R1, R2 rune) Rune
Decode decodes the UTF-16 sequence s into a sequence of Unicode characters and returns
Func Listen Decode (s []uint16) [] Rune
Encode encodes s into a UTF-16 sequence and returns
Func Listen Encode (s []rune) [] uint16
------------------------------
Example
Func Listen Main () {Listen
Hear and hear the FMT.Printf("%t,", Utf16.issurrogate(0xd400)) //FalseListen
Hear and hear the FMT.Printf("%t,", Utf16.issurrogate(0xdc00)) //TrueListen
Hear and hear the FMT.Printf("%t\n", Utf16.issurrogate(0xDFFF)) //TrueListen
Listen to listen to R1, r2: = Utf16. encoderune ( ' > ' ) Listen to
Listen and listen to the FMT. printf Span style= "font-family: ' Courier New '; Color:rgb (165,165,165); Background-color:rgb (255,255,255);" > ( "%x,% x\n " //d840, dc3e listen
Listen listen r: = Utf16. decoderune ( 0xd840 , 0xdc3e ) listen
Hear and hear the FMT. Printf ("%c\n", R) //d840, dc3e Listen
Listen to hear u: = []uint16{' No ', ' will ', 0xd840, 0xdc3e} Listen
Listen and listen to s: = Utf16. Decode (u) listen
Hear and hear the FMT. Printf ("%c", s) //[will not;]
}