github.com/primecitizens/pcz/std@v0.2.1/text/unicode/utf32/utf32.go (about)

     1  package utf32
     2  
     3  import (
     4  	"math/bits"
     5  	"unsafe"
     6  
     7  	"github.com/primecitizens/pcz/std/core/arch"
     8  )
     9  
    10  func AsString(s []uint32) String {
    11  	if arch.BigEndian {
    12  		for i, x := range s {
    13  			s[i] = bits.ReverseBytes32(x)
    14  		}
    15  	}
    16  
    17  	return String(
    18  		unsafe.String(
    19  			(*byte)(unsafe.Pointer(unsafe.SliceData(s))), len(s)*4,
    20  		),
    21  	)
    22  }
    23  
    24  type String string
    25  
    26  func (s String) Slice() []uint32 {
    27  	ret := unsafe.Slice(
    28  		(*uint32)(unsafe.Pointer(unsafe.StringData(string(s)))), len(s)/4,
    29  	)
    30  
    31  	if arch.BigEndian {
    32  		for i, x := range ret {
    33  			ret[i] = bits.ReverseBytes32(x)
    34  		}
    35  	}
    36  
    37  	return ret
    38  }