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)
| 309 | // re-implementation of PyUnicode_AsUTF8. The bytes are copied from |
| 310 | // the vmem, so the returned string is safe to use. |
| 311 | func 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 | |
| 325 | func derefPyUnicodeUtf8(m vmem, p ptr32) string { |
| 326 | x := deref[ptr32](m, p) |
no test coverage detected