mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Revert a part of the previous commit that was left in by mistake and also add a test for handling of positions when the haystack contains non-BMP chars
This commit is contained in:
parent
bd88666bb0
commit
b8e414f18b
@ -160,8 +160,6 @@ static void convert_positions(int32_t *positions, int32_t *final_positions, UCha
|
|||||||
|
|
||||||
if (score == 0.0) { for (i = 0; i < char_len; i++) final_positions[i] = -1; return; }
|
if (score == 0.0) { for (i = 0; i < char_len; i++) final_positions[i] = -1; return; }
|
||||||
|
|
||||||
if (char_len == byte_len) { memcpy(final_positions, positions, sizeof(*positions) * char_len); return; }
|
|
||||||
|
|
||||||
end = final_positions + char_len;
|
end = final_positions + char_len;
|
||||||
for (i = 0; i < byte_len && final_positions < end; i++) {
|
for (i = 0; i < byte_len && final_positions < end; i++) {
|
||||||
if (positions[i] == -1) continue;
|
if (positions[i] == -1) continue;
|
||||||
|
@ -217,14 +217,17 @@ def test2():
|
|||||||
print ('\tns', item, positions)
|
print ('\tns', item, positions)
|
||||||
|
|
||||||
def test():
|
def test():
|
||||||
items = ['m1mn34o/mno', 'xxx/XXX', 'mxnxox']
|
items = ['mx\U0001f431nxox']
|
||||||
for q in (PyScorer, CScorer):
|
for q in (PyScorer, CScorer):
|
||||||
print (q)
|
print (q)
|
||||||
m = Matcher(items, scorer=q)
|
m = Matcher(items, scorer=q)
|
||||||
for item, positions in m('MNO').iteritems():
|
for item, positions in m('MNO').iteritems():
|
||||||
print ('\tMNO', item, positions)
|
print ('\tMNO', item, positions)
|
||||||
for item, positions in m('xxx').iteritems():
|
if -1 not in positions:
|
||||||
print ('\txxx', item, positions)
|
for p in positions:
|
||||||
|
print (item[p], end=' ')
|
||||||
|
print ()
|
||||||
|
|
||||||
|
|
||||||
def test_mem():
|
def test_mem():
|
||||||
from calibre.utils.mem import gc_histogram, diff_hists
|
from calibre.utils.mem import gc_histogram, diff_hists
|
||||||
@ -277,4 +280,5 @@ def main(basedir=None, query=None):
|
|||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
# main(basedir='/t', query='ns')
|
# main(basedir='/t', query='ns')
|
||||||
|
# test()
|
||||||
main()
|
main()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user