本文整理汇总了C++中PyUnicode_CheckExact函数的典型用法代码示例。如果您正苦于以下问题:C++ PyUnicode_CheckExact函数的具体用法?C++ PyUnicode_CheckExact怎么用?C++ PyUnicode_CheckExact使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了PyUnicode_CheckExact函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: BINARY_OPERATION_ADD_UNICODE_UNICODE_INPLACE
bool BINARY_OPERATION_ADD_UNICODE_UNICODE_INPLACE(PyObject **operand1, PyObject *operand2) {
assert(operand1);
CHECK_OBJECT(*operand1);
CHECK_OBJECT(operand2);
assert(PyUnicode_CheckExact(*operand1));
assert(PyUnicode_CheckExact(operand2));
#if PYTHON_VERSION >= 300
if (Py_REFCNT(*operand1) == 1 && !PyUnicode_CHECK_INTERNED(*operand1)) {
// We more or less own the operand, so we might re-use its storage and
// execute stuff in-place.
return UNICODE_ADD_INCREMENTAL(operand1, operand2);
}
#endif
PyObject *result = UNICODE_CONCAT(*operand1, operand2);
if (unlikely(result == NULL)) {
return false;
}
Py_DECREF(*operand1);
*operand1 = result;
return true;
}
开发者ID:kayhayen,项目名称:Nuitka,代码行数:26,代码来源:HelpersOperationBinaryInplaceAdd.c
示例2: _split_u_list
static PyObject*
_split_u_list(PyObject* self, PyObject* arg) {
size_t sLen = 0, splitterLen = 1, maxsplit = 1, index = 0;
Py_UNICODE *src = NULL, *s, *ss, *sEnd = NULL, *sPrev = NULL;
Py_UNICODE defaultSplitter = ',', *splitter = &defaultSplitter, *sp, *spEnd = splitter + splitterLen;
PyObject *list;
PyTupleObject* argTuple = (PyTupleObject*) arg;
if (PyUnicode_CheckExact(argTuple->ob_item[0])) {
src = PyUnicode_AS_UNICODE(argTuple->ob_item[0]);
sLen = PyUnicode_GET_SIZE(argTuple->ob_item[0]);
} else {
return NULL;
}
maxsplit = PyInt_AsSsize_t(argTuple->ob_item[1]);
if (!maxsplit || maxsplit > 100) {
return NULL;
}
if (argTuple->ob_size > 2) {
if (PyUnicode_CheckExact(argTuple->ob_item[2])) {
splitter = PyUnicode_AS_UNICODE(argTuple->ob_item[2]);
splitterLen = PyUnicode_GET_SIZE(argTuple->ob_item[2]);
spEnd = splitter + splitterLen;
} else {
return NULL;
}
}
sPrev = s = src, sEnd = src + sLen;
list = TYPE_NEW(maxsplit);
while (s < sEnd) {
if (*s == *splitter) {
if (splitterLen > 1) {
sp = splitter, ss = s;
while (*++sp == *++ss);
if (sp >= spEnd) {
ADD_U;
if (index >= maxsplit) return list;
sPrev = s + splitterLen;
s += splitterLen;
continue;
}
} else {
ADD_U;
if (index >= maxsplit) return list;
sPrev = s + 1;
}
}
s++;
}
if (index < maxsplit) {
ADD_U;
}
Py_SIZE(list) = index;
return list;
}
开发者ID:S-YOU,项目名称:split,代码行数:58,代码来源:split.c
示例3: inner_atohl
static int
inner_atohl(PyObject *o, unsigned long *ip_ul){
struct in_addr buf;
char *ip_addr;
#ifdef IS_PY3K
if(PyUnicode_CheckExact(o)){
ip_addr = PyUnicode_AsUTF8(o);
} else if (PyBytes_CheckExact(o)){
ip_addr = PyBytes_AsString(o);
} else if (PyByteArray_CheckExact(o)){
ip_addr = PyByteArray_AsString(o);
#else
if(PyUnicode_CheckExact(o) || PyString_CheckExact(o)){
ip_addr = PyString_AsString(o);
} else if (PyByteArray_CheckExact(o)){
ip_addr = PyByteArray_AsString(o);
#endif
} else {
PyErr_SetString(PyExc_TypeError, "should be built-in string/bytes/byte array");
return 0;
}
if (ip_addr == NULL){
return 0;
}
if (inet_aton(ip_addr, &buf)){
*ip_ul = ntohl(buf.s_addr);
return 1;
}else{
PyErr_SetString(PyExc_ValueError,
"illegal IP address string");
return 0;
}
}
static PyObject *
ip_store_atohl(PyObject *self, PyObject *o){
unsigned long ip_ul;
if(inner_atohl(o, &ip_ul)){
return PyLong_FromUnsignedLong(ip_ul);
}else{
return NULL;
}
}
开发者ID:huxt2014,项目名称:python-examples,代码行数:49,代码来源:ip_store.c
示例4: PyObject_Unicode
PyObject *
PyObject_Unicode(PyObject *v)
{
PyObject *res;
PyObject *func;
PyObject *str;
static PyObject *unicodestr;
if (v == NULL) {
res = PyString_FromString("<NULL>");
if (res == NULL)
return NULL;
str = PyUnicode_FromEncodedObject(res, NULL, "strict");
Py_DECREF(res);
return str;
} else if (PyUnicode_CheckExact(v)) {
Py_INCREF(v);
return v;
}
/* XXX As soon as we have a tp_unicode slot, we should
check this before trying the __unicode__
method. */
if (unicodestr == NULL) {
unicodestr= PyString_InternFromString("__unicode__");
if (unicodestr == NULL)
return NULL;
}
func = PyObject_GetAttr(v, unicodestr);
if (func != NULL) {
res = PyEval_CallObject(func, (PyObject *)NULL);
Py_DECREF(func);
}
else {
PyErr_Clear();
if (PyUnicode_Check(v)) {
/* For a Unicode subtype that's didn't overwrite __unicode__,
return a true Unicode object with the same data. */
return PyUnicode_FromUnicode(PyUnicode_AS_UNICODE(v),
PyUnicode_GET_SIZE(v));
}
if (PyString_CheckExact(v)) {
Py_INCREF(v);
res = v;
}
else {
if (v->ob_type->tp_str != NULL)
res = (*v->ob_type->tp_str)(v);
else
res = PyObject_Repr(v);
}
}
if (res == NULL)
return NULL;
if (!PyUnicode_Check(res)) {
str = PyUnicode_FromEncodedObject(res, NULL, "strict");
Py_DECREF(res);
res = str;
}
return res;
}
开发者ID:Charlian,项目名称:python-cobra,代码行数:60,代码来源:object.c
示例5: _psyco_conn_parse_onoff
RAISES_NEG static int
_psyco_conn_parse_onoff(PyObject *pyval)
{
int rv = -1;
Py_INCREF(pyval); /* for ensure_bytes */
if (pyval == Py_None) {
rv = STATE_DEFAULT;
}
else if (PyUnicode_CheckExact(pyval) || Bytes_CheckExact(pyval)) {
if (!(pyval = psycopg_ensure_bytes(pyval))) {
goto exit;
}
if (0 == strcasecmp("default", Bytes_AS_STRING(pyval))) {
rv = STATE_DEFAULT;
}
else {
PyErr_Format(PyExc_ValueError,
"the only string accepted is 'default'; got %s",
Bytes_AS_STRING(pyval));
goto exit;
}
}
else {
int istrue;
if (0 > (istrue = PyObject_IsTrue(pyval))) { goto exit; }
rv = istrue ? STATE_ON : STATE_OFF;
}
exit:
Py_XDECREF(pyval);
return rv;
}
开发者ID:gencer,项目名称:psycopg2,代码行数:35,代码来源:connection_type.c
示例6: TDI_RawNodeType_setitem
static int
TDI_RawNodeType_setitem(rawnodeobject *self, PyObject *key, PyObject *value)
{
PyObject *tmp, *normkey;
tdi_attr_t *item;
int subresult;
if (!(key = ENCODE_NAME(self->node, key)))
return -1;
if (!PyString_CheckExact(key) && !PyString_Check(key)) {
PyErr_SetString(TDI_E_ModelError, "attribute key must be a string");
Py_DECREF(key);
return -1;
}
if (!(normkey = DECODER_NORMALIZE(self->node, key))) {
Py_DECREF(key);
return -1;
}
if (!value) {
subresult = PyDict_DelItem(self->node->attr, normkey);
if (subresult == -1) {
if (PyErr_ExceptionMatches(PyExc_KeyError)) {
PyErr_Clear();
subresult = 0;
}
}
Py_DECREF(normkey);
Py_DECREF(key);
return subresult;
}
if (PyUnicode_CheckExact(value) || PyUnicode_Check(value)) {
if (!(value = ENCODE_UNICODE(self->node, value))) {
Py_DECREF(normkey);
Py_DECREF(key);
return -1;
}
}
else if (!(value = PyObject_Str(value))) {
Py_DECREF(normkey);
Py_DECREF(key);
return -1;
}
item = (tdi_attr_t *)PyDict_GetItem(self->node->attr, normkey);
tmp = tdi_attr_new(item ? item->key : key, value);
Py_DECREF(value);
Py_DECREF(key);
if (!tmp) {
Py_DECREF(normkey);
return -1;
}
subresult = PyDict_SetItem(self->node->attr, normkey, tmp);
Py_DECREF(tmp);
Py_DECREF(normkey);
return subresult;
}
开发者ID:ndparker,项目名称:tdi,代码行数:60,代码来源:raw_node.c
示例7: py_variable_to_json_internal
static void py_variable_to_json_internal( PyObject *obj,
json_writer_t *writer )
{
if ( PyString_CheckExact( obj ) ) {
json_writer_write_str( writer, PyString_AS_STRING( obj ) );
}
else if ( PyInt_CheckExact( obj ) ) {
json_writer_write_integer( writer, PyInt_AS_LONG( obj ) );
}
else if ( PyFloat_CheckExact( obj ) ) {
json_writer_write_number( writer, PyFloat_AS_DOUBLE( obj ) );
}
else if ( PyBool_Check( obj ) ) {
json_writer_write_boolean( writer, ( obj == Py_True ) );
}
else if ( PyUnicode_CheckExact( obj ) ) {
/* Create a new string object that is UTF-8 encoded. */
Py_UNICODE *unicode = PyUnicode_AS_UNICODE( obj );
Py_ssize_t size = PyUnicode_GET_SIZE( obj );
PyObject *str_obj = PyUnicode_EncodeUTF8( unicode, size, NULL );
py_variable_to_json_internal( str_obj, writer );
PyObject_Free( str_obj );
}
else if ( PyDict_CheckExact( obj ) ) {
py_dict_to_json( obj, writer );
}
else if ( PyList_CheckExact( obj ) ) {
py_list_to_json( obj, writer );
}
else if ( PyTuple_CheckExact( obj ) ) {
py_tuple_to_json( obj, writer );
}
}
开发者ID:TheProjecter,项目名称:jxtl,代码行数:33,代码来源:py_util.c
示例8: module_init_dict
static int
module_init_dict(PyModuleObject *mod, PyObject *md_dict,
PyObject *name, PyObject *doc)
{
_Py_IDENTIFIER(__name__);
_Py_IDENTIFIER(__doc__);
_Py_IDENTIFIER(__package__);
_Py_IDENTIFIER(__loader__);
_Py_IDENTIFIER(__spec__);
if (md_dict == NULL)
return -1;
if (doc == NULL)
doc = Py_None;
if (_PyDict_SetItemId(md_dict, &PyId___name__, name) != 0)
return -1;
if (_PyDict_SetItemId(md_dict, &PyId___doc__, doc) != 0)
return -1;
if (_PyDict_SetItemId(md_dict, &PyId___package__, Py_None) != 0)
return -1;
if (_PyDict_SetItemId(md_dict, &PyId___loader__, Py_None) != 0)
return -1;
if (_PyDict_SetItemId(md_dict, &PyId___spec__, Py_None) != 0)
return -1;
if (PyUnicode_CheckExact(name)) {
Py_INCREF(name);
Py_XSETREF(mod->md_name, name);
}
return 0;
}
开发者ID:3lnc,项目名称:cpython,代码行数:32,代码来源:moduleobject.c
示例9: IsNCName
static int IsNCName(PyObject *str)
{
Py_UNICODE *p;
if (!PyUnicode_CheckExact(str)) {
PyErr_Format(PyExc_TypeError,
"argument must be unicode, %.80s found.",
str == Py_None ? "None" : str->ob_type->tp_name);
return -1;
}
p = PyUnicode_AS_UNICODE(str);
if (*p == 0) {
return 0;
}
/* the first character must match NCNameStart */
if (!IS_NCNAMESTART(*p)) {
return 0;
}
/* the remaining characters must match NCNameChar */
for (p++; *p; p++) {
if (!IS_NCNAMECHAR(*p)) {
return 0;
}
}
return 1;
}
开发者ID:H1d3r,项目名称:binary_blobs,代码行数:30,代码来源:xmlstring.c
示例10: module_init_dict
static int
module_init_dict(PyModuleObject *mod, PyObject *md_dict,
PyObject *name, PyObject *doc)
{
if (md_dict == NULL)
return -1;
if (doc == NULL)
doc = Py_None;
if (PyDict_SetItemString(md_dict, "__name__", name) != 0)
return -1;
if (PyDict_SetItemString(md_dict, "__doc__", doc) != 0)
return -1;
if (PyDict_SetItemString(md_dict, "__package__", Py_None) != 0)
return -1;
if (PyDict_SetItemString(md_dict, "__loader__", Py_None) != 0)
return -1;
if (PyDict_SetItemString(md_dict, "__spec__", Py_None) != 0)
return -1;
if (PyUnicode_CheckExact(name)) {
Py_INCREF(name);
Py_XDECREF(mod->md_name);
mod->md_name = name;
}
return 0;
}
开发者ID:1564143452,项目名称:kbengine,代码行数:27,代码来源:moduleobject.c
示例11: IsNmtokens
static int IsNmtokens(PyObject *str)
{
Py_UNICODE *p;
if (!PyUnicode_CheckExact(str)) {
PyErr_Format(PyExc_TypeError,
"argument must be unicode, %.80s found.",
str == Py_None ? "None" : str->ob_type->tp_name);
return -1;
}
p = PyUnicode_AS_UNICODE(str);
if (*p == 0) {
return 0;
}
do {
/* all characters must match NameChar */
for (p++; *p && *p != 0x20; p++) {
if (!IS_NAMECHAR(*p)) {
return 0;
}
}
} while (*p++);
return 1;
}
开发者ID:H1d3r,项目名称:binary_blobs,代码行数:27,代码来源:xmlstring.c
示例12: fp_readl
static char *
fp_readl(char *s, int size, struct tok_state *tok)
{
PyObject* bufobj;
const char *buf;
Py_ssize_t buflen;
/* Ask for one less byte so we can terminate it */
assert(size > 0);
size--;
if (tok->decoding_buffer) {
bufobj = tok->decoding_buffer;
Py_INCREF(bufobj);
}
else
{
bufobj = PyObject_CallObject(tok->decoding_readline, NULL);
if (bufobj == NULL)
goto error;
}
if (PyUnicode_CheckExact(bufobj))
{
buf = _PyUnicode_AsStringAndSize(bufobj, &buflen);
if (buf == NULL) {
goto error;
}
}
else
{
buf = PyByteArray_AsString(bufobj);
if (buf == NULL) {
goto error;
}
buflen = PyByteArray_GET_SIZE(bufobj);
}
Py_XDECREF(tok->decoding_buffer);
if (buflen > size) {
/* Too many chars, the rest goes into tok->decoding_buffer */
tok->decoding_buffer = PyByteArray_FromStringAndSize(buf+size,
buflen-size);
if (tok->decoding_buffer == NULL)
goto error;
buflen = size;
}
else
tok->decoding_buffer = NULL;
memcpy(s, buf, buflen);
s[buflen] = '\0';
if (buflen == 0) /* EOF */
s = NULL;
Py_DECREF(bufobj);
return s;
error:
Py_XDECREF(bufobj);
return error_ret(tok);
}
开发者ID:Martiusweb,项目名称:cpython,代码行数:60,代码来源:tokenizer.c
示例13: _PyUnicode_FormatAdvancedWriter
int
_PyUnicode_FormatAdvancedWriter(_PyUnicodeWriter *writer,
PyObject *obj,
PyObject *format_spec,
Py_ssize_t start, Py_ssize_t end)
{
InternalFormatSpec format;
assert(PyUnicode_Check(obj));
/* check for the special case of zero length format spec, make
it equivalent to str(obj) */
if (start == end) {
if (PyUnicode_CheckExact(obj))
return _PyUnicodeWriter_WriteStr(writer, obj);
else
return format_obj(obj, writer);
}
/* parse the format_spec */
if (!parse_internal_render_format_spec(format_spec, start, end,
&format, 's', '<'))
return -1;
/* type conversion? */
switch (format.type) {
case 's':
/* no type conversion needed, already a string. do the formatting */
return format_string_internal(obj, &format, writer);
default:
/* unknown */
unknown_presentation_type(format.type, obj->ob_type->tp_name);
return -1;
}
}
开发者ID:1564143452,项目名称:kbengine,代码行数:35,代码来源:formatter_unicode.c
示例14: PyFloat_FromString
NUITKA_MAY_BE_UNUSED static PyObject *TO_FLOAT( PyObject *value )
{
PyObject *result;
#if PYTHON_VERSION < 300
if ( PyString_CheckExact( value ) )
{
result = PyFloat_FromString( value, NULL );
}
#else
if ( PyUnicode_CheckExact( value ) )
{
result = PyFloat_FromString( value );
}
#endif
else
{
result = PyNumber_Float( value );
}
if (unlikely( result == NULL ))
{
return NULL;
}
return result;
}
开发者ID:gitter-badger,项目名称:Nuitka,代码行数:27,代码来源:helpers.hpp
示例15: pkey
void pb_num_feature::add_feature(
const std::string& key,
double value,
std::vector<std::pair<std::string, double> >& ret_fv) const {
scoped_gil lk;
pb_object pkey(pb_unicode_from_string(key));
PB_CHECK(pkey,
"cannot convert input key to Python object: " << key);
pb_object pval(PyFloat_FromDouble(value));
PB_CHECK(pval,
"cannot convert input value to Python object for key: " << key);
pb_object ret(PyObject_CallMethodObjArgs(
ins_.get(),
method_.get(),
pkey.get(),
pval.get(),
NULL));
PB_CHECK(ret,
name_ << " method cannot be called");
PB_CHECK(PyList_CheckExact(ret.get()),
name_ << " method returned non-list type: " << pb_str(ret.get()));
size_t size = PyList_Size(ret.get());
for (size_t i = 0; i < size; ++i) {
PyObject* tpl = PyList_GetItem(ret.get(), i);
PB_CHECK(tpl,
"item " << i << " cannot be accessed: "
<< pb_str(ret.get()));
PB_CHECK(PyTuple_CheckExact(tpl),
"list must not contain non-tuple: " << pb_str(tpl));
PB_CHECK(PyTuple_Size(tpl) == 2,
"tuple length must be 2: " << pb_str(tpl));
PyObject* f_key = PyTuple_GetItem(tpl, 0);
PyObject* f_val = PyTuple_GetItem(tpl, 1);
PB_CHECK(PyUnicode_CheckExact(f_key),
"feature key must be a unicode string: " << pb_str(tpl));
PB_CHECK(PyNumber_Check(f_val),
"feature value must be a number: " << pb_str(tpl));
pb_object f_key_enc(PyUnicode_AsUTF8String(f_key));
PB_CHECK(f_key_enc,
"feature key cannot be encoded as UTF-8: "
<< pb_str(tpl));
pb_object f_val_float(PyNumber_Float(f_val));
PB_CHECK(f_val_float,
"value cannot be converted as float: " << pb_str(tpl));
ret_fv.push_back(std::make_pair(
std::string(PyBytes_AsString(f_key_enc.get())),
PyFloat_AsDouble(f_val_float.get())));
}
}
开发者ID:jubatus,项目名称:jubatus,代码行数:58,代码来源:pb_num_feature.cpp
示例16: BINARY_OPERATION_ADD_UNICODE_OBJECT_INPLACE
bool BINARY_OPERATION_ADD_UNICODE_OBJECT_INPLACE(PyObject **operand1, PyObject *operand2) {
assert(operand1);
CHECK_OBJECT(*operand1);
CHECK_OBJECT(operand2);
assert(PyUnicode_CheckExact(*operand1));
if (likely(PyUnicode_CheckExact(operand2))) {
#if PYTHON_VERSION >= 300
if (Py_REFCNT(*operand1) == 1 && !PyUnicode_CHECK_INTERNED(*operand1)) {
// We more or less own the operand, so we might re-use its storage and
// execute stuff in-place.
return UNICODE_ADD_INCREMENTAL(operand1, operand2);
}
#endif
PyObject *result = UNICODE_CONCAT(*operand1, operand2);
if (unlikely(result == NULL)) {
return false;
}
Py_DECREF(*operand1);
*operand1 = result;
return true;
}
PyObject *result = PyNumber_InPlaceAdd(*operand1, operand2);
if (unlikely(result == NULL)) {
return false;
}
// We got an object handed, that we have to release.
Py_DECREF(*operand1);
// That's our return value then. As we use a dedicated variable, it's
// OK that way.
*operand1 = result;
return true;
}
开发者ID:kayhayen,项目名称:Nuitka,代码行数:42,代码来源:HelpersOperationBinaryInplaceAdd.c
示例17: microprotocol_getquoted
PyObject *
microprotocol_getquoted(PyObject *obj, connectionObject *conn)
{
PyObject *res = NULL;
PyObject *prepare = NULL;
PyObject *adapted;
if (!(adapted = microprotocols_adapt(obj, (PyObject*)&isqlquoteType, NULL))) {
goto exit;
}
Dprintf("microprotocol_getquoted: adapted to %s",
Py_TYPE(adapted)->tp_name);
/* if requested prepare the object passing it the connection */
if (conn) {
if ((prepare = PyObject_GetAttrString(adapted, "prepare"))) {
res = PyObject_CallFunctionObjArgs(
prepare, (PyObject *)conn, NULL);
if (res) {
Py_DECREF(res);
res = NULL;
} else {
goto exit;
}
}
else {
/* adapted.prepare not found */
PyErr_Clear();
}
}
/* call the getquoted method on adapted (that should exist because we
adapted to the right protocol) */
res = PyObject_CallMethod(adapted, "getquoted", NULL);
/* Convert to bytes. */
if (res && PyUnicode_CheckExact(res)) {
PyObject *b;
const char *codec;
codec = (conn && conn->codec) ? conn->codec : "utf8";
b = PyUnicode_AsEncodedString(res, codec, NULL);
Py_DECREF(res);
res = b;
}
exit:
Py_XDECREF(adapted);
Py_XDECREF(prepare);
/* we return res with one extra reference, the caller shall free it */
return res;
}
开发者ID:AnthonyBRoberts,项目名称:eeditionautomate,代码行数:53,代码来源:microprotocols.c
示例18: intern_strings
static void
intern_strings(PyObject *tuple)
{
Py_ssize_t i;
for (i = PyTuple_GET_SIZE(tuple); --i >= 0; ) {
PyObject *v = PyTuple_GET_ITEM(tuple, i);
if (v == NULL || !PyUnicode_CheckExact(v)) {
Py_FatalError("non-string found in code slot");
}
PyUnicode_InternInPlace(&PyTuple_GET_ITEM(tuple, i));
}
}
开发者ID:TruckHacking,项目名称:J1939Python,代码行数:13,代码来源:codeobject.c
示例19: unquote_internal_unicode
static PyObject *
unquote_internal_unicode(PyObject *string, int plus)
{
PyObject *result;
Py_UNICODE *su, *ru;
Py_ssize_t j, slen, tlen, sentinel;
if (!PyUnicode_CheckExact(string)) {
if (!(string = PyObject_Unicode(string)))
return NULL;
}
else
Py_INCREF(string);
su = PyUnicode_AS_UNICODE(string);
slen = tlen = PyUnicode_GET_SIZE(string);
for (j=0, sentinel=slen-2; j<sentinel; ++j) {
if ( WTF_IS_LATIN1(su[j]) && (su[j] & 0xFF) == '%'
&& WTF_IS_LATIN1(su[j+1]) && WTF_IS_HEX_DIGIT(su[j+1])
&& WTF_IS_LATIN1(su[j+2]) && WTF_IS_HEX_DIGIT(su[j+2])) {
tlen -= 2;
j += 2;
}
}
if (slen == tlen && !plus) /* shortcut: nothing to unquote */
return string;
if (!(result = PyUnicode_FromUnicode(NULL, tlen)))
goto done;
ru = PyUnicode_AS_UNICODE(result);
for (j=0, sentinel=slen-2; j<slen; ++j) {
if ( j < sentinel && WTF_IS_LATIN1(su[j]) && (su[j] & 0xFF) == '%'
&& WTF_IS_LATIN1(su[j+1]) && WTF_IS_HEX_DIGIT(su[j+1])
&& WTF_IS_LATIN1(su[j+2]) && WTF_IS_HEX_DIGIT(su[j+2])) {
*ru++ = (WTF_HEX_VALUE(su[j+1]) << 4)
+ (WTF_HEX_VALUE(su[j+2]));
j += 2;
}
else if (plus && su[j] == (unsigned char)'+') {
*ru++ = (unsigned char)' ';
}
else {
*ru++ = su[j];
}
}
done:
Py_DECREF(string);
return result;
}
开发者ID:wontfix-org,项目名称:wtf,代码行数:51,代码来源:util.c
示例20: while
static PyObject *NormalizeSpace(PyObject *str)
{
Py_UNICODE *start, *end, *p;
PyObject *result;
if (!PyUnicode_CheckExact(str)) {
PyErr_SetString(PyExc_TypeError, "unicode object expected");
return NULL;
}
start = PyUnicode_AS_UNICODE(str);
end = start + PyUnicode_GET_SIZE(str);
/* look for runs of contiguous whitespace */
for (p = start; p < end; p++) {
if (IS_XMLSPACE(p[0]) && IS_XMLSPACE(p[1])) break;
}
if (p == end && !IS_XMLSPACE(start[0]) && !IS_XMLSPACE(end[-1])) {
/* no whitespace to remove; return original string */
Py_INCREF(str);
return str;
}
/* skip over leading whitespace */
while (start < end && IS_XMLSPACE(start[0])) start++;
/* skip over trailing whitespace */
while (end > start && IS_XMLSPACE(end[-1])) end--;
/* create the result string (it may be shrunk later) */
result = PyUnicode_FromUnicode(start, (Py_ssize_t)(end - start));
if (result) {
start = PyUnicode_AS_UNICODE(result);
end = start + PyUnicode_GET_SIZE(result);
for (p = start; p < end; p++) {
if (IS_XMLSPACE(*p)) {
/* replace contiguous whitespace with a single space */
*start++ = 0x20;
p++;
while (p < end && IS_XMLSPACE(*p)) p++;
}
*start++ = *p;
}
if (start != end) {
Py_ssize_t newsize = (Py_ssize_t)(start - PyUnicode_AS_UNICODE(result));
if (PyUnicode_Resize(&result, newsize) < 0) {
Py_DECREF(result);
return NULL;
}
}
}
return result;
}
开发者ID:H1d3r,项目名称:binary_blobs,代码行数:50,代码来源:xmlstring.c
注:本文中的PyUnicode_CheckExact函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论