What is a surrogate pair?

前端 未结 3 627
猫巷女王i
猫巷女王i 2021-01-03 03:49

I came across this code in a javascript open source project.

validator.isLength = function (str, min, max) 
    // match surrogate pairs in string or declare         


        
3条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-03 04:07

    For your second question: 1. What is a "surrogate pair" in Java? The term "surrogate pair" refers to a means of encoding Unicode characters with high code-points in the UTF-16 encoding scheme.

    In the Unicode character encoding, characters are mapped to values between 0x0 and 0x10FFFF.

    Internally, Java uses the UTF-16 encoding scheme to store strings of Unicode text. In UTF-16, 16-bit (two-byte) code units are used. Since 16 bits can only contain the range of characters from 0x0 to 0xFFFF, some additional complexity is used to store values above this range (0x10000 to 0x10FFFF). This is done using pairs of code units known as surrogates.

    The surrogate code units are in two ranges known as "low surrogates" and "high surrogates", depending on whether they are allowed at the start or end of the two code unit sequence.

    1. https://msdn.microsoft.com/en-us/library/windows/desktop/dd374069%28v=vs.85%29.aspx?f=255&MSPPError=-2147217396

    Hope this helps.

提交回复
热议问题