github.com/rajveermalviya/gamen@v0.1.2-0.20220930195403-9be15877c1aa/internal/win32/util.go (about)

     1  package win32
     2  
     3  func must[T any](v T, err error) T {
     4  	if err != nil {
     5  		panic(err)
     6  	}
     7  	return v
     8  }
     9  
    10  func loword(x uint32) uint16 {
    11  	return uint16(x & 0xFFFF)
    12  }
    13  
    14  func hiword(x uint32) uint16 {
    15  	return uint16((x >> 16) & 0xFFFF)
    16  }
    17  
    18  func decodeUtf16(s uint16) rune {
    19  	const (
    20  		// 0xd800-0xdc00 encodes the high 10 bits of a pair.
    21  		// 0xdc00-0xe000 encodes the low 10 bits of a pair.
    22  		// the value is those 20 bits plus 0x10000.
    23  		surr1 = 0xd800
    24  		surr3 = 0xe000
    25  
    26  		// Unicode replacement character
    27  		replacementChar = '\uFFFD'
    28  	)
    29  
    30  	var a rune
    31  	switch r := s; {
    32  	case r < surr1, surr3 <= r:
    33  		// normal rune
    34  		a = rune(r)
    35  	default:
    36  		// invalid surrogate sequence
    37  		a = replacementChar
    38  	}
    39  	return a
    40  }