-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstring.go
More file actions
29 lines (24 loc) · 718 Bytes
/
string.go
File metadata and controls
29 lines (24 loc) · 718 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
package cbyte
import (
"unsafe"
)
// InitString makes a string with underlying cbyte pointer.
func InitString(len int) string {
return String(InitHeader(len, len))
}
// ReleaseString releases underlying cbyte pointer of string.
//
// Caution! Don't try to release non-cbyte strings.
func ReleaseString(p string) {
ReleaseHeader(HeaderString(p))
}
// HeaderString decomposes string to SliceHeader.
func HeaderString(p string) SliceHeader {
h := *(*StringHeader)(unsafe.Pointer(&p))
return SliceHeader{Data: h.Data, Len: h.Len, Cap: h.Len}
}
// String composes string from SliceHeader.
func String(h SliceHeader) string {
hs := StringHeader{Data: h.Data, Len: h.Len}
return *(*string)(unsafe.Pointer(&hs))
}