github.com/suiyunonghen/DxCommonLib@v0.5.3/strfuncs_unix.go (about)

     1  // +build linux darwin dragonfly freebsd netbsd openbsd
     2  
     3  package DxCommonLib
     4  
     5  import (
     6  	"errors"
     7  	"unicode/utf16"
     8  )
     9  
    10  var(
    11  	EINVAL = errors.New("invalid argument")
    12  )
    13  
    14  func UTF16FromString(s string) ([]uint16, error) {
    15  	for i := 0; i < len(s); i++ {
    16  		if s[i] == 0 {
    17  			return nil, EINVAL
    18  		}
    19  	}
    20  	return utf16.Encode([]rune(s + "\x00")), nil
    21  }