@@ -9576,6 +9576,24 @@ 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_casefold (int kind , void * data , Py_ssize_t length , Py_UCS4 * res , Py_UCS4 * maxchar )
9581+ {
9582+ Py_ssize_t i , k = 0 ;
9583+
9584+ for (i = 0 ; i < length ; i ++ ) {
9585+ Py_UCS4 c = PyUnicode_READ (kind , data , i );
9586+ Py_UCS4 mapped [3 ];
9587+ int j , n_res = _PyUnicode_ToFoldedFull (c , mapped );
9588+ for (j = 0 ; j < n_res ; j ++ ) {
9589+ if (mapped [j ] > * maxchar )
9590+ * maxchar = mapped [j ];
9591+ res [k ++ ] = mapped [j ];
9592+ }
9593+ }
9594+ return k ;
9595+ }
9596+
95799597static Py_ssize_t
95809598do_title (int kind , void * data , Py_ssize_t length , Py_UCS4 * res , Py_UCS4 * maxchar )
95819599{
@@ -10501,6 +10519,22 @@ unicode_capitalize(PyObject *self)
1050110519 return case_operation (self , do_capitalize );
1050210520}
1050310521
10522+ PyDoc_STRVAR (casefold__doc__ ,
10523+ "S.casefold() -> str\n\
10524+ \n\
10525+ Return a version of S suitable for caseless comparisons." );
10526+
10527+ static PyObject *
10528+ unicode_casefold (PyObject * self )
10529+ {
10530+ if (PyUnicode_READY (self ) == -1 )
10531+ return NULL ;
10532+ if (PyUnicode_IS_ASCII (self ))
10533+ return ascii_upper_or_lower (self , 1 );
10534+ return case_operation (self , do_casefold );
10535+ }
10536+
10537+
1050410538/* Argument converter. Coerces to a single unicode character */
1050510539
1050610540static int
@@ -12998,6 +13032,7 @@ static PyMethodDef unicode_methods[] = {
1299813032 {"rsplit" , (PyCFunction ) unicode_rsplit , METH_VARARGS , rsplit__doc__ },
1299913033 {"join" , (PyCFunction ) unicode_join , METH_O , join__doc__ },
1300013034 {"capitalize" , (PyCFunction ) unicode_capitalize , METH_NOARGS , capitalize__doc__ },
13035+ {"casefold" , (PyCFunction ) unicode_casefold , METH_NOARGS , casefold__doc__ },
1300113036 {"title" , (PyCFunction ) unicode_title , METH_NOARGS , title__doc__ },
1300213037 {"center" , (PyCFunction ) unicode_center , METH_VARARGS , center__doc__ },
1300313038 {"count" , (PyCFunction ) unicode_count , METH_VARARGS , count__doc__ },
0 commit comments