mirror of
https://github.com/python/cpython.git
synced 2025-09-27 02:39:58 +00:00
Whitespace normalization
This commit is contained in:
parent
f71ec5a0ac
commit
a7edb11122
1 changed files with 32 additions and 35 deletions
|
@ -1492,7 +1492,6 @@ string_split(PyStringObject *self, PyObject *args)
|
||||||
j = i+pos;
|
j = i+pos;
|
||||||
SPLIT_ADD(s, i, j);
|
SPLIT_ADD(s, i, j);
|
||||||
i = j + n;
|
i = j + n;
|
||||||
|
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
i = j = 0;
|
i = j = 0;
|
||||||
|
@ -1588,7 +1587,7 @@ rsplit_whitespace(const char *s, Py_ssize_t len, Py_ssize_t maxsplit)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
i = j = len-1;
|
i = j = len-1;
|
||||||
|
|
||||||
while (maxsplit-- > 0) {
|
while (maxsplit-- > 0) {
|
||||||
RSKIP_SPACE(s, i);
|
RSKIP_SPACE(s, i);
|
||||||
if (i<0) break;
|
if (i<0) break;
|
||||||
|
@ -2581,12 +2580,12 @@ replace_interleave(PyStringObject *self,
|
||||||
PyStringObject *result;
|
PyStringObject *result;
|
||||||
|
|
||||||
self_len = PyString_GET_SIZE(self);
|
self_len = PyString_GET_SIZE(self);
|
||||||
|
|
||||||
/* 1 at the end plus 1 after every character */
|
/* 1 at the end plus 1 after every character */
|
||||||
count = self_len+1;
|
count = self_len+1;
|
||||||
if (maxcount < count)
|
if (maxcount < count)
|
||||||
count = maxcount;
|
count = maxcount;
|
||||||
|
|
||||||
/* Check for overflow */
|
/* Check for overflow */
|
||||||
/* result_len = count * to_len + self_len; */
|
/* result_len = count * to_len + self_len; */
|
||||||
product = count * to_len;
|
product = count * to_len;
|
||||||
|
@ -2667,7 +2666,7 @@ replace_delete_single_character(PyStringObject *self,
|
||||||
start = next+1;
|
start = next+1;
|
||||||
}
|
}
|
||||||
Py_MEMCPY(result_s, start, end-start);
|
Py_MEMCPY(result_s, start, end-start);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2698,13 +2697,13 @@ replace_delete_substring(PyStringObject *self,
|
||||||
|
|
||||||
result_len = self_len - (count * from_len);
|
result_len = self_len - (count * from_len);
|
||||||
assert (result_len>=0);
|
assert (result_len>=0);
|
||||||
|
|
||||||
if ( (result = (PyStringObject *)
|
if ( (result = (PyStringObject *)
|
||||||
PyString_FromStringAndSize(NULL, result_len)) == NULL )
|
PyString_FromStringAndSize(NULL, result_len)) == NULL )
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
result_s = PyString_AS_STRING(result);
|
result_s = PyString_AS_STRING(result);
|
||||||
|
|
||||||
start = self_s;
|
start = self_s;
|
||||||
end = self_s + self_len;
|
end = self_s + self_len;
|
||||||
while (count-- > 0) {
|
while (count-- > 0) {
|
||||||
|
@ -2714,9 +2713,9 @@ replace_delete_substring(PyStringObject *self,
|
||||||
if (offset == -1)
|
if (offset == -1)
|
||||||
break;
|
break;
|
||||||
next = start + offset;
|
next = start + offset;
|
||||||
|
|
||||||
Py_MEMCPY(result_s, start, next-start);
|
Py_MEMCPY(result_s, start, next-start);
|
||||||
|
|
||||||
result_s += (next-start);
|
result_s += (next-start);
|
||||||
start = next+from_len;
|
start = next+from_len;
|
||||||
}
|
}
|
||||||
|
@ -2733,31 +2732,31 @@ replace_single_character_in_place(PyStringObject *self,
|
||||||
char *self_s, *result_s, *start, *end, *next;
|
char *self_s, *result_s, *start, *end, *next;
|
||||||
Py_ssize_t self_len;
|
Py_ssize_t self_len;
|
||||||
PyStringObject *result;
|
PyStringObject *result;
|
||||||
|
|
||||||
/* The result string will be the same size */
|
/* The result string will be the same size */
|
||||||
self_s = PyString_AS_STRING(self);
|
self_s = PyString_AS_STRING(self);
|
||||||
self_len = PyString_GET_SIZE(self);
|
self_len = PyString_GET_SIZE(self);
|
||||||
|
|
||||||
next = findchar(self_s, self_len, from_c);
|
next = findchar(self_s, self_len, from_c);
|
||||||
|
|
||||||
if (next == NULL) {
|
if (next == NULL) {
|
||||||
/* No matches; return the original string */
|
/* No matches; return the original string */
|
||||||
return return_self(self);
|
return return_self(self);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Need to make a new string */
|
/* Need to make a new string */
|
||||||
result = (PyStringObject *) PyString_FromStringAndSize(NULL, self_len);
|
result = (PyStringObject *) PyString_FromStringAndSize(NULL, self_len);
|
||||||
if (result == NULL)
|
if (result == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
result_s = PyString_AS_STRING(result);
|
result_s = PyString_AS_STRING(result);
|
||||||
Py_MEMCPY(result_s, self_s, self_len);
|
Py_MEMCPY(result_s, self_s, self_len);
|
||||||
|
|
||||||
/* change everything in-place, starting with this one */
|
/* change everything in-place, starting with this one */
|
||||||
start = result_s + (next-self_s);
|
start = result_s + (next-self_s);
|
||||||
*start = to_c;
|
*start = to_c;
|
||||||
start++;
|
start++;
|
||||||
end = result_s + self_len;
|
end = result_s + self_len;
|
||||||
|
|
||||||
while (--maxcount > 0) {
|
while (--maxcount > 0) {
|
||||||
next = findchar(start, end-start, from_c);
|
next = findchar(start, end-start, from_c);
|
||||||
if (next == NULL)
|
if (next == NULL)
|
||||||
|
@ -2765,7 +2764,7 @@ replace_single_character_in_place(PyStringObject *self,
|
||||||
*next = to_c;
|
*next = to_c;
|
||||||
start = next+1;
|
start = next+1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2780,21 +2779,20 @@ replace_substring_in_place(PyStringObject *self,
|
||||||
char *self_s;
|
char *self_s;
|
||||||
Py_ssize_t self_len, offset;
|
Py_ssize_t self_len, offset;
|
||||||
PyStringObject *result;
|
PyStringObject *result;
|
||||||
|
|
||||||
/* The result string will be the same size */
|
/* The result string will be the same size */
|
||||||
|
|
||||||
self_s = PyString_AS_STRING(self);
|
self_s = PyString_AS_STRING(self);
|
||||||
self_len = PyString_GET_SIZE(self);
|
self_len = PyString_GET_SIZE(self);
|
||||||
|
|
||||||
offset = findstring(self_s, self_len,
|
offset = findstring(self_s, self_len,
|
||||||
from_s, from_len,
|
from_s, from_len,
|
||||||
0, self_len, FORWARD);
|
0, self_len, FORWARD);
|
||||||
|
|
||||||
if (offset == -1) {
|
if (offset == -1) {
|
||||||
/* No matches; return the original string */
|
/* No matches; return the original string */
|
||||||
return return_self(self);
|
return return_self(self);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Need to make a new string */
|
/* Need to make a new string */
|
||||||
result = (PyStringObject *) PyString_FromStringAndSize(NULL, self_len);
|
result = (PyStringObject *) PyString_FromStringAndSize(NULL, self_len);
|
||||||
if (result == NULL)
|
if (result == NULL)
|
||||||
|
@ -2807,7 +2805,7 @@ replace_substring_in_place(PyStringObject *self,
|
||||||
Py_MEMCPY(start, to_s, from_len);
|
Py_MEMCPY(start, to_s, from_len);
|
||||||
start += from_len;
|
start += from_len;
|
||||||
end = result_s + self_len;
|
end = result_s + self_len;
|
||||||
|
|
||||||
while ( --maxcount > 0) {
|
while ( --maxcount > 0) {
|
||||||
offset = findstring(start, end-start,
|
offset = findstring(start, end-start,
|
||||||
from_s, from_len,
|
from_s, from_len,
|
||||||
|
@ -2817,7 +2815,7 @@ replace_substring_in_place(PyStringObject *self,
|
||||||
Py_MEMCPY(start+offset, to_s, from_len);
|
Py_MEMCPY(start+offset, to_s, from_len);
|
||||||
start += offset+from_len;
|
start += offset+from_len;
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2833,12 +2831,11 @@ replace_single_character(PyStringObject *self,
|
||||||
Py_ssize_t self_len, result_len;
|
Py_ssize_t self_len, result_len;
|
||||||
Py_ssize_t count, product;
|
Py_ssize_t count, product;
|
||||||
PyStringObject *result;
|
PyStringObject *result;
|
||||||
|
|
||||||
self_s = PyString_AS_STRING(self);
|
self_s = PyString_AS_STRING(self);
|
||||||
self_len = PyString_GET_SIZE(self);
|
self_len = PyString_GET_SIZE(self);
|
||||||
|
|
||||||
count = countchar(self_s, self_len, from_c, maxcount);
|
count = countchar(self_s, self_len, from_c, maxcount);
|
||||||
|
|
||||||
if (count == 0) {
|
if (count == 0) {
|
||||||
/* no matches, return unchanged */
|
/* no matches, return unchanged */
|
||||||
return return_self(self);
|
return return_self(self);
|
||||||
|
@ -2856,19 +2853,19 @@ replace_single_character(PyStringObject *self,
|
||||||
PyErr_SetString(PyExc_OverflowError, "replace string is too long");
|
PyErr_SetString(PyExc_OverflowError, "replace string is too long");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( (result = (PyStringObject *)
|
if ( (result = (PyStringObject *)
|
||||||
PyString_FromStringAndSize(NULL, result_len)) == NULL)
|
PyString_FromStringAndSize(NULL, result_len)) == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
result_s = PyString_AS_STRING(result);
|
result_s = PyString_AS_STRING(result);
|
||||||
|
|
||||||
start = self_s;
|
start = self_s;
|
||||||
end = self_s + self_len;
|
end = self_s + self_len;
|
||||||
while (count-- > 0) {
|
while (count-- > 0) {
|
||||||
next = findchar(start, end-start, from_c);
|
next = findchar(start, end-start, from_c);
|
||||||
if (next == NULL)
|
if (next == NULL)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
if (next == start) {
|
if (next == start) {
|
||||||
/* replace with the 'to' */
|
/* replace with the 'to' */
|
||||||
Py_MEMCPY(result_s, to_s, to_len);
|
Py_MEMCPY(result_s, to_s, to_len);
|
||||||
|
@ -2885,7 +2882,7 @@ replace_single_character(PyStringObject *self,
|
||||||
}
|
}
|
||||||
/* Copy the remainder of the remaining string */
|
/* Copy the remainder of the remaining string */
|
||||||
Py_MEMCPY(result_s, start, end-start);
|
Py_MEMCPY(result_s, start, end-start);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2900,7 +2897,7 @@ replace_substring(PyStringObject *self,
|
||||||
Py_ssize_t self_len, result_len;
|
Py_ssize_t self_len, result_len;
|
||||||
Py_ssize_t count, offset, product;
|
Py_ssize_t count, offset, product;
|
||||||
PyStringObject *result;
|
PyStringObject *result;
|
||||||
|
|
||||||
self_s = PyString_AS_STRING(self);
|
self_s = PyString_AS_STRING(self);
|
||||||
self_len = PyString_GET_SIZE(self);
|
self_len = PyString_GET_SIZE(self);
|
||||||
|
|
||||||
|
@ -2924,12 +2921,12 @@ replace_substring(PyStringObject *self,
|
||||||
PyErr_SetString(PyExc_OverflowError, "replace string is too long");
|
PyErr_SetString(PyExc_OverflowError, "replace string is too long");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( (result = (PyStringObject *)
|
if ( (result = (PyStringObject *)
|
||||||
PyString_FromStringAndSize(NULL, result_len)) == NULL)
|
PyString_FromStringAndSize(NULL, result_len)) == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
result_s = PyString_AS_STRING(result);
|
result_s = PyString_AS_STRING(result);
|
||||||
|
|
||||||
start = self_s;
|
start = self_s;
|
||||||
end = self_s + self_len;
|
end = self_s + self_len;
|
||||||
while (count-- > 0) {
|
while (count-- > 0) {
|
||||||
|
@ -2955,7 +2952,7 @@ replace_substring(PyStringObject *self,
|
||||||
}
|
}
|
||||||
/* Copy the remainder of the remaining string */
|
/* Copy the remainder of the remaining string */
|
||||||
Py_MEMCPY(result_s, start, end-start);
|
Py_MEMCPY(result_s, start, end-start);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2980,7 +2977,7 @@ replace(PyStringObject *self,
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Handle zero-length special cases */
|
/* Handle zero-length special cases */
|
||||||
|
|
||||||
if (from_len == 0) {
|
if (from_len == 0) {
|
||||||
/* insert the 'to' string everywhere. */
|
/* insert the 'to' string everywhere. */
|
||||||
/* >>> "Python".replace("", ".") */
|
/* >>> "Python".replace("", ".") */
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue