utils.go 350 B

1234567891011121314151617181920212223
  1. package ieproxy
  2. import (
  3. "unicode/utf16"
  4. "unsafe"
  5. )
  6. // StringFromUTF16Ptr converts a *uint16 C string to a Go String
  7. func StringFromUTF16Ptr(s *uint16) string {
  8. if s == nil {
  9. return ""
  10. }
  11. p := (*[1<<30 - 1]uint16)(unsafe.Pointer(s))
  12. // find the string length
  13. sz := 0
  14. for p[sz] != 0 {
  15. sz++
  16. }
  17. return string(utf16.Decode(p[:sz:sz]))
  18. }