Wrap the api to control the max variable for collation

This commit is contained in:
Kovid Goyal 2022-04-23 13:25:22 +05:30
parent ef41db8cc7
commit 50f4b86f9e
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 31 additions and 0 deletions

View File

@ -118,6 +118,25 @@ icu_Collator_set_numeric(icu_Collator *self, PyObject *val, void *closure) {
} }
// }}} // }}}
// Collator.numeric {{{
static PyObject *
icu_Collator_get_max_variable(icu_Collator *self, void *closure) {
return Py_BuildValue("i", ucol_getMaxVariable(self->collator));
}
static int
icu_Collator_set_max_variable(icu_Collator *self, PyObject *val, void *closure) {
int group = PyLong_AsLong(val);
UErrorCode status = U_ZERO_ERROR;
ucol_setMaxVariable(self->collator, group, &status);
if (U_FAILURE(status)) {
PyErr_SetString(PyExc_ValueError, u_errorName(status));
return -1;
}
return 0;
}
// }}}
// Collator.actual_locale {{{ // Collator.actual_locale {{{
static PyObject * static PyObject *
icu_Collator_actual_locale(icu_Collator *self, void *closure) { icu_Collator_actual_locale(icu_Collator *self, void *closure) {
@ -483,6 +502,12 @@ static PyGetSetDef icu_Collator_getsetters[] = {
(char *)"If True the collator sorts contiguous digits as numbers rather than strings, so 2 will sort before 10.", (char *)"If True the collator sorts contiguous digits as numbers rather than strings, so 2 will sort before 10.",
NULL}, NULL},
{(char *)"max_variable",
(getter)icu_Collator_get_max_variable, (setter)icu_Collator_set_max_variable,
(char *)"The highest sorting character affected by alternate handling",
NULL},
{NULL} /* Sentinel */ {NULL} /* Sentinel */
}; };
@ -1511,6 +1536,11 @@ exec_module(PyObject *mod) {
ADDUCONST(UCOL_DECOMPOSITION_MODE); ADDUCONST(UCOL_DECOMPOSITION_MODE);
ADDUCONST(UCOL_STRENGTH); ADDUCONST(UCOL_STRENGTH);
ADDUCONST(UCOL_NUMERIC_COLLATION); ADDUCONST(UCOL_NUMERIC_COLLATION);
ADDUCONST(UCOL_REORDER_CODE_SPACE);
ADDUCONST(UCOL_REORDER_CODE_PUNCTUATION);
ADDUCONST(UCOL_REORDER_CODE_SYMBOL);
ADDUCONST(UCOL_REORDER_CODE_CURRENCY);
ADDUCONST(UCOL_REORDER_CODE_DEFAULT);
ADDUCONST(NFD); ADDUCONST(NFD);
ADDUCONST(NFKD); ADDUCONST(NFKD);

View File

@ -117,6 +117,7 @@ class TestICU(unittest.TestCase):
self.ae((0, 4), icu.primary_no_punc_find('pena"', 'peña')) self.ae((0, 4), icu.primary_no_punc_find('pena"', 'peña'))
self.ae((0, 13), icu.primary_no_punc_find("typographers", 'typographers')) self.ae((0, 13), icu.primary_no_punc_find("typographers", 'typographers'))
self.ae((0, 7), icu.primary_no_punc_find('abcd', 'a\u00adb\u200cc\u200dd')) self.ae((0, 7), icu.primary_no_punc_find('abcd', 'a\u00adb\u200cc\u200dd'))
self.ae((0, 5), icu.primary_no_punc_find('abcd', 'ab cd'))
def test_collation_order(self): def test_collation_order(self):
'Testing collation ordering' 'Testing collation ordering'