qbolt/util.go

25 lines
521 B
Go
Raw Permalink Normal View History

2024-10-03 06:34:28 +00:00
package main
2024-10-05 02:58:56 +00:00
import (
"unsafe"
"github.com/mappu/miqt/qt"
)
2024-10-03 06:34:28 +00:00
// ReverseSlice reverses a slice.
// @ref https://stackoverflow.com/a/28058324
func ReverseSlice[S ~[]E, E any](s S) {
for i, j := 0, len(s)-1; i < j; i, j = i+1, j-1 {
s[i], s[j] = s[j], s[i]
}
}
2024-10-05 02:58:56 +00:00
func MakeQByteArray(s string) *qt.QByteArray {
return qt.NewQByteArray7(s, len(s))
}
func FromQByteArray(qba *qt.QByteArray) string {
var rawData []byte = unsafe.Slice((*byte)(qba.Data()), qba.Length())
return string(rawData) // copy
}