Cleanup copilot code

This commit is contained in:
Kovid Goyal 2026-03-16 13:41:59 +05:30
parent 267a89a0dd
commit 86e2403595
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
3 changed files with 11 additions and 4 deletions

View File

@ -1666,15 +1666,13 @@ icu_word_prefix_find(PyObject *self, PyObject *args) {
x_icu = python_to_icu(x_, &xsz);
if (x_icu == NULL) return NULL;
it->counter++;
if (it->text != NULL) { free(it->text); it->text = NULL; it->text_len = 0; }
ubrk_setText(it->break_iterator, x_icu, xsz, &status);
if (U_FAILURE(status)) {
free(x_icu);
PyErr_SetString(PyExc_ValueError, u_errorName(status));
return NULL;
}
it->text = x_icu; it->text_len = xsz;
x_icu = NULL; // ownership transferred to it->text
free(it->text); it->text = x_icu; it->text_len = xsz; x_icu = NULL; // ownership transferred to it->text
// Convert prefix to ICU once
prefix_icu = python_to_icu(prefix_, &prefix_sz);

View File

@ -239,7 +239,15 @@ startswith = make_two_arg_func(collator, 'startswith')
primary_startswith = make_two_arg_func(primary_collator, 'startswith')
safe_chr = _icu.chr
ord_string = _icu.ord_string
word_prefix_find = _icu.word_prefix_find
try:
word_prefix_find = _icu.word_prefix_find
except AttributeError: # people running from source
def word_prefix_find(collator, it, x, prefix):
it.set_text(x)
for pos, size in it.split2():
if collator.startswith(x, prefix, pos):
return pos
return -1
def character_name(string):

View File

@ -287,6 +287,7 @@ class TestICU(unittest.TestCase):
self.ae(wpf(c, it, 'hello world', 'he'), 0)
self.ae(wpf(c, it, 'hello world', 'world'), 6)
self.ae(wpf(c, it, 'hello world', 'hello'), 0)
self.ae(wpf(c, it, 'masi asim', 'asi'), 5)
# No match returns -1
self.ae(wpf(c, it, 'hello world', 'xyz'), -1)
# Case-insensitive match with primary collator