mirror of
https://github.com/python/cpython.git
synced 2024-11-29 12:54:02 +08:00
Removed mixed tabs and whitespace.
This commit is contained in:
parent
b5292a2e27
commit
f8c8b6d3ea
@ -132,7 +132,7 @@ typedef struct {
|
||||
*/
|
||||
static int
|
||||
parse_internal_render_format_spec(STRINGLIB_CHAR *format_spec,
|
||||
Py_ssize_t format_spec_len,
|
||||
Py_ssize_t format_spec_len,
|
||||
InternalFormatSpec *format,
|
||||
char default_type)
|
||||
{
|
||||
@ -178,8 +178,8 @@ parse_internal_render_format_spec(STRINGLIB_CHAR *format_spec,
|
||||
/* If the next character is #, we're in alternate mode. This only
|
||||
applies to integers. */
|
||||
if (end-ptr >= 1 && ptr[0] == '#') {
|
||||
format->alternate = 1;
|
||||
++ptr;
|
||||
format->alternate = 1;
|
||||
++ptr;
|
||||
}
|
||||
|
||||
/* The special case for 0-padding (backwards compat) */
|
||||
@ -259,8 +259,8 @@ typedef struct {
|
||||
and more efficient enough to justify a little obfuscation? */
|
||||
static void
|
||||
calc_number_widths(NumberFieldWidths *spec, STRINGLIB_CHAR actual_sign,
|
||||
Py_ssize_t n_prefix, Py_ssize_t n_digits,
|
||||
const InternalFormatSpec *format)
|
||||
Py_ssize_t n_prefix, Py_ssize_t n_digits,
|
||||
const InternalFormatSpec *format)
|
||||
{
|
||||
spec->n_lpadding = 0;
|
||||
spec->n_prefix = 0;
|
||||
@ -327,7 +327,7 @@ calc_number_widths(NumberFieldWidths *spec, STRINGLIB_CHAR actual_sign,
|
||||
else {
|
||||
/* see if any padding is needed */
|
||||
if (spec->n_lsign + n_digits + spec->n_rsign +
|
||||
spec->n_prefix >= format->width) {
|
||||
spec->n_prefix >= format->width) {
|
||||
/* no padding needed, we're already bigger than the
|
||||
requested width */
|
||||
}
|
||||
@ -335,8 +335,8 @@ calc_number_widths(NumberFieldWidths *spec, STRINGLIB_CHAR actual_sign,
|
||||
/* determine which of left, space, or right padding is
|
||||
needed */
|
||||
Py_ssize_t padding = format->width -
|
||||
(spec->n_lsign + spec->n_prefix +
|
||||
n_digits + spec->n_rsign);
|
||||
(spec->n_lsign + spec->n_prefix +
|
||||
n_digits + spec->n_rsign);
|
||||
if (format->align == '<')
|
||||
spec->n_rpadding = padding;
|
||||
else if (format->align == '>')
|
||||
@ -352,7 +352,7 @@ calc_number_widths(NumberFieldWidths *spec, STRINGLIB_CHAR actual_sign,
|
||||
}
|
||||
}
|
||||
spec->n_total = spec->n_lpadding + spec->n_lsign + spec->n_prefix +
|
||||
spec->n_spadding + n_digits + spec->n_rsign + spec->n_rpadding;
|
||||
spec->n_spadding + n_digits + spec->n_rsign + spec->n_rpadding;
|
||||
}
|
||||
|
||||
/* fill in the non-digit parts of a numbers's string representation,
|
||||
@ -360,8 +360,8 @@ calc_number_widths(NumberFieldWidths *spec, STRINGLIB_CHAR actual_sign,
|
||||
where the digits go. */
|
||||
static STRINGLIB_CHAR *
|
||||
fill_non_digits(STRINGLIB_CHAR *p_buf, const NumberFieldWidths *spec,
|
||||
STRINGLIB_CHAR *prefix, Py_ssize_t n_digits,
|
||||
STRINGLIB_CHAR fill_char)
|
||||
STRINGLIB_CHAR *prefix, Py_ssize_t n_digits,
|
||||
STRINGLIB_CHAR fill_char)
|
||||
{
|
||||
STRINGLIB_CHAR *p_digits;
|
||||
|
||||
@ -373,10 +373,10 @@ fill_non_digits(STRINGLIB_CHAR *p_buf, const NumberFieldWidths *spec,
|
||||
*p_buf++ = spec->lsign;
|
||||
}
|
||||
if (spec->n_prefix) {
|
||||
memmove(p_buf,
|
||||
prefix,
|
||||
spec->n_prefix * sizeof(STRINGLIB_CHAR));
|
||||
p_buf += spec->n_prefix;
|
||||
memmove(p_buf,
|
||||
prefix,
|
||||
spec->n_prefix * sizeof(STRINGLIB_CHAR));
|
||||
p_buf += spec->n_prefix;
|
||||
}
|
||||
if (spec->n_spadding) {
|
||||
STRINGLIB_FILL(p_buf, fill_char, spec->n_spadding);
|
||||
@ -420,7 +420,7 @@ format_string_internal(PyObject *value, const InternalFormatSpec *format)
|
||||
if (format->alternate) {
|
||||
PyErr_SetString(PyExc_ValueError,
|
||||
"Alternate form (#) not allowed in string format "
|
||||
"specifier");
|
||||
"specifier");
|
||||
goto done;
|
||||
}
|
||||
|
||||
@ -504,7 +504,7 @@ typedef PyObject*
|
||||
|
||||
static PyObject *
|
||||
format_int_or_long_internal(PyObject *value, const InternalFormatSpec *format,
|
||||
IntOrLongToString tostring)
|
||||
IntOrLongToString tostring)
|
||||
{
|
||||
PyObject *result = NULL;
|
||||
PyObject *tmp = NULL;
|
||||
@ -516,8 +516,8 @@ format_int_or_long_internal(PyObject *value, const InternalFormatSpec *format,
|
||||
string */
|
||||
Py_ssize_t n_leading_chars;
|
||||
Py_ssize_t n_grouping_chars = 0; /* Count of additional chars to
|
||||
allocate, used for 'n'
|
||||
formatting. */
|
||||
allocate, used for 'n'
|
||||
formatting. */
|
||||
Py_ssize_t n_prefix = 0; /* Count of prefix chars, (e.g., '0x') */
|
||||
STRINGLIB_CHAR *prefix = NULL;
|
||||
NumberFieldWidths spec;
|
||||
@ -562,31 +562,31 @@ format_int_or_long_internal(PyObject *value, const InternalFormatSpec *format,
|
||||
goto done;
|
||||
}
|
||||
#endif
|
||||
numeric_char = (STRINGLIB_CHAR)x;
|
||||
pnumeric_chars = &numeric_char;
|
||||
numeric_char = (STRINGLIB_CHAR)x;
|
||||
pnumeric_chars = &numeric_char;
|
||||
n_digits = 1;
|
||||
}
|
||||
else {
|
||||
int base;
|
||||
int leading_chars_to_skip = 0; /* Number of characters added by
|
||||
PyNumber_ToBase that we want to
|
||||
skip over. */
|
||||
int leading_chars_to_skip = 0; /* Number of characters added by
|
||||
PyNumber_ToBase that we want to
|
||||
skip over. */
|
||||
|
||||
/* Compute the base and how many characters will be added by
|
||||
PyNumber_ToBase */
|
||||
switch (format->type) {
|
||||
case 'b':
|
||||
base = 2;
|
||||
leading_chars_to_skip = 2; /* 0b */
|
||||
leading_chars_to_skip = 2; /* 0b */
|
||||
break;
|
||||
case 'o':
|
||||
base = 8;
|
||||
leading_chars_to_skip = 2; /* 0o */
|
||||
leading_chars_to_skip = 2; /* 0o */
|
||||
break;
|
||||
case 'x':
|
||||
case 'X':
|
||||
base = 16;
|
||||
leading_chars_to_skip = 2; /* 0x */
|
||||
leading_chars_to_skip = 2; /* 0x */
|
||||
break;
|
||||
default: /* shouldn't be needed, but stops a compiler warning */
|
||||
case 'd':
|
||||
@ -595,52 +595,52 @@ format_int_or_long_internal(PyObject *value, const InternalFormatSpec *format,
|
||||
break;
|
||||
}
|
||||
|
||||
/* The number of prefix chars is the same as the leading
|
||||
chars to skip */
|
||||
if (format->alternate)
|
||||
n_prefix = leading_chars_to_skip;
|
||||
/* The number of prefix chars is the same as the leading
|
||||
chars to skip */
|
||||
if (format->alternate)
|
||||
n_prefix = leading_chars_to_skip;
|
||||
|
||||
/* Do the hard part, converting to a string in a given base */
|
||||
tmp = tostring(value, base);
|
||||
tmp = tostring(value, base);
|
||||
if (tmp == NULL)
|
||||
goto done;
|
||||
|
||||
pnumeric_chars = STRINGLIB_STR(tmp);
|
||||
pnumeric_chars = STRINGLIB_STR(tmp);
|
||||
n_digits = STRINGLIB_LEN(tmp);
|
||||
|
||||
prefix = pnumeric_chars;
|
||||
prefix = pnumeric_chars;
|
||||
|
||||
/* Remember not to modify what pnumeric_chars points to. it
|
||||
might be interned. Only modify it after we copy it into a
|
||||
newly allocated output buffer. */
|
||||
/* Remember not to modify what pnumeric_chars points to. it
|
||||
might be interned. Only modify it after we copy it into a
|
||||
newly allocated output buffer. */
|
||||
|
||||
/* Is a sign character present in the output? If so, remember it
|
||||
and skip it */
|
||||
sign = pnumeric_chars[0];
|
||||
if (sign == '-') {
|
||||
++prefix;
|
||||
++leading_chars_to_skip;
|
||||
++prefix;
|
||||
++leading_chars_to_skip;
|
||||
}
|
||||
|
||||
/* Skip over the leading chars (0x, 0b, etc.) */
|
||||
n_digits -= leading_chars_to_skip;
|
||||
pnumeric_chars += leading_chars_to_skip;
|
||||
/* Skip over the leading chars (0x, 0b, etc.) */
|
||||
n_digits -= leading_chars_to_skip;
|
||||
pnumeric_chars += leading_chars_to_skip;
|
||||
}
|
||||
|
||||
if (format->type == 'n')
|
||||
/* Compute how many additional chars we need to allocate
|
||||
to hold the thousands grouping. */
|
||||
STRINGLIB_GROUPING(NULL, n_digits, n_digits,
|
||||
0, &n_grouping_chars, 0);
|
||||
/* Compute how many additional chars we need to allocate
|
||||
to hold the thousands grouping. */
|
||||
STRINGLIB_GROUPING(NULL, n_digits, n_digits,
|
||||
0, &n_grouping_chars, 0);
|
||||
|
||||
/* Calculate the widths of the various leading and trailing parts */
|
||||
calc_number_widths(&spec, sign, n_prefix, n_digits + n_grouping_chars,
|
||||
format);
|
||||
format);
|
||||
|
||||
/* Allocate a new string to hold the result */
|
||||
result = STRINGLIB_NEW(NULL, spec.n_total);
|
||||
if (!result)
|
||||
goto done;
|
||||
goto done;
|
||||
p = STRINGLIB_STR(result);
|
||||
|
||||
/* XXX There is too much magic here regarding the internals of
|
||||
@ -651,44 +651,44 @@ format_int_or_long_internal(PyObject *value, const InternalFormatSpec *format,
|
||||
|
||||
/* Fill in the digit parts */
|
||||
n_leading_chars = spec.n_lpadding + spec.n_lsign +
|
||||
spec.n_prefix + spec.n_spadding;
|
||||
spec.n_prefix + spec.n_spadding;
|
||||
memmove(p + n_leading_chars,
|
||||
pnumeric_chars,
|
||||
n_digits * sizeof(STRINGLIB_CHAR));
|
||||
pnumeric_chars,
|
||||
n_digits * sizeof(STRINGLIB_CHAR));
|
||||
|
||||
/* If type is 'X', convert the filled in digits to uppercase */
|
||||
if (format->type == 'X') {
|
||||
Py_ssize_t t;
|
||||
for (t = 0; t < n_digits; ++t)
|
||||
p[t + n_leading_chars] = STRINGLIB_TOUPPER(p[t + n_leading_chars]);
|
||||
Py_ssize_t t;
|
||||
for (t = 0; t < n_digits; ++t)
|
||||
p[t + n_leading_chars] = STRINGLIB_TOUPPER(p[t + n_leading_chars]);
|
||||
}
|
||||
|
||||
/* Insert the grouping, if any, after the uppercasing of the digits, so
|
||||
we can ensure that grouping chars won't be affected. */
|
||||
if (n_grouping_chars) {
|
||||
/* We know this can't fail, since we've already
|
||||
reserved enough space. */
|
||||
STRINGLIB_CHAR *pstart = p + n_leading_chars;
|
||||
/* We know this can't fail, since we've already
|
||||
reserved enough space. */
|
||||
STRINGLIB_CHAR *pstart = p + n_leading_chars;
|
||||
#ifndef NDEBUG
|
||||
int r =
|
||||
int r =
|
||||
#endif
|
||||
STRINGLIB_GROUPING(pstart, n_digits, n_digits,
|
||||
spec.n_total+n_grouping_chars-n_leading_chars,
|
||||
NULL, 0);
|
||||
assert(r);
|
||||
STRINGLIB_GROUPING(pstart, n_digits, n_digits,
|
||||
spec.n_total+n_grouping_chars-n_leading_chars,
|
||||
NULL, 0);
|
||||
assert(r);
|
||||
}
|
||||
|
||||
/* Fill in the non-digit parts (padding, sign, etc.) */
|
||||
fill_non_digits(p, &spec, prefix, n_digits + n_grouping_chars,
|
||||
format->fill_char == '\0' ? ' ' : format->fill_char);
|
||||
format->fill_char == '\0' ? ' ' : format->fill_char);
|
||||
|
||||
/* If type is 'X', uppercase the prefix. This has to be done after the
|
||||
prefix is filled in by fill_non_digits */
|
||||
if (format->type == 'X') {
|
||||
Py_ssize_t t;
|
||||
for (t = 0; t < n_prefix; ++t)
|
||||
p[t + spec.n_lpadding + spec.n_lsign] =
|
||||
STRINGLIB_TOUPPER(p[t + spec.n_lpadding + spec.n_lsign]);
|
||||
Py_ssize_t t;
|
||||
for (t = 0; t < n_prefix; ++t)
|
||||
p[t + spec.n_lpadding + spec.n_lsign] =
|
||||
STRINGLIB_TOUPPER(p[t + spec.n_lpadding + spec.n_lsign]);
|
||||
}
|
||||
|
||||
|
||||
@ -723,7 +723,7 @@ strtounicode(Py_UNICODE *buffer, const char *charbuffer)
|
||||
/* much of this is taken from unicodeobject.c */
|
||||
static PyObject *
|
||||
format_float_internal(PyObject *value,
|
||||
const InternalFormatSpec *format)
|
||||
const InternalFormatSpec *format)
|
||||
{
|
||||
/* fmt = '%.' + `prec` + `type` + '%%'
|
||||
worst case length = 2 + 10 (len of INT_MAX) + 1 + 2 = 15 (use 20)*/
|
||||
@ -765,7 +765,7 @@ format_float_internal(PyObject *value,
|
||||
if (format->alternate) {
|
||||
PyErr_SetString(PyExc_ValueError,
|
||||
"Alternate form (#) not allowed in float format "
|
||||
"specifier");
|
||||
"specifier");
|
||||
goto done;
|
||||
}
|
||||
|
||||
@ -796,7 +796,7 @@ format_float_internal(PyObject *value,
|
||||
8-bit char. this is safe, because we've restricted what "type"
|
||||
can be */
|
||||
PyOS_snprintf(fmt, sizeof(fmt), "%%.%" PY_FORMAT_SIZE_T "d%c", precision,
|
||||
(char)type);
|
||||
(char)type);
|
||||
|
||||
/* do the actual formatting */
|
||||
PyOS_ascii_formatd(charbuf, sizeof(charbuf), fmt, x);
|
||||
@ -838,11 +838,11 @@ format_float_internal(PyObject *value,
|
||||
|
||||
/* Fill in the non-digit parts (padding, sign, etc.) */
|
||||
fill_non_digits(STRINGLIB_STR(result), &spec, NULL, n_digits,
|
||||
format->fill_char == '\0' ? ' ' : format->fill_char);
|
||||
format->fill_char == '\0' ? ' ' : format->fill_char);
|
||||
|
||||
/* fill in the digit parts */
|
||||
memmove(STRINGLIB_STR(result) +
|
||||
(spec.n_lpadding + spec.n_lsign + spec.n_spadding),
|
||||
(spec.n_lpadding + spec.n_lsign + spec.n_spadding),
|
||||
p,
|
||||
n_digits * sizeof(STRINGLIB_CHAR));
|
||||
|
||||
@ -856,8 +856,8 @@ done:
|
||||
/************************************************************************/
|
||||
PyObject *
|
||||
FORMAT_STRING(PyObject *obj,
|
||||
STRINGLIB_CHAR *format_spec,
|
||||
Py_ssize_t format_spec_len)
|
||||
STRINGLIB_CHAR *format_spec,
|
||||
Py_ssize_t format_spec_len)
|
||||
{
|
||||
InternalFormatSpec format;
|
||||
PyObject *result = NULL;
|
||||
@ -871,7 +871,7 @@ FORMAT_STRING(PyObject *obj,
|
||||
|
||||
/* parse the format_spec */
|
||||
if (!parse_internal_render_format_spec(format_spec, format_spec_len,
|
||||
&format, 's'))
|
||||
&format, 's'))
|
||||
goto done;
|
||||
|
||||
/* type conversion? */
|
||||
@ -893,9 +893,9 @@ done:
|
||||
#if defined FORMAT_LONG || defined FORMAT_INT
|
||||
static PyObject*
|
||||
format_int_or_long(PyObject* obj,
|
||||
STRINGLIB_CHAR *format_spec,
|
||||
Py_ssize_t format_spec_len,
|
||||
IntOrLongToString tostring)
|
||||
STRINGLIB_CHAR *format_spec,
|
||||
Py_ssize_t format_spec_len,
|
||||
IntOrLongToString tostring)
|
||||
{
|
||||
PyObject *result = NULL;
|
||||
PyObject *tmp = NULL;
|
||||
@ -910,8 +910,8 @@ format_int_or_long(PyObject* obj,
|
||||
|
||||
/* parse the format_spec */
|
||||
if (!parse_internal_render_format_spec(format_spec,
|
||||
format_spec_len,
|
||||
&format, 'd'))
|
||||
format_spec_len,
|
||||
&format, 'd'))
|
||||
goto done;
|
||||
|
||||
/* type conversion? */
|
||||
@ -924,8 +924,8 @@ format_int_or_long(PyObject* obj,
|
||||
case 'X':
|
||||
case 'n':
|
||||
/* no type conversion needed, already an int (or long). do
|
||||
the formatting */
|
||||
result = format_int_or_long_internal(obj, &format, tostring);
|
||||
the formatting */
|
||||
result = format_int_or_long_internal(obj, &format, tostring);
|
||||
break;
|
||||
|
||||
case 'e':
|
||||
@ -974,11 +974,11 @@ long_format(PyObject* value, int base)
|
||||
|
||||
PyObject *
|
||||
FORMAT_LONG(PyObject *obj,
|
||||
STRINGLIB_CHAR *format_spec,
|
||||
Py_ssize_t format_spec_len)
|
||||
STRINGLIB_CHAR *format_spec,
|
||||
Py_ssize_t format_spec_len)
|
||||
{
|
||||
return format_int_or_long(obj, format_spec, format_spec_len,
|
||||
long_format);
|
||||
long_format);
|
||||
}
|
||||
#endif /* FORMAT_LONG */
|
||||
|
||||
@ -995,19 +995,19 @@ int_format(PyObject* value, int base)
|
||||
|
||||
PyObject *
|
||||
FORMAT_INT(PyObject *obj,
|
||||
STRINGLIB_CHAR *format_spec,
|
||||
Py_ssize_t format_spec_len)
|
||||
STRINGLIB_CHAR *format_spec,
|
||||
Py_ssize_t format_spec_len)
|
||||
{
|
||||
return format_int_or_long(obj, format_spec, format_spec_len,
|
||||
int_format);
|
||||
int_format);
|
||||
}
|
||||
#endif /* FORMAT_INT */
|
||||
|
||||
#ifdef FORMAT_FLOAT
|
||||
PyObject *
|
||||
FORMAT_FLOAT(PyObject *obj,
|
||||
STRINGLIB_CHAR *format_spec,
|
||||
Py_ssize_t format_spec_len)
|
||||
STRINGLIB_CHAR *format_spec,
|
||||
Py_ssize_t format_spec_len)
|
||||
{
|
||||
PyObject *result = NULL;
|
||||
InternalFormatSpec format;
|
||||
@ -1021,17 +1021,17 @@ FORMAT_FLOAT(PyObject *obj,
|
||||
|
||||
/* parse the format_spec */
|
||||
if (!parse_internal_render_format_spec(format_spec,
|
||||
format_spec_len,
|
||||
&format, '\0'))
|
||||
format_spec_len,
|
||||
&format, '\0'))
|
||||
goto done;
|
||||
|
||||
/* type conversion? */
|
||||
switch (format.type) {
|
||||
case '\0':
|
||||
/* 'Z' means like 'g', but with at least one decimal. See
|
||||
PyOS_ascii_formatd */
|
||||
format.type = 'Z';
|
||||
/* Deliberate fall through to the next case statement */
|
||||
/* 'Z' means like 'g', but with at least one decimal. See
|
||||
PyOS_ascii_formatd */
|
||||
format.type = 'Z';
|
||||
/* Deliberate fall through to the next case statement */
|
||||
case 'e':
|
||||
case 'E':
|
||||
case 'f':
|
||||
|
Loading…
Reference in New Issue
Block a user