From 8aaf03ef284d8e2b7ffed38301e7e5b60c0f8f62 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sat, 13 Dec 2014 17:03:30 +0530 Subject: [PATCH] E-book viewer: Fix sorting of bookmarks by position in book not working on windows and OS X. Fixes #1402152 [error when sorting bookmarks by position](https://bugs.launchpad.net/calibre/+bug/1402152) --- src/calibre/ebooks/epub/cfi/parse.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/calibre/ebooks/epub/cfi/parse.py b/src/calibre/ebooks/epub/cfi/parse.py index fb80b9f3bb..569e4fe70c 100644 --- a/src/calibre/ebooks/epub/cfi/parse.py +++ b/src/calibre/ebooks/epub/cfi/parse.py @@ -6,9 +6,11 @@ from __future__ import (unicode_literals, division, absolute_import, __license__ = 'GPL v3' __copyright__ = '2014, Kovid Goyal ' -import regex +import regex, sys from future_builtins import map, zip +is_narrow_build = sys.maxunicode < 0x10ffff + class Parser(object): ''' See epubcfi.ebnf for the specification that this parser tries to @@ -19,7 +21,10 @@ class Parser(object): def __init__(self): # All allowed unicode characters + escaped special characters special_char = r'[\[\](),;=^]' - unescaped_char = '[[\t\n\r -\ud7ff\ue000-\ufffd\U00010000-\U0010ffff]--%s]' % special_char + if is_narrow_build: + unescaped_char = '[[\t\n\r -\ud7ff\ue000-\ufffd]--%s]' % special_char + else: + unescaped_char = '[[\t\n\r -\ud7ff\ue000-\ufffd\U00010000-\U0010ffff]--%s]' % special_char escaped_char = r'\^' + special_char chars = r'(?:%s|(?:%s))+' % (unescaped_char, escaped_char) chars_no_space = chars.replace('0020', '0021')