mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Viewer: When searching have single and double quotes match their curly variants as well. Fixes #1861715 [searching for contractions doesn't recognize typewriter apostrophes](https://bugs.launchpad.net/calibre/+bug/1861715)
This commit is contained in:
parent
49defc9a13
commit
ebea435ad5
@ -50,6 +50,21 @@ class BusySpinner(QWidget): # {{{
|
||||
# }}}
|
||||
|
||||
|
||||
quote_map= {'"':'"“”', "'": "'‘’"}
|
||||
qpat = regex.compile(r'''(['"])''')
|
||||
|
||||
|
||||
def text_to_regex(text):
|
||||
ans = []
|
||||
for part in qpat.split(text):
|
||||
r = quote_map.get(part)
|
||||
if r is not None:
|
||||
ans.append('[' + r + ']')
|
||||
else:
|
||||
ans.append(regex.escape(part))
|
||||
return ''.join(ans)
|
||||
|
||||
|
||||
class Search(object):
|
||||
|
||||
def __init__(self, text, mode, case_sensitive, backwards):
|
||||
@ -72,10 +87,10 @@ class Search(object):
|
||||
if self.mode == 'word':
|
||||
words = []
|
||||
for part in expr.split():
|
||||
words.append(r'\b{}\b'.format(regex.escape(part)))
|
||||
words.append(r'\b{}\b'.format(text_to_regex(part)))
|
||||
expr = r'\s+'.join(words)
|
||||
else:
|
||||
expr = regex.escape(expr)
|
||||
expr = text_to_regex(expr)
|
||||
self._regex = regex.compile(expr, flags)
|
||||
return self._regex
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user