mirror of https://github.com/python/cpython
Remove 'const' from local variable declaration in string_zfill() -- it
isn't constant, so why bother. Folded long lines. Whitespace normalization.
This commit is contained in:
parent
068325ef92
commit
3aa3fc46c8
|
@ -1,4 +1,3 @@
|
||||||
|
|
||||||
/* String object implementation */
|
/* String object implementation */
|
||||||
|
|
||||||
#include "Python.h"
|
#include "Python.h"
|
||||||
|
@ -25,21 +24,22 @@ static PyStringObject *nullstring;
|
||||||
string containing exactly `size' bytes.
|
string containing exactly `size' bytes.
|
||||||
|
|
||||||
For PyString_FromStringAndSize(), the parameter the parameter `str' is
|
For PyString_FromStringAndSize(), the parameter the parameter `str' is
|
||||||
either NULL or else points to a string containing at least `size' bytes. For
|
either NULL or else points to a string containing at least `size' bytes.
|
||||||
PyString_FromStringAndSize(), the string in the `str' parameter does not
|
For PyString_FromStringAndSize(), the string in the `str' parameter does
|
||||||
have to be null-terminated. (Therefore it is safe to construct a substring
|
not have to be null-terminated. (Therefore it is safe to construct a
|
||||||
by calling `PyString_FromStringAndSize(origstring, substrlen)'.) If `str'
|
substring by calling `PyString_FromStringAndSize(origstring, substrlen)'.)
|
||||||
is NULL then PyString_FromStringAndSize() will allocate `size+1' bytes
|
If `str' is NULL then PyString_FromStringAndSize() will allocate `size+1'
|
||||||
(setting the last byte to the null terminating character) and you can fill in
|
bytes (setting the last byte to the null terminating character) and you can
|
||||||
the data yourself. If `str' is non-NULL then the resulting PyString object
|
fill in the data yourself. If `str' is non-NULL then the resulting
|
||||||
must be treated as immutable and you must not fill in nor alter the data
|
PyString object must be treated as immutable and you must not fill in nor
|
||||||
yourself, since the strings may be shared.
|
alter the data yourself, since the strings may be shared.
|
||||||
|
|
||||||
The PyObject member `op->ob_size', which denotes the number of "extra items"
|
The PyObject member `op->ob_size', which denotes the number of "extra
|
||||||
in a variable-size object, will contain the number of bytes allocated for
|
items" in a variable-size object, will contain the number of bytes
|
||||||
string data, not counting the null terminating character. It is therefore
|
allocated for string data, not counting the null terminating character. It
|
||||||
equal to the equal to the `size' parameter (for PyString_FromStringAndSize())
|
is therefore equal to the equal to the `size' parameter (for
|
||||||
or the length of the string in the `str' parameter (for PyString_FromString()).
|
PyString_FromStringAndSize()) or the length of the string in the `str'
|
||||||
|
parameter (for PyString_FromString()).
|
||||||
*/
|
*/
|
||||||
PyObject *
|
PyObject *
|
||||||
PyString_FromStringAndSize(const char *str, int size)
|
PyString_FromStringAndSize(const char *str, int size)
|
||||||
|
@ -586,7 +586,8 @@ string_print(PyStringObject *op, FILE *fp, int flags)
|
||||||
|
|
||||||
/* figure out which quote to use; single is preferred */
|
/* figure out which quote to use; single is preferred */
|
||||||
quote = '\'';
|
quote = '\'';
|
||||||
if (memchr(op->ob_sval, '\'', op->ob_size) && !memchr(op->ob_sval, '"', op->ob_size))
|
if (memchr(op->ob_sval, '\'', op->ob_size) &&
|
||||||
|
!memchr(op->ob_sval, '"', op->ob_size))
|
||||||
quote = '"';
|
quote = '"';
|
||||||
|
|
||||||
fputc(quote, fp);
|
fputc(quote, fp);
|
||||||
|
@ -630,7 +631,8 @@ string_repr(register PyStringObject *op)
|
||||||
|
|
||||||
/* figure out which quote to use; single is preferred */
|
/* figure out which quote to use; single is preferred */
|
||||||
quote = '\'';
|
quote = '\'';
|
||||||
if (memchr(op->ob_sval, '\'', op->ob_size) && !memchr(op->ob_sval, '"', op->ob_size))
|
if (memchr(op->ob_sval, '\'', op->ob_size) &&
|
||||||
|
!memchr(op->ob_sval, '"', op->ob_size))
|
||||||
quote = '"';
|
quote = '"';
|
||||||
|
|
||||||
p = PyString_AS_STRING(v);
|
p = PyString_AS_STRING(v);
|
||||||
|
@ -2392,7 +2394,7 @@ string_zfill(PyStringObject *self, PyObject *args)
|
||||||
{
|
{
|
||||||
int fill;
|
int fill;
|
||||||
PyObject *s;
|
PyObject *s;
|
||||||
const char *p;
|
char *p;
|
||||||
|
|
||||||
int width;
|
int width;
|
||||||
if (!PyArg_ParseTuple(args, "i:zfill", &width))
|
if (!PyArg_ParseTuple(args, "i:zfill", &width))
|
||||||
|
@ -2749,9 +2751,11 @@ string_methods[] = {
|
||||||
{"istitle", (PyCFunction)string_istitle, METH_NOARGS, istitle__doc__},
|
{"istitle", (PyCFunction)string_istitle, METH_NOARGS, istitle__doc__},
|
||||||
{"isalpha", (PyCFunction)string_isalpha, METH_NOARGS, isalpha__doc__},
|
{"isalpha", (PyCFunction)string_isalpha, METH_NOARGS, isalpha__doc__},
|
||||||
{"isalnum", (PyCFunction)string_isalnum, METH_NOARGS, isalnum__doc__},
|
{"isalnum", (PyCFunction)string_isalnum, METH_NOARGS, isalnum__doc__},
|
||||||
{"capitalize", (PyCFunction)string_capitalize, METH_NOARGS, capitalize__doc__},
|
{"capitalize", (PyCFunction)string_capitalize, METH_NOARGS,
|
||||||
|
capitalize__doc__},
|
||||||
{"count", (PyCFunction)string_count, METH_VARARGS, count__doc__},
|
{"count", (PyCFunction)string_count, METH_VARARGS, count__doc__},
|
||||||
{"endswith", (PyCFunction)string_endswith, METH_VARARGS, endswith__doc__},
|
{"endswith", (PyCFunction)string_endswith, METH_VARARGS,
|
||||||
|
endswith__doc__},
|
||||||
{"find", (PyCFunction)string_find, METH_VARARGS, find__doc__},
|
{"find", (PyCFunction)string_find, METH_VARARGS, find__doc__},
|
||||||
{"index", (PyCFunction)string_index, METH_VARARGS, index__doc__},
|
{"index", (PyCFunction)string_index, METH_VARARGS, index__doc__},
|
||||||
{"lstrip", (PyCFunction)string_lstrip, METH_VARARGS, lstrip__doc__},
|
{"lstrip", (PyCFunction)string_lstrip, METH_VARARGS, lstrip__doc__},
|
||||||
|
@ -2759,10 +2763,13 @@ string_methods[] = {
|
||||||
{"rfind", (PyCFunction)string_rfind, METH_VARARGS, rfind__doc__},
|
{"rfind", (PyCFunction)string_rfind, METH_VARARGS, rfind__doc__},
|
||||||
{"rindex", (PyCFunction)string_rindex, METH_VARARGS, rindex__doc__},
|
{"rindex", (PyCFunction)string_rindex, METH_VARARGS, rindex__doc__},
|
||||||
{"rstrip", (PyCFunction)string_rstrip, METH_VARARGS, rstrip__doc__},
|
{"rstrip", (PyCFunction)string_rstrip, METH_VARARGS, rstrip__doc__},
|
||||||
{"startswith", (PyCFunction)string_startswith, METH_VARARGS, startswith__doc__},
|
{"startswith", (PyCFunction)string_startswith, METH_VARARGS,
|
||||||
|
startswith__doc__},
|
||||||
{"strip", (PyCFunction)string_strip, METH_VARARGS, strip__doc__},
|
{"strip", (PyCFunction)string_strip, METH_VARARGS, strip__doc__},
|
||||||
{"swapcase", (PyCFunction)string_swapcase, METH_NOARGS, swapcase__doc__},
|
{"swapcase", (PyCFunction)string_swapcase, METH_NOARGS,
|
||||||
{"translate", (PyCFunction)string_translate, METH_VARARGS, translate__doc__},
|
swapcase__doc__},
|
||||||
|
{"translate", (PyCFunction)string_translate, METH_VARARGS,
|
||||||
|
translate__doc__},
|
||||||
{"title", (PyCFunction)string_title, METH_NOARGS, title__doc__},
|
{"title", (PyCFunction)string_title, METH_NOARGS, title__doc__},
|
||||||
{"ljust", (PyCFunction)string_ljust, METH_VARARGS, ljust__doc__},
|
{"ljust", (PyCFunction)string_ljust, METH_VARARGS, ljust__doc__},
|
||||||
{"rjust", (PyCFunction)string_rjust, METH_VARARGS, rjust__doc__},
|
{"rjust", (PyCFunction)string_rjust, METH_VARARGS, rjust__doc__},
|
||||||
|
@ -2770,11 +2777,10 @@ string_methods[] = {
|
||||||
{"zfill", (PyCFunction)string_zfill, METH_VARARGS, zfill__doc__},
|
{"zfill", (PyCFunction)string_zfill, METH_VARARGS, zfill__doc__},
|
||||||
{"encode", (PyCFunction)string_encode, METH_VARARGS, encode__doc__},
|
{"encode", (PyCFunction)string_encode, METH_VARARGS, encode__doc__},
|
||||||
{"decode", (PyCFunction)string_decode, METH_VARARGS, decode__doc__},
|
{"decode", (PyCFunction)string_decode, METH_VARARGS, decode__doc__},
|
||||||
{"expandtabs", (PyCFunction)string_expandtabs, METH_VARARGS, expandtabs__doc__},
|
{"expandtabs", (PyCFunction)string_expandtabs, METH_VARARGS,
|
||||||
{"splitlines", (PyCFunction)string_splitlines, METH_VARARGS, splitlines__doc__},
|
expandtabs__doc__},
|
||||||
#if 0
|
{"splitlines", (PyCFunction)string_splitlines, METH_VARARGS,
|
||||||
{"zfill", (PyCFunction)string_zfill, METH_VARARGS, zfill__doc__},
|
splitlines__doc__},
|
||||||
#endif
|
|
||||||
{NULL, NULL} /* sentinel */
|
{NULL, NULL} /* sentinel */
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -3280,7 +3286,8 @@ PyString_Format(PyObject *format, PyObject *args)
|
||||||
char *pbuf;
|
char *pbuf;
|
||||||
int sign;
|
int sign;
|
||||||
int len;
|
int len;
|
||||||
char formatbuf[FORMATBUFLEN]; /* For format{float,int,char}() */
|
char formatbuf[FORMATBUFLEN];
|
||||||
|
/* For format{float,int,char}() */
|
||||||
#ifdef Py_USING_UNICODE
|
#ifdef Py_USING_UNICODE
|
||||||
char *fmt_start = fmt;
|
char *fmt_start = fmt;
|
||||||
int argidx_start = argidx;
|
int argidx_start = argidx;
|
||||||
|
@ -3478,7 +3485,8 @@ PyString_Format(PyObject *format, PyObject *args)
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
pbuf = formatbuf;
|
pbuf = formatbuf;
|
||||||
len = formatint(pbuf, sizeof(formatbuf),
|
len = formatint(pbuf,
|
||||||
|
sizeof(formatbuf),
|
||||||
flags, prec, c, v);
|
flags, prec, c, v);
|
||||||
if (len < 0)
|
if (len < 0)
|
||||||
goto error;
|
goto error;
|
||||||
|
@ -3494,7 +3502,8 @@ PyString_Format(PyObject *format, PyObject *args)
|
||||||
case 'g':
|
case 'g':
|
||||||
case 'G':
|
case 'G':
|
||||||
pbuf = formatbuf;
|
pbuf = formatbuf;
|
||||||
len = formatfloat(pbuf, sizeof(formatbuf), flags, prec, c, v);
|
len = formatfloat(pbuf, sizeof(formatbuf),
|
||||||
|
flags, prec, c, v);
|
||||||
if (len < 0)
|
if (len < 0)
|
||||||
goto error;
|
goto error;
|
||||||
sign = 1;
|
sign = 1;
|
||||||
|
|
Loading…
Reference in New Issue