-
Notifications
You must be signed in to change notification settings - Fork 2
/
PyUnicode.go
36 lines (30 loc) · 787 Bytes
/
PyUnicode.go
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
30
31
32
33
34
35
36
package py3
import (
"github.com/aadog/py3-go/cpy3"
"unsafe"
)
type PyUnicode struct {
PyObject
}
func (p *PyUnicode) GetLength() int64 {
return cpy3.PyUnicode_GetLength(p.instance)
}
func (p *PyObject) AsUTF8() string {
return cpy3.PyUnicode_AsUTF8(p.instance)
}
func PyUnicode_DecodeFSDefault(s string) *PyUnicode {
return PyUnicodeFromInst(cpy3.PyUnicode_DecodeFSDefault(s))
}
func NewPyUnicode(s string) *PyUnicode {
return PyUnicodeFromInst(cpy3.PyUnicode_FromString(s))
}
// PyUnicodeFromInst
// 新建一个对象来自已经存在的对象实例指针。
//
// Create a new object from an existing object instance pointer.
func PyUnicodeFromInst(inst uintptr) *PyUnicode {
dl := new(PyUnicode)
dl.instance = inst
dl.ptr = unsafe.Pointer(dl.instance)
return dl
}