本文整理汇总了C++中PyUnicode_GET_LENGTH函数的典型用法代码示例。如果您正苦于以下问题:C++ PyUnicode_GET_LENGTH函数的具体用法?C++ PyUnicode_GET_LENGTH怎么用?C++ PyUnicode_GET_LENGTH使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了PyUnicode_GET_LENGTH函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: zipimport_zipimporter_get_data_impl
static PyObject *
zipimport_zipimporter_get_data_impl(ZipImporter *self, PyObject *path)
/*[clinic end generated code: output=65dc506aaa268436 input=fa6428b74843c4ae]*/
{
PyObject *key;
PyObject *toc_entry;
Py_ssize_t path_start, path_len, len;
if (self->archive == NULL) {
PyErr_SetString(PyExc_ValueError,
"zipimporter.__init__() wasn't called");
return NULL;
}
#ifdef ALTSEP
path = _PyObject_CallMethodId((PyObject *)&PyUnicode_Type, &PyId_replace,
"OCC", path, ALTSEP, SEP);
if (!path)
return NULL;
#else
Py_INCREF(path);
#endif
if (PyUnicode_READY(path) == -1)
goto error;
path_len = PyUnicode_GET_LENGTH(path);
len = PyUnicode_GET_LENGTH(self->archive);
path_start = 0;
if (PyUnicode_Tailmatch(path, self->archive, 0, len, -1)
&& PyUnicode_READ_CHAR(path, len) == SEP) {
path_start = len + 1;
}
key = PyUnicode_Substring(path, path_start, path_len);
if (key == NULL)
goto error;
toc_entry = PyDict_GetItem(self->files, key);
if (toc_entry == NULL) {
PyErr_SetFromErrnoWithFilenameObject(PyExc_OSError, key);
Py_DECREF(key);
goto error;
}
Py_DECREF(key);
Py_DECREF(path);
return get_data(self->archive, toc_entry);
error:
Py_DECREF(path);
return NULL;
}
示例2: zipimporter_get_data
static PyObject *
zipimporter_get_data(PyObject *obj, PyObject *args)
{
ZipImporter *self = (ZipImporter *)obj;
PyObject *path, *key;
#ifdef ALTSEP
_Py_IDENTIFIER(replace);
#endif
PyObject *toc_entry;
Py_ssize_t path_start, path_len, len;
if (!PyArg_ParseTuple(args, "U:zipimporter.get_data", &path))
return NULL;
#ifdef ALTSEP
path = _PyObject_CallMethodId(path, &PyId_replace, "CC", ALTSEP, SEP);
if (!path)
return NULL;
#else
Py_INCREF(path);
#endif
if (PyUnicode_READY(path) == -1)
goto error;
path_len = PyUnicode_GET_LENGTH(path);
len = PyUnicode_GET_LENGTH(self->archive);
path_start = 0;
if (PyUnicode_Tailmatch(path, self->archive, 0, len, -1)
&& PyUnicode_READ_CHAR(path, len) == SEP) {
path_start = len + 1;
}
key = PyUnicode_Substring(path, path_start, path_len);
if (key == NULL)
goto error;
toc_entry = PyDict_GetItem(self->files, key);
if (toc_entry == NULL) {
PyErr_SetFromErrnoWithFilenameObject(PyExc_IOError, key);
Py_DECREF(key);
goto error;
}
Py_DECREF(key);
Py_DECREF(path);
return get_data(self->archive, toc_entry);
error:
Py_DECREF(path);
return NULL;
}
示例3: asciistr_getbuffer
static int
asciistr_getbuffer(PyObject *exporter, Py_buffer *view, int flags)
{
return (PyBuffer_FillInfo(view, exporter, PyUnicode_DATA(exporter),
PyUnicode_GET_LENGTH(exporter), 1, flags));
}
示例4: qpycore_PyObject_AsQString
// Convert a Python Unicode object to a QString.
QString qpycore_PyObject_AsQString(PyObject *obj)
{
#if defined(PYQT_PEP_393)
SIP_SSIZE_T len = PyUnicode_GET_LENGTH(obj);
switch (PyUnicode_KIND(obj))
{
case PyUnicode_1BYTE_KIND:
return QString::fromLatin1((char *)PyUnicode_1BYTE_DATA(obj), len);
case PyUnicode_2BYTE_KIND:
// The (QChar *) cast should be safe.
return QString((QChar *)PyUnicode_2BYTE_DATA(obj), len);
case PyUnicode_4BYTE_KIND:
return QString::fromUcs4(PyUnicode_4BYTE_DATA(obj), len);
}
return QString();
#elif defined(Py_UNICODE_WIDE)
return QString::fromUcs4((const uint *)PyUnicode_AS_UNICODE(obj),
PyUnicode_GET_SIZE(obj));
#else
return QString::fromUtf16((const ushort *)PyUnicode_AS_UNICODE(obj),
PyUnicode_GET_SIZE(obj));
#endif
}
示例5: Reader_iternext
static PyObject *
Reader_iternext(ReaderObj *self)
{
PyObject *fields = NULL;
Py_UCS4 c;
Py_ssize_t pos, linelen;
unsigned int kind;
void *data;
PyObject *lineobj;
if (parse_reset(self) < 0)
return NULL;
do {
lineobj = PyIter_Next(self->input_iter);
if (lineobj == NULL) {
/* End of input OR exception */
if (!PyErr_Occurred() && self->field_len != 0)
PyErr_Format(error_obj,
"newline inside string");
return NULL;
}
if (!PyUnicode_Check(lineobj)) {
PyErr_Format(error_obj,
"iterator should return strings, "
"not %.200s "
"(did you open the file in text mode?)",
lineobj->ob_type->tp_name
);
Py_DECREF(lineobj);
return NULL;
}
++self->line_num;
kind = PyUnicode_KIND(lineobj);
data = PyUnicode_DATA(lineobj);
pos = 0;
linelen = PyUnicode_GET_LENGTH(lineobj);
while (linelen--) {
c = PyUnicode_READ(kind, data, pos);
if (c == '\0') {
Py_DECREF(lineobj);
PyErr_Format(error_obj,
"line contains NULL byte");
goto err;
}
if (parse_process_char(self, c) < 0) {
Py_DECREF(lineobj);
goto err;
}
pos++;
}
Py_DECREF(lineobj);
if (parse_process_char(self, 0) < 0)
goto err;
} while (self->state != START_RECORD);
fields = self->fields;
self->fields = NULL;
err:
return fields;
}
示例6: join_append
static int
join_append(WriterObj *self, PyObject *field, int *quoted, int quote_empty)
{
unsigned int field_kind = -1;
void *field_data = NULL;
Py_ssize_t field_len = 0;
Py_ssize_t rec_len;
if (field != NULL) {
field_kind = PyUnicode_KIND(field);
field_data = PyUnicode_DATA(field);
field_len = PyUnicode_GET_LENGTH(field);
}
rec_len = join_append_data(self, field_kind, field_data, field_len,
quote_empty, quoted, 0);
if (rec_len < 0)
return 0;
/* grow record buffer if necessary */
if (!join_check_rec_size(self, rec_len))
return 0;
self->rec_len = join_append_data(self, field_kind, field_data, field_len,
quote_empty, quoted, 1);
self->num_fields++;
return 1;
}
示例7: qpycore_PyObject_AsQString
// Convert a Python Unicode object to a QString.
QString qpycore_PyObject_AsQString(PyObject *obj)
{
#if defined(PYQT_PEP_393)
SIP_SSIZE_T len = PyUnicode_GET_LENGTH(obj);
switch (PyUnicode_KIND(obj))
{
case PyUnicode_1BYTE_KIND:
return QString::fromLatin1((char *)PyUnicode_1BYTE_DATA(obj), len);
case PyUnicode_2BYTE_KIND:
// The (QChar *) cast should be safe.
return QString((QChar *)PyUnicode_2BYTE_DATA(obj), len);
case PyUnicode_4BYTE_KIND:
#if QT_VERSION >= 0x040200
return QString::fromUcs4(PyUnicode_4BYTE_DATA(obj), len);
#else
// Note that this code doesn't handle code points greater than 0xffff
// very well.
QString qstr;
Py_UCS4 *ucode = PyUnicode_4BYTE_DATA(obj);
for (SIP_SSIZE_T i = 0; i < len; ++i)
qstr.append((uint)ucode[i]);
return qstr;
#endif
}
return QString();
#elif defined(Py_UNICODE_WIDE)
#if QT_VERSION >= 0x040200
return QString::fromUcs4((const uint *)PyUnicode_AS_UNICODE(obj),
PyUnicode_GET_SIZE(obj));
#else
// Note that this code doesn't handle code points greater than 0xffff very
// well.
QString qstr;
Py_UNICODE *ucode = PyUnicode_AS_UNICODE(obj);
SIP_SSIZE_T len = PyUnicode_GET_SIZE(obj);
for (SIP_SSIZE_T i = 0; i < len; ++i)
qstr.append((uint)ucode[i]);
return qstr;
#endif
#else
return QString::fromUtf16((const ushort *)PyUnicode_AS_UNICODE(obj),
PyUnicode_GET_SIZE(obj));
#endif
}
示例8: complex__format__
static PyObject *
complex__format__(PyObject* self, PyObject* args)
{
PyObject *format_spec;
if (!PyArg_ParseTuple(args, "U:__format__", &format_spec))
return NULL;
return _PyComplex_FormatAdvanced(self, format_spec, 0,
PyUnicode_GET_LENGTH(format_spec));
}
示例9: _str_shared
static int
_str_shared(PyObject *obj, _PyCrossInterpreterData *data)
{
struct _shared_str_data *shared = PyMem_NEW(struct _shared_str_data, 1);
shared->kind = PyUnicode_KIND(obj);
shared->buffer = PyUnicode_DATA(obj);
shared->len = PyUnicode_GET_LENGTH(obj) - 1;
data->data = (void *)shared;
data->obj = obj; // Will be "released" (decref'ed) when data released.
data->new_object = _new_str_object;
data->free = PyMem_Free;
return 0;
}
示例10: syslog_get_argv
static PyObject *
syslog_get_argv(void)
{
/* Figure out what to use for as the program "ident" for openlog().
* This swallows exceptions and continues rather than failing out,
* because the syslog module can still be used because openlog(3)
* is optional.
*/
Py_ssize_t argv_len, scriptlen;
PyObject *scriptobj;
Py_ssize_t slash;
PyObject *argv = PySys_GetObject("argv");
if (argv == NULL) {
return(NULL);
}
argv_len = PyList_Size(argv);
if (argv_len == -1) {
PyErr_Clear();
return(NULL);
}
if (argv_len == 0) {
return(NULL);
}
scriptobj = PyList_GetItem(argv, 0);
if (!PyUnicode_Check(scriptobj)) {
return(NULL);
}
scriptlen = PyUnicode_GET_LENGTH(scriptobj);
if (scriptlen == 0) {
return(NULL);
}
slash = PyUnicode_FindChar(scriptobj, SEP, 0, scriptlen, -1);
if (slash == -2)
return NULL;
if (slash != -1) {
return PyUnicode_Substring(scriptobj, slash, scriptlen);
} else {
Py_INCREF(scriptobj);
return(scriptobj);
}
return(NULL);
}
示例11: all_name_chars
/* all_name_chars(s): true iff s matches [a-zA-Z0-9_]* */
static int
all_name_chars(PyObject *o)
{
const unsigned char *s, *e;
if (!PyUnicode_IS_ASCII(o))
return 0;
s = PyUnicode_1BYTE_DATA(o);
e = s + PyUnicode_GET_LENGTH(o);
for (; s != e; s++) {
if (!Py_ISALNUM(*s) && *s != '_')
return 0;
}
return 1;
}
示例12: __Numba_PyObject_AsPy_UCS4
static NUMBA_INLINE Py_UCS4 __Numba_PyObject_AsPy_UCS4(PyObject* x) {
long ival;
if (PyUnicode_Check(x)) {
Py_ssize_t length;
#if CYTHON_PEP393_ENABLED
length = PyUnicode_GET_LENGTH(x);
if (likely(length == 1)) {
return PyUnicode_READ_CHAR(x, 0);
}
#else
length = PyUnicode_GET_SIZE(x);
if (likely(length == 1)) {
return PyUnicode_AS_UNICODE(x)[0];
}
#if Py_UNICODE_SIZE == 2
else if (PyUnicode_GET_SIZE(x) == 2) {
Py_UCS4 high_val = PyUnicode_AS_UNICODE(x)[0];
if (high_val >= 0xD800 && high_val <= 0xDBFF) {
Py_UCS4 low_val = PyUnicode_AS_UNICODE(x)[1];
if (low_val >= 0xDC00 && low_val <= 0xDFFF) {
return 0x10000 + (((high_val & ((1<<10)-1)) << 10) | (low_val & ((1<<10)-1)));
}
}
}
#endif
#endif
PyErr_Format(PyExc_ValueError,
"only single character unicode strings can be converted to Py_UCS4, "
"got length %" CYTHON_FORMAT_SSIZE_T "d", length);
return (Py_UCS4)-1;
}
ival = __Numba_PyInt_AsLong(x);
if (unlikely(ival < 0)) {
if (!PyErr_Occurred())
PyErr_SetString(PyExc_OverflowError,
"cannot convert negative value to Py_UCS4");
return (Py_UCS4)-1;
} else if (unlikely(ival > 1114111)) {
PyErr_SetString(PyExc_OverflowError,
"value too large to convert to Py_UCS4");
return (Py_UCS4)-1;
}
return (Py_UCS4)ival;
}
示例13: complex__format__
static PyObject *
complex__format__(PyObject* self, PyObject* args)
{
PyObject *format_spec;
_PyUnicodeWriter writer;
int ret;
if (!PyArg_ParseTuple(args, "U:__format__", &format_spec))
return NULL;
_PyUnicodeWriter_Init(&writer);
ret = _PyComplex_FormatAdvancedWriter(
&writer,
self,
format_spec, 0, PyUnicode_GET_LENGTH(format_spec));
if (ret == -1) {
_PyUnicodeWriter_Dealloc(&writer);
return NULL;
}
return _PyUnicodeWriter_Finish(&writer);
}
示例14: join_append_lineterminator
static int
join_append_lineterminator(WriterObj *self)
{
Py_ssize_t terminator_len, i;
unsigned int term_kind;
void *term_data;
terminator_len = PyUnicode_GET_LENGTH(self->dialect->lineterminator);
if (terminator_len == -1)
return 0;
/* grow record buffer if necessary */
if (!join_check_rec_size(self, self->rec_len + terminator_len))
return 0;
term_kind = PyUnicode_KIND(self->dialect->lineterminator);
term_data = PyUnicode_DATA(self->dialect->lineterminator);
for (i = 0; i < terminator_len; i++)
self->rec[self->rec_len + i] = PyUnicode_READ(term_kind, term_data, i);
self->rec_len += terminator_len;
return 1;
}
示例15: PyUnicode_INDEX
Py_ssize_t
PyUnicode_INDEX(const char *text, Py_ssize_t index)
{
PyObject *u;
Py_ssize_t i;
/* Prevent excessive micro allocations */
char buffer[256];
size_t buffer_size = Py_ARRAY_LENGTH(buffer);
char *s = buffer;
size_t l;
/* Short-circuit */
if (index == 0)
return 0;
l = strlen(text);
if (index > l)
index = l;
if (index >= buffer_size) {
s = PyMem_RawMalloc(index+1);
if (s == NULL)
return -1;
}
strncpy(s, text, index);
s[index] = '\0';
u = PyUnicode_DECODE(s);
if (s != buffer)
PyMem_RawFree(s);
if (u == NULL)
return -1;
i = PyUnicode_GET_LENGTH(u);
Py_DECREF(u);
return i;
}