j = i+pos;
SPLIT_ADD(s, i, j);
i = j + n;
-
}
#else
i = j = 0;
return NULL;
i = j = len-1;
-
+
while (maxsplit-- > 0) {
RSKIP_SPACE(s, i);
if (i<0) break;
PyStringObject *result;
self_len = PyString_GET_SIZE(self);
-
+
/* 1 at the end plus 1 after every character */
count = self_len+1;
if (maxcount < count)
count = maxcount;
-
+
/* Check for overflow */
/* result_len = count * to_len + self_len; */
product = count * to_len;
start = next+1;
}
Py_MEMCPY(result_s, start, end-start);
-
+
return result;
}
result_len = self_len - (count * from_len);
assert (result_len>=0);
-
+
if ( (result = (PyStringObject *)
PyString_FromStringAndSize(NULL, result_len)) == NULL )
return NULL;
-
+
result_s = PyString_AS_STRING(result);
-
+
start = self_s;
end = self_s + self_len;
while (count-- > 0) {
if (offset == -1)
break;
next = start + offset;
-
+
Py_MEMCPY(result_s, start, next-start);
-
+
result_s += (next-start);
start = next+from_len;
}
char *self_s, *result_s, *start, *end, *next;
Py_ssize_t self_len;
PyStringObject *result;
-
+
/* The result string will be the same size */
self_s = PyString_AS_STRING(self);
self_len = PyString_GET_SIZE(self);
-
+
next = findchar(self_s, self_len, from_c);
-
+
if (next == NULL) {
/* No matches; return the original string */
return return_self(self);
}
-
+
/* Need to make a new string */
result = (PyStringObject *) PyString_FromStringAndSize(NULL, self_len);
if (result == NULL)
return NULL;
result_s = PyString_AS_STRING(result);
Py_MEMCPY(result_s, self_s, self_len);
-
+
/* change everything in-place, starting with this one */
start = result_s + (next-self_s);
*start = to_c;
start++;
end = result_s + self_len;
-
+
while (--maxcount > 0) {
next = findchar(start, end-start, from_c);
if (next == NULL)
*next = to_c;
start = next+1;
}
-
+
return result;
}
char *self_s;
Py_ssize_t self_len, offset;
PyStringObject *result;
-
+
/* The result string will be the same size */
-
+
self_s = PyString_AS_STRING(self);
self_len = PyString_GET_SIZE(self);
offset = findstring(self_s, self_len,
from_s, from_len,
0, self_len, FORWARD);
-
if (offset == -1) {
/* No matches; return the original string */
return return_self(self);
}
-
+
/* Need to make a new string */
result = (PyStringObject *) PyString_FromStringAndSize(NULL, self_len);
if (result == NULL)
Py_MEMCPY(start, to_s, from_len);
start += from_len;
end = result_s + self_len;
-
+
while ( --maxcount > 0) {
offset = findstring(start, end-start,
from_s, from_len,
Py_MEMCPY(start+offset, to_s, from_len);
start += offset+from_len;
}
-
+
return result;
}
Py_ssize_t self_len, result_len;
Py_ssize_t count, product;
PyStringObject *result;
-
+
self_s = PyString_AS_STRING(self);
self_len = PyString_GET_SIZE(self);
-
+
count = countchar(self_s, self_len, from_c, maxcount);
-
if (count == 0) {
/* no matches, return unchanged */
return return_self(self);
PyErr_SetString(PyExc_OverflowError, "replace string is too long");
return NULL;
}
-
+
if ( (result = (PyStringObject *)
PyString_FromStringAndSize(NULL, result_len)) == NULL)
return NULL;
result_s = PyString_AS_STRING(result);
-
+
start = self_s;
end = self_s + self_len;
while (count-- > 0) {
next = findchar(start, end-start, from_c);
if (next == NULL)
break;
-
+
if (next == start) {
/* replace with the 'to' */
Py_MEMCPY(result_s, to_s, to_len);
}
/* Copy the remainder of the remaining string */
Py_MEMCPY(result_s, start, end-start);
-
+
return result;
}
Py_ssize_t self_len, result_len;
Py_ssize_t count, offset, product;
PyStringObject *result;
-
+
self_s = PyString_AS_STRING(self);
self_len = PyString_GET_SIZE(self);
PyErr_SetString(PyExc_OverflowError, "replace string is too long");
return NULL;
}
-
+
if ( (result = (PyStringObject *)
PyString_FromStringAndSize(NULL, result_len)) == NULL)
return NULL;
result_s = PyString_AS_STRING(result);
-
+
start = self_s;
end = self_s + self_len;
while (count-- > 0) {
}
/* Copy the remainder of the remaining string */
Py_MEMCPY(result_s, start, end-start);
-
+
return result;
}
}
/* Handle zero-length special cases */
-
+
if (from_len == 0) {
/* insert the 'to' string everywhere. */
/* >>> "Python".replace("", ".") */