wchar

package
v0.0.1-alpha Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 26, 2015 License: Apache-2.0 Imports: 4 Imported by: 0

README

cgo.wchar

Helps with using wchars with cgo.

Example

Example from the go.hid library:

func (dev *Device) ManufacturerString() (string, error) {
	// create WcharString
	ws := wchar.NewWcharString(100)

	// retrieve manufacturer string from hid
	res := C.hid_get_manufacturer_string(dev.hidHandle, (*C.wchar_t)(ws.Pointer()), 100)
	if res != 0 {
		return "", dev.lastError()
	}

	// get WcharString as Go string
	str := ws.GoString()

	// all done
	return str, nil
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WcharPtrToGoRune

func WcharPtrToGoRune(first unsafe.Pointer) (rune, error)

convenient wrapper for WcharPtrToWcharString(first).GoString()

func WcharStringPtrNToGoString

func WcharStringPtrNToGoString(first unsafe.Pointer, length int) (string, error)

convert a *C.wchar_t and length int to a Go string convenient wrapper for WcharPtrIntToWcharString(first, length).GoString()

func WcharStringPtrToGoString

func WcharStringPtrToGoString(first unsafe.Pointer) (string, error)

convert a null terminated *C.wchar_t to a Go string convenient wrapper for WcharPtrToWcharString(first).GoString()

Types

type Wchar

type Wchar int32

go representation of a wchar

func FromGoRune

func FromGoRune(r rune) (Wchar, error)

func FromWcharPtr

func FromWcharPtr(ptr unsafe.Pointer) Wchar

FromWcharPtr converts a *C.wchar_t to a Go Wchar

func (Wchar) GoRune

func (w Wchar) GoRune() (rune, error)

convert Wchar to Go rune will return an error when conversion failed.

func (Wchar) Pointer

func (w Wchar) Pointer() *Wchar

return pointer to this Wchar

type WcharString

type WcharString []Wchar

go representation of a wchar string (array)

func FromGoString

func FromGoString(s string) (WcharString, error)

FromGoString creates a WcharString from a Go string

func FromWcharStringPtr

func FromWcharStringPtr(first unsafe.Pointer) WcharString

FromWcharStringPtr creates a WcharString from a *C.wchar_t. It finds the end of the *C.wchar_t string by finding the null terminator.

func FromWcharStringPtrN

func FromWcharStringPtrN(first unsafe.Pointer, length int) WcharString

convert a *C.wchar_t and length int to a WcharString

func NewWcharString

func NewWcharString(length int) WcharString

NewWcharString creates a new WcharString with given length. This is required when the WcharString is being used as write buffer for a call to a C function.

func (WcharString) GoString

func (ws WcharString) GoString() (string, error)

convert WcharString to Go string will return an error when conversion failed.

func (WcharString) Pointer

func (ws WcharString) Pointer() *Wchar

return pointer to first element

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL