numpy  2.0.0
src/multiarray/ucsnarrow.h File Reference

Go to the source code of this file.

Functions

NPY_NO_EXPORT int PyUCS2Buffer_FromUCS4 (Py_UNICODE *ucs2, npy_ucs4 *ucs4, int ucs4length)
NPY_NO_EXPORT int PyUCS2Buffer_AsUCS4 (Py_UNICODE *ucs2, npy_ucs4 *ucs4, int ucs2len, int ucs4len)
NPY_NO_EXPORT PyUnicodeObject * PyUnicode_FromUCS4 (char *src, Py_ssize_t size, int swap, int align)

Function Documentation

NPY_NO_EXPORT int PyUCS2Buffer_AsUCS4 ( Py_UNICODE *  ucs2,
npy_ucs4 *  ucs4,
int  ucs2len,
int  ucs4len 
)
This converts a UCS2 buffer of the given length to UCS4 buffer. It converts up to ucs4len characters of UCS2
It returns the number of characters converted which can be less than ucs2len if there are surrogate pairs in ucs2.
The return value is the actual size of the used part of the ucs4 buffer.
surrogate pair

<

-0xdc00 + 0x10000
NPY_NO_EXPORT int PyUCS2Buffer_FromUCS4 ( Py_UNICODE *  ucs2,
npy_ucs4 *  ucs4,
int  ucs4length 
)
Functions only needed on narrow builds of Python for converting back and forth between the NumPy Unicode data-type (always 4-bytes) and the Python Unicode scalar (2-bytes on a narrow build).
The ucs2 buffer must be large enough to hold 2*ucs4length characters due to the use of surrogate pairs.
The return value is the number of ucs2 bytes used-up which is ucs4length + number of surrogate pairs found.
Values above 0xffff are converted to surrogate pairs.
NPY_NO_EXPORT PyUnicodeObject* PyUnicode_FromUCS4 ( char *  src,
Py_ssize_t  size,
int  swap,
int  align 
)
Returns a PyUnicodeObject initialized from a buffer containing UCS4 unicode.

Parameters

<blockquote>

src: char *
Pointer to buffer containing UCS4 unicode.
size: Py_ssize_t
Size of buffer in bytes.
swap: int
If true, the data will be swapped.
align: int
If true, the data will be aligned.

</blockquote>

Returns

new_reference: PyUnicodeObject
swap and align if needed
trim trailing zeros
produce PyUnicode object