Ooops just realised that I didn't enforce the max chars limit. Here's 
another version:

func CwcharToString(p uintptr, maxchars int) string {
    if p == 0 {
        return ""
    }
    uints := make([]uint16, 0, maxchars)
    for i, p := 0, uintptr(unsafe.Pointer(p)); i < maxchars; p += 2 {
        u := *(*uint16)(unsafe.Pointer(p))
        if u == 0 {
            break
        }
        uints = append(uints, u)
        i++
    }
    return string(utf16.Decode(uints))
}

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to