cinap_lenrekadd hg and python4bb9e2215 years agoHistory
5009 lines · 120.0 KB · C
RawDownload
} PyDoc_STRVAR(isspace__doc__,"S.isspace() -> bool\n\\n\Return True if all characters in S are whitespace\n\and there is at least one character in S, False otherwise."); static PyObject*string_isspace(PyStringObject *self){    register const unsigned char *p        = (unsigned char *) PyString_AS_STRING(self);    register const unsigned char *e;     /* Shortcut for single character strings */    if (PyString_GET_SIZE(self) == 1 &&	isspace(*p))	return PyBool_FromLong(1);     /* Special case for empty strings */    if (PyString_GET_SIZE(self) == 0)	return PyBool_FromLong(0);     e = p + PyString_GET_SIZE(self);    for (; p < e; p++) {	if (!isspace(*p))	    return PyBool_FromLong(0);    }    return PyBool_FromLong(1);}  PyDoc_STRVAR(isalpha__doc__,"S.isalpha() -> bool\n\\n\Return True if all characters in S are alphabetic\n\and there is at least one character in S, False otherwise."); static PyObject*string_isalpha(PyStringObject *self){    register const unsigned char *p        = (unsigned char *) PyString_AS_STRING(self);    register const unsigned char *e;     /* Shortcut for single character strings */    if (PyString_GET_SIZE(self) == 1 &&	isalpha(*p))	return PyBool_FromLong(1);     /* Special case for empty strings */    if (PyString_GET_SIZE(self) == 0)	return PyBool_FromLong(0);     e = p + PyString_GET_SIZE(self);    for (; p < e; p++) {	if (!isalpha(*p))	    return PyBool_FromLong(0);    }    return PyBool_FromLong(1);}  PyDoc_STRVAR(isalnum__doc__,"S.isalnum() -> bool\n\\n\Return True if all characters in S are alphanumeric\n\and there is at least one character in S, False otherwise."); static PyObject*string_isalnum(PyStringObject *self){    register const unsigned char *p        = (unsigned char *) PyString_AS_STRING(self);    register const unsigned char *e;     /* Shortcut for single character strings */    if (PyString_GET_SIZE(self) == 1 &&	isalnum(*p))	return PyBool_FromLong(1);     /* Special case for empty strings */    if (PyString_GET_SIZE(self) == 0)	return PyBool_FromLong(0);     e = p + PyString_GET_SIZE(self);    for (; p < e; p++) {	if (!isalnum(*p))	    return PyBool_FromLong(0);    }    return PyBool_FromLong(1);}  PyDoc_STRVAR(isdigit__doc__,"S.isdigit() -> bool\n\\n\Return True if all characters in S are digits\n\and there is at least one character in S, False otherwise."); static PyObject*string_isdigit(PyStringObject *self){    register const unsigned char *p        = (unsigned char *) PyString_AS_STRING(self);    register const unsigned char *e;     /* Shortcut for single character strings */    if (PyString_GET_SIZE(self) == 1 &&	isdigit(*p))	return PyBool_FromLong(1);     /* Special case for empty strings */    if (PyString_GET_SIZE(self) == 0)	return PyBool_FromLong(0);     e = p + PyString_GET_SIZE(self);    for (; p < e; p++) {	if (!isdigit(*p))	    return PyBool_FromLong(0);    }    return PyBool_FromLong(1);}  PyDoc_STRVAR(islower__doc__,"S.islower() -> bool\n\\n\Return True if all cased characters in S are lowercase and there is\n\at least one cased character in S, False otherwise."); static PyObject*string_islower(PyStringObject *self){    register const unsigned char *p        = (unsigned char *) PyString_AS_STRING(self);    register const unsigned char *e;    int cased;     /* Shortcut for single character strings */    if (PyString_GET_SIZE(self) == 1)	return PyBool_FromLong(islower(*p) != 0);     /* Special case for empty strings */    if (PyString_GET_SIZE(self) == 0)	return PyBool_FromLong(0);     e = p + PyString_GET_SIZE(self);    cased = 0;    for (; p < e; p++) {	if (isupper(*p))	    return PyBool_FromLong(0);	else if (!cased && islower(*p))	    cased = 1;    }    return PyBool_FromLong(cased);}  PyDoc_STRVAR(isupper__doc__,"S.isupper() -> bool\n\\n\Return True if all cased characters in S are uppercase and there is\n\at least one cased character in S, False otherwise."); static PyObject*string_isupper(PyStringObject *self){    register const unsigned char *p        = (unsigned char *) PyString_AS_STRING(self);    register const unsigned char *e;    int cased;     /* Shortcut for single character strings */    if (PyString_GET_SIZE(self) == 1)	return PyBool_FromLong(isupper(*p) != 0);     /* Special case for empty strings */    if (PyString_GET_SIZE(self) == 0)	return PyBool_FromLong(0);     e = p + PyString_GET_SIZE(self);    cased = 0;    for (; p < e; p++) {	if (islower(*p))	    return PyBool_FromLong(0);	else if (!cased && isupper(*p))	    cased = 1;    }    return PyBool_FromLong(cased);}  PyDoc_STRVAR(istitle__doc__,"S.istitle() -> bool\n\\n\Return True if S is a titlecased string and there is at least one\n\character in S, i.e. uppercase characters may only follow uncased\n\characters and lowercase characters only cased ones. Return False\n\otherwise."); static PyObject*string_istitle(PyStringObject *self, PyObject *uncased){    register const unsigned char *p        = (unsigned char *) PyString_AS_STRING(self);    register const unsigned char *e;    int cased, previous_is_cased;     /* Shortcut for single character strings */    if (PyString_GET_SIZE(self) == 1)	return PyBool_FromLong(isupper(*p) != 0);     /* Special case for empty strings */    if (PyString_GET_SIZE(self) == 0)	return PyBool_FromLong(0);     e = p + PyString_GET_SIZE(self);    cased = 0;    previous_is_cased = 0;    for (; p < e; p++) {	register const unsigned char ch = *p; 	if (isupper(ch)) {	    if (previous_is_cased)		return PyBool_FromLong(0);	    previous_is_cased = 1;	    cased = 1;	}	else if (islower(ch)) {	    if (!previous_is_cased)		return PyBool_FromLong(0);	    previous_is_cased = 1;	    cased = 1;	}	else	    previous_is_cased = 0;    }    return PyBool_FromLong(cased);}  PyDoc_STRVAR(splitlines__doc__,"S.splitlines([keepends]) -> list of strings\n\\n\Return a list of the lines in S, breaking at line boundaries.\n\Line breaks are not included in the resulting list unless keepends\n\is given and true."); static PyObject*string_splitlines(PyStringObject *self, PyObject *args){    register Py_ssize_t i;    register Py_ssize_t j;    Py_ssize_t len;    int keepends = 0;    PyObject *list;    PyObject *str;    char *data;     if (!PyArg_ParseTuple(args, "|i:splitlines", &keepends))        return NULL;     data = PyString_AS_STRING(self);    len = PyString_GET_SIZE(self);     /* This does not use the preallocated list because splitlines is       usually run with hundreds of newlines.  The overhead of       switching between PyList_SET_ITEM and append causes about a       2-3% slowdown for that common case.  A smarter implementation       could move the if check out, so the SET_ITEMs are done first       and the appends only done when the prealloc buffer is full.       That's too much work for little gain.*/     list = PyList_New(0);    if (!list)        goto onError;     for (i = j = 0; i < len; ) {	Py_ssize_t eol; 	/* Find a line and append it */	while (i < len && data[i] != '\n' && data[i] != '\r')	    i++; 	/* Skip the line break reading CRLF as one line break */	eol = i;	if (i < len) {	    if (data[i] == '\r' && i + 1 < len &&		data[i+1] == '\n')		i += 2;	    else		i++;	    if (keepends)		eol = i;	}	SPLIT_APPEND(data, j, eol);	j = i;    }    if (j < len) {	SPLIT_APPEND(data, j, len);    }     return list;  onError:    Py_XDECREF(list);    return NULL;} #undef SPLIT_APPEND#undef SPLIT_ADD#undef MAX_PREALLOC#undef PREALLOC_SIZE static PyObject *string_getnewargs(PyStringObject *v){	return Py_BuildValue("(s#)", v->ob_sval, v->ob_size);} static PyMethodDefstring_methods[] = {	/* Counterparts of the obsolete stropmodule functions; except	   string.maketrans(). */	{"join", (PyCFunction)string_join, METH_O, join__doc__},	{"split", (PyCFunction)string_split, METH_VARARGS, split__doc__},	{"rsplit", (PyCFunction)string_rsplit, METH_VARARGS, rsplit__doc__},	{"lower", (PyCFunction)string_lower, METH_NOARGS, lower__doc__},	{"upper", (PyCFunction)string_upper, METH_NOARGS, upper__doc__},	{"islower", (PyCFunction)string_islower, METH_NOARGS, islower__doc__},	{"isupper", (PyCFunction)string_isupper, METH_NOARGS, isupper__doc__},	{"isspace", (PyCFunction)string_isspace, METH_NOARGS, isspace__doc__},	{"isdigit", (PyCFunction)string_isdigit, METH_NOARGS, isdigit__doc__},	{"istitle", (PyCFunction)string_istitle, METH_NOARGS, istitle__doc__},	{"isalpha", (PyCFunction)string_isalpha, METH_NOARGS, isalpha__doc__},	{"isalnum", (PyCFunction)string_isalnum, METH_NOARGS, isalnum__doc__},	{"capitalize", (PyCFunction)string_capitalize, METH_NOARGS,	 capitalize__doc__},	{"count", (PyCFunction)string_count, METH_VARARGS, count__doc__},	{"endswith", (PyCFunction)string_endswith, METH_VARARGS,	 endswith__doc__},	{"partition", (PyCFunction)string_partition, METH_O, partition__doc__},	{"find", (PyCFunction)string_find, METH_VARARGS, find__doc__},	{"index", (PyCFunction)string_index, METH_VARARGS, index__doc__},	{"lstrip", (PyCFunction)string_lstrip, METH_VARARGS, lstrip__doc__},	{"replace", (PyCFunction)string_replace, METH_VARARGS, replace__doc__},	{"rfind", (PyCFunction)string_rfind, METH_VARARGS, rfind__doc__},	{"rindex", (PyCFunction)string_rindex, METH_VARARGS, rindex__doc__},	{"rstrip", (PyCFunction)string_rstrip, METH_VARARGS, rstrip__doc__},	{"rpartition", (PyCFunction)string_rpartition, METH_O,	 rpartition__doc__},	{"startswith", (PyCFunction)string_startswith, METH_VARARGS,	 startswith__doc__},	{"strip", (PyCFunction)string_strip, METH_VARARGS, strip__doc__},	{"swapcase", (PyCFunction)string_swapcase, METH_NOARGS,	 swapcase__doc__},	{"translate", (PyCFunction)string_translate, METH_VARARGS,	 translate__doc__},	{"title", (PyCFunction)string_title, METH_NOARGS, title__doc__},	{"ljust", (PyCFunction)string_ljust, METH_VARARGS, ljust__doc__},	{"rjust", (PyCFunction)string_rjust, METH_VARARGS, rjust__doc__},	{"center", (PyCFunction)string_center, METH_VARARGS, center__doc__},	{"zfill", (PyCFunction)string_zfill, METH_VARARGS, zfill__doc__},	{"encode", (PyCFunction)string_encode, METH_VARARGS, encode__doc__},	{"decode", (PyCFunction)string_decode, METH_VARARGS, decode__doc__},	{"expandtabs", (PyCFunction)string_expandtabs, METH_VARARGS,	 expandtabs__doc__},	{"splitlines", (PyCFunction)string_splitlines, METH_VARARGS,	 splitlines__doc__},	{"__getnewargs__",	(PyCFunction)string_getnewargs,	METH_NOARGS},	{NULL,     NULL}		     /* sentinel */}; static PyObject *str_subtype_new(PyTypeObject *type, PyObject *args, PyObject *kwds); static PyObject *string_new(PyTypeObject *type, PyObject *args, PyObject *kwds){	PyObject *x = NULL;	static char *kwlist[] = {"object", 0}; 	if (type != &PyString_Type)		return str_subtype_new(type, args, kwds);	if (!PyArg_ParseTupleAndKeywords(args, kwds, "|O:str", kwlist, &x))		return NULL;	if (x == NULL)		return PyString_FromString("");	return PyObject_Str(x);} static PyObject *str_subtype_new(PyTypeObject *type, PyObject *args, PyObject *kwds){	PyObject *tmp, *pnew;	Py_ssize_t n; 	assert(PyType_IsSubtype(type, &PyString_Type));	tmp = string_new(&PyString_Type, args, kwds);	if (tmp == NULL)		return NULL;	assert(PyString_CheckExact(tmp));	n = PyString_GET_SIZE(tmp);	pnew = type->tp_alloc(type, n);	if (pnew != NULL) {		Py_MEMCPY(PyString_AS_STRING(pnew), PyString_AS_STRING(tmp), n+1);		((PyStringObject *)pnew)->ob_shash =			((PyStringObject *)tmp)->ob_shash;		((PyStringObject *)pnew)->ob_sstate = SSTATE_NOT_INTERNED;	}	Py_DECREF(tmp);	return pnew;} static PyObject *basestring_new(PyTypeObject *type, PyObject *args, PyObject *kwds){	PyErr_SetString(PyExc_TypeError,			"The basestring type cannot be instantiated");	return NULL;} static PyObject *string_mod(PyObject *v, PyObject *w){	if (!PyString_Check(v)) {		Py_INCREF(Py_NotImplemented);		return Py_NotImplemented;	}	return PyString_Format(v, w);} PyDoc_STRVAR(basestring_doc,"Type basestring cannot be instantiated; it is the base for str and unicode."); static PyNumberMethods string_as_number = {	0,			/*nb_add*/	0,			/*nb_subtract*/	0,			/*nb_multiply*/	0, 			/*nb_divide*/	string_mod,		/*nb_remainder*/};  PyTypeObject PyBaseString_Type = {	PyObject_HEAD_INIT(&PyType_Type)	0,	"basestring",	0,	0, 	0,			 		/* tp_dealloc */	0,			 		/* tp_print */	0,					/* tp_getattr */	0,					/* tp_setattr */	0,					/* tp_compare */	0,		 			/* tp_repr */	0,					/* tp_as_number */	0,					/* tp_as_sequence */	0,					/* tp_as_mapping */	0,		 			/* tp_hash */	0,					/* tp_call */	0,					/* tp_str */	0,					/* tp_getattro */	0,					/* tp_setattro */	0,					/* tp_as_buffer */	Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */	basestring_doc,				/* tp_doc */	0,					/* tp_traverse */	0,					/* tp_clear */	0,					/* tp_richcompare */	0,					/* tp_weaklistoffset */	0,					/* tp_iter */	0,					/* tp_iternext */	0,					/* tp_methods */	0,					/* tp_members */	0,					/* tp_getset */	&PyBaseObject_Type,			/* tp_base */	0,					/* tp_dict */	0,					/* tp_descr_get */	0,					/* tp_descr_set */	0,					/* tp_dictoffset */	0,					/* tp_init */	0,					/* tp_alloc */	basestring_new,				/* tp_new */	0,		                	/* tp_free */}; PyDoc_STRVAR(string_doc,"str(object) -> string\n\\n\Return a nice string representation of the object.\n\If the argument is a string, the return value is the same object."); PyTypeObject PyString_Type = {	PyObject_HEAD_INIT(&PyType_Type)	0,	"str",

Lines 3501–4000 of 5009. Previous lines