Removed mixed tabs and whitespace.

This commit is contained in:
Eric Smith 2009-04-03 11:19:31 +00:00
parent b5292a2e27
commit f8c8b6d3ea
1 changed files with 96 additions and 96 deletions

View File

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