示例#1
0
文件: highlight.go 项目: rlugojr/lucy
func spanSliceToVec(slice []Span) *C.cfish_Vector {
	if slice == nil {
		return nil
	}
	length := len(slice)
	vec := C.cfish_Vec_new(C.size_t(length))
	for i := 0; i < length; i++ {
		elem := clownfish.Unwrap(slice[i], "slice[i]")
		C.CFISH_Vec_Push(vec, C.cfish_incref(elem))
	}
	return vec
}
示例#2
0
文件: lucy.go 项目: apache/lucy
// Turn a slice of Go strings into a Vector of Clownfish Strings.
func stringSliceToVec(strings []string) *C.cfish_Vector {
	if strings == nil {
		return nil
	}
	size := len(strings)
	vec := C.cfish_Vec_new(C.size_t(size))
	for i := 0; i < size; i++ {
		str := C.CString(strings[i])
		length := C.size_t(len(strings[i]))
		cfStr := C.cfish_Str_new_steal_utf8(str, length)
		C.CFISH_Vec_Push(vec, (*C.cfish_Obj)(unsafe.Pointer(cfStr)))
	}
	return vec
}
示例#3
0
文件: index.go 项目: rlugojr/lucy
func (d *DataReaderIMP) Aggregator(readers []DataReader, offsets []int32) (retval DataReader, err error) {
	err = clownfish.TrapErr(func() {
		self := (*C.lucy_DataReader)(clownfish.Unwrap(d, "d"))
		size := len(readers)
		readersC := C.cfish_Vec_new(C.size_t(size))
		defer C.cfish_decref(unsafe.Pointer(readersC))
		for i := 0; i < size; i++ {
			elemC := clownfish.Unwrap(readers[i], "readers[i]")
			C.CFISH_Vec_Push(readersC, C.cfish_incref(elemC))
		}
		offs := NewI32Array(offsets)
		offsetsC := (*C.lucy_I32Array)(clownfish.Unwrap(offs, "offs"))
		retvalCF := C.LUCY_DataReader_Aggregator(self, readersC, offsetsC)
		defer C.cfish_decref(unsafe.Pointer(retvalCF))
		if retvalCF != nil {
			retval = clownfish.ToGo(unsafe.Pointer(retvalCF)).(DataReader)
		}
	})
	return retval, err
}