26 lines
661 B
Go
26 lines
661 B
Go
|
|
package odbc
|
||
|
|
|
||
|
|
import (
|
||
|
|
"unicode/utf16"
|
||
|
|
)
|
||
|
|
|
||
|
|
// StringToUTF16 returns the UTF-16 encoding of the UTF-8 string s,
|
||
|
|
// with a terminating NUL added.
|
||
|
|
func StringToUTF16(s string) []uint16 { return utf16.Encode([]rune(s + "\x00")) }
|
||
|
|
|
||
|
|
// UTF16ToString returns the UTF-8 encoding of the UTF-16 sequence s,
|
||
|
|
// with a terminating NUL removed.
|
||
|
|
func UTF16ToString(s []uint16) string {
|
||
|
|
for i, v := range s {
|
||
|
|
if v == 0 {
|
||
|
|
s = s[0:i]
|
||
|
|
break
|
||
|
|
}
|
||
|
|
}
|
||
|
|
return string(utf16.Decode(s))
|
||
|
|
}
|
||
|
|
|
||
|
|
// StringToUTF16Ptr returns pointer to the UTF-16 encoding of
|
||
|
|
// the UTF-8 string s, with a terminating NUL added.
|
||
|
|
func StringToUTF16Ptr(s string) *uint16 { return &StringToUTF16(s)[0] }
|