Skip to content

Commit e51757f

Browse files
committed
move do_title to a better place
1 parent 3a5d4cb commit e51757f

File tree

1 file changed

+28
-28
lines changed

1 file changed

+28
-28
lines changed

Objects/unicodeobject.c

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -9576,6 +9576,34 @@ do_lower(int kind, void *data, Py_ssize_t length, Py_UCS4 *res, Py_UCS4 *maxchar
95769576
return do_upper_or_lower(kind, data, length, res, maxchar, 1);
95779577
}
95789578

9579+
static Py_ssize_t
9580+
do_title(int kind, void *data, Py_ssize_t length, Py_UCS4 *res, Py_UCS4 *maxchar)
9581+
{
9582+
Py_ssize_t i, k = 0;
9583+
int previous_is_cased;
9584+
9585+
previous_is_cased = 0;
9586+
for (i = 0; i < length; i++) {
9587+
const Py_UCS4 c = PyUnicode_READ(kind, data, i);
9588+
Py_UCS4 mapped[3];
9589+
int n_res, j;
9590+
9591+
if (previous_is_cased)
9592+
n_res = lower_ucs4(kind, data, length, i, c, mapped);
9593+
else
9594+
n_res = _PyUnicode_ToTitleFull(c, mapped);
9595+
9596+
for (j = 0; j < n_res; j++) {
9597+
if (mapped[j] > *maxchar)
9598+
*maxchar = mapped[j];
9599+
res[k++] = mapped[j];
9600+
}
9601+
9602+
previous_is_cased = _PyUnicode_IsCased(c);
9603+
}
9604+
return k;
9605+
}
9606+
95799607
static PyObject *
95809608
case_operation(PyObject *self,
95819609
Py_ssize_t (*perform)(int, void *, Py_ssize_t, Py_UCS4 *, Py_UCS4 *))
@@ -9621,34 +9649,6 @@ case_operation(PyObject *self,
96219649
return res;
96229650
}
96239651

9624-
static Py_ssize_t
9625-
do_title(int kind, void *data, Py_ssize_t length, Py_UCS4 *res, Py_UCS4 *maxchar)
9626-
{
9627-
Py_ssize_t i, k = 0;
9628-
int previous_is_cased;
9629-
9630-
previous_is_cased = 0;
9631-
for (i = 0; i < length; i++) {
9632-
const Py_UCS4 c = PyUnicode_READ(kind, data, i);
9633-
Py_UCS4 mapped[3];
9634-
int n_res, j;
9635-
9636-
if (previous_is_cased)
9637-
n_res = lower_ucs4(kind, data, length, i, c, mapped);
9638-
else
9639-
n_res = _PyUnicode_ToTitleFull(c, mapped);
9640-
9641-
for (j = 0; j < n_res; j++) {
9642-
if (mapped[j] > *maxchar)
9643-
*maxchar = mapped[j];
9644-
res[k++] = mapped[j];
9645-
}
9646-
9647-
previous_is_cased = _PyUnicode_IsCased(c);
9648-
}
9649-
return k;
9650-
}
9651-
96529652
PyObject *
96539653
PyUnicode_Join(PyObject *separator, PyObject *seq)
96549654
{

0 commit comments

Comments
 (0)