MCPcopy Create free account
hub / github.com/dispatchrun/wzprof / pyUnicodeUTf8

Function pyUnicodeUTf8

python.go:311–323  ·  view source on GitHub ↗

Return the utf8 encoding of a PyUnicode object. It is a re-implementation of PyUnicode_AsUTF8. The bytes are copied from the vmem, so the returned string is safe to use.

(m vmem, p ptr32)

Source from the content-addressed store, hash-verified

309// re-implementation of PyUnicode_AsUTF8. The bytes are copied from
310// the vmem, so the returned string is safe to use.
311func pyUnicodeUTf8(m vmem, p ptr32) string {
312 statep := p + padStateInAsciiObject
313 state := deref[uint8](m, statep)
314 compact := state&(1<<5) > 0
315 ascii := state&(1<<6) > 0
316 if !compact || !ascii {
317 panic("only support ascii-compact utf8 representation")
318 }
319
320 length := deref[int32](m, p+padLengthInAsciiObject)
321 bytes := derefArray[byte](m, p+sizeAsciiObject, uint32(length))
322 return unsafe.String(unsafe.SliceData(bytes), len(bytes))
323}
324
325func derefPyUnicodeUtf8(m vmem, p ptr32) string {
326 x := deref[ptr32](m, p)

Callers 1

derefPyUnicodeUtf8Function · 0.85

Calls 1

StringMethod · 0.45

Tested by

no test coverage detected