mirror of
https://github.com/kovidgoyal/calibre.git
synced 2026-04-12 20:22:07 -04:00
Cleanup copilot code
This commit is contained in:
parent
267a89a0dd
commit
86e2403595
@ -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);
|
||||
|
||||
@ -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):
|
||||
|
||||
@ -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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user