Golang Study (--unicode) UTF16 bag

Source: Internet
Author: User
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;]

}


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.