mirror of
https://github.com/python/cpython.git
synced 2025-08-19 00:00:48 +00:00
Recorded merge of revisions 81029 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk ........ r81029 | antoine.pitrou | 2010-05-09 16:46:46 +0200 (dim., 09 mai 2010) | 3 lines Untabify C files. Will watch buildbots. ........
This commit is contained in:
parent
ba32864b2d
commit
c7c96a90bc
321 changed files with 195492 additions and 195492 deletions
|
@ -34,97 +34,97 @@
|
|||
**/
|
||||
int
|
||||
_Py_InsertThousandsGrouping(STRINGLIB_CHAR *buffer,
|
||||
Py_ssize_t n_buffer,
|
||||
Py_ssize_t n_digits,
|
||||
Py_ssize_t buf_size,
|
||||
Py_ssize_t *count,
|
||||
int append_zero_char)
|
||||
Py_ssize_t n_buffer,
|
||||
Py_ssize_t n_digits,
|
||||
Py_ssize_t buf_size,
|
||||
Py_ssize_t *count,
|
||||
int append_zero_char)
|
||||
{
|
||||
struct lconv *locale_data = localeconv();
|
||||
const char *grouping = locale_data->grouping;
|
||||
const char *thousands_sep = locale_data->thousands_sep;
|
||||
Py_ssize_t thousands_sep_len = strlen(thousands_sep);
|
||||
STRINGLIB_CHAR *pend = NULL; /* current end of buffer */
|
||||
STRINGLIB_CHAR *pmax = NULL; /* max of buffer */
|
||||
char current_grouping;
|
||||
Py_ssize_t remaining = n_digits; /* Number of chars remaining to
|
||||
be looked at */
|
||||
struct lconv *locale_data = localeconv();
|
||||
const char *grouping = locale_data->grouping;
|
||||
const char *thousands_sep = locale_data->thousands_sep;
|
||||
Py_ssize_t thousands_sep_len = strlen(thousands_sep);
|
||||
STRINGLIB_CHAR *pend = NULL; /* current end of buffer */
|
||||
STRINGLIB_CHAR *pmax = NULL; /* max of buffer */
|
||||
char current_grouping;
|
||||
Py_ssize_t remaining = n_digits; /* Number of chars remaining to
|
||||
be looked at */
|
||||
|
||||
/* Initialize the character count, if we're just counting. */
|
||||
if (count)
|
||||
*count = 0;
|
||||
else {
|
||||
/* We're not just counting, we're modifying buffer */
|
||||
pend = buffer + n_buffer;
|
||||
pmax = buffer + buf_size;
|
||||
}
|
||||
/* Initialize the character count, if we're just counting. */
|
||||
if (count)
|
||||
*count = 0;
|
||||
else {
|
||||
/* We're not just counting, we're modifying buffer */
|
||||
pend = buffer + n_buffer;
|
||||
pmax = buffer + buf_size;
|
||||
}
|
||||
|
||||
/* Starting at the end and working right-to-left, keep track of
|
||||
what grouping needs to be added and insert that. */
|
||||
current_grouping = *grouping++;
|
||||
/* Starting at the end and working right-to-left, keep track of
|
||||
what grouping needs to be added and insert that. */
|
||||
current_grouping = *grouping++;
|
||||
|
||||
/* If the first character is 0, perform no grouping at all. */
|
||||
if (current_grouping == 0)
|
||||
return 1;
|
||||
/* If the first character is 0, perform no grouping at all. */
|
||||
if (current_grouping == 0)
|
||||
return 1;
|
||||
|
||||
while (remaining > current_grouping) {
|
||||
/* Always leave buffer and pend valid at the end of this
|
||||
loop, since we might leave with a return statement. */
|
||||
while (remaining > current_grouping) {
|
||||
/* Always leave buffer and pend valid at the end of this
|
||||
loop, since we might leave with a return statement. */
|
||||
|
||||
remaining -= current_grouping;
|
||||
if (count) {
|
||||
/* We're only counting, not touching the memory. */
|
||||
*count += thousands_sep_len;
|
||||
}
|
||||
else {
|
||||
/* Do the formatting. */
|
||||
remaining -= current_grouping;
|
||||
if (count) {
|
||||
/* We're only counting, not touching the memory. */
|
||||
*count += thousands_sep_len;
|
||||
}
|
||||
else {
|
||||
/* Do the formatting. */
|
||||
|
||||
STRINGLIB_CHAR *plast = buffer + remaining;
|
||||
STRINGLIB_CHAR *plast = buffer + remaining;
|
||||
|
||||
/* Is there room to insert thousands_sep_len chars? */
|
||||
if (pmax - pend < thousands_sep_len)
|
||||
/* No room. */
|
||||
return 0;
|
||||
/* Is there room to insert thousands_sep_len chars? */
|
||||
if (pmax - pend < thousands_sep_len)
|
||||
/* No room. */
|
||||
return 0;
|
||||
|
||||
/* Move the rest of the string down. */
|
||||
memmove(plast + thousands_sep_len,
|
||||
plast,
|
||||
(pend - plast) * sizeof(STRINGLIB_CHAR));
|
||||
/* Copy the thousands_sep chars into the buffer. */
|
||||
/* Move the rest of the string down. */
|
||||
memmove(plast + thousands_sep_len,
|
||||
plast,
|
||||
(pend - plast) * sizeof(STRINGLIB_CHAR));
|
||||
/* Copy the thousands_sep chars into the buffer. */
|
||||
#if STRINGLIB_IS_UNICODE
|
||||
/* Convert from the char's of the thousands_sep from
|
||||
the locale into unicode. */
|
||||
{
|
||||
Py_ssize_t i;
|
||||
for (i = 0; i < thousands_sep_len; ++i)
|
||||
plast[i] = thousands_sep[i];
|
||||
}
|
||||
/* Convert from the char's of the thousands_sep from
|
||||
the locale into unicode. */
|
||||
{
|
||||
Py_ssize_t i;
|
||||
for (i = 0; i < thousands_sep_len; ++i)
|
||||
plast[i] = thousands_sep[i];
|
||||
}
|
||||
#else
|
||||
/* No conversion, just memcpy the thousands_sep. */
|
||||
memcpy(plast, thousands_sep, thousands_sep_len);
|
||||
/* No conversion, just memcpy the thousands_sep. */
|
||||
memcpy(plast, thousands_sep, thousands_sep_len);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
/* Adjust end pointer. */
|
||||
pend += thousands_sep_len;
|
||||
/* Adjust end pointer. */
|
||||
pend += thousands_sep_len;
|
||||
|
||||
/* Move to the next grouping character, unless we're
|
||||
repeating (which is designated by a grouping of 0). */
|
||||
if (*grouping != 0) {
|
||||
current_grouping = *grouping++;
|
||||
if (current_grouping == CHAR_MAX)
|
||||
/* We're done. */
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (append_zero_char) {
|
||||
/* Append a zero character to mark the end of the string,
|
||||
if there's room. */
|
||||
if (pend - (buffer + remaining) < 1)
|
||||
/* No room, error. */
|
||||
return 0;
|
||||
*pend = 0;
|
||||
}
|
||||
return 1;
|
||||
/* Move to the next grouping character, unless we're
|
||||
repeating (which is designated by a grouping of 0). */
|
||||
if (*grouping != 0) {
|
||||
current_grouping = *grouping++;
|
||||
if (current_grouping == CHAR_MAX)
|
||||
/* We're done. */
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (append_zero_char) {
|
||||
/* Append a zero character to mark the end of the string,
|
||||
if there's room. */
|
||||
if (pend - (buffer + remaining) < 1)
|
||||
/* No room, error. */
|
||||
return 0;
|
||||
*pend = 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
#endif /* STRINGLIB_LOCALEUTIL_H */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue