Exemplo n.º 1
0
func (c osx16Collator) Compare(a, b Input) int {
	sa := C.CFStringCreateWithCharactersNoCopy(
		nil,
		osxCharP(a.UTF16),
		C.CFIndex(len(a.UTF16)),
		nil,
	)
	sb := C.CFStringCreateWithCharactersNoCopy(
		nil,
		osxCharP(b.UTF16),
		C.CFIndex(len(b.UTF16)),
		nil,
	)
	_range := C.CFRangeMake(0, C.CFStringGetLength(sa))
	return int(C.CFStringCompareWithOptionsAndLocale(sa, sb, _range, c.opt, c.loc))
}
Exemplo n.º 2
0
func (c osx8Collator) Compare(a, b Input) int {
	sa := C.CFStringCreateWithBytesNoCopy(
		nil,
		osxUInt8P(a.UTF8),
		C.CFIndex(len(a.UTF8)),
		C.kCFStringEncodingUTF8,
		C.Boolean(0),
		nil,
	)
	sb := C.CFStringCreateWithBytesNoCopy(
		nil,
		osxUInt8P(b.UTF8),
		C.CFIndex(len(b.UTF8)),
		C.kCFStringEncodingUTF8,
		C.Boolean(0),
		nil,
	)
	_range := C.CFRangeMake(0, C.CFStringGetLength(sa))
	return int(C.CFStringCompareWithOptionsAndLocale(sa, sb, _range, c.opt, c.loc))
}
Exemplo n.º 3
0
// Converts a CGStringRef object to a Go string.
func CFStringToGoString(s C.CFStringRef) string {
	ptr := C.CFStringGetCStringPtr(s, C.kCFStringEncodingUTF8)

	if ptr != nil {
		return C.GoString(ptr)
	}

	n := C.CFStringGetLength(s)
	b := make([]byte, int(4*n))
	C.CFStringGetBytes(
		s,
		C.CFRangeMake(0, n),
		C.kCFStringEncodingUTF8,
		'?',
		0,
		(*C.UInt8)(unsafe.Pointer(&b[0])),
		C.CFIndex(len(b)),
		&n,
	)

	return string(b[:n])
}