mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
...
This commit is contained in:
commit
45fef44919
@ -17,7 +17,7 @@ from calibre.gui2 import error_dialog
|
||||
from calibre.gui2.progress_indicator import ProgressIndicator
|
||||
from calibre.utils.config import dynamic
|
||||
from calibre.utils.titlecase import titlecase
|
||||
from calibre.utils.icu import sort_key
|
||||
from calibre.utils.icu import sort_key, capitalize
|
||||
|
||||
class MyBlockingBusy(QDialog):
|
||||
|
||||
@ -187,6 +187,7 @@ class MetadataBulkDialog(QDialog, Ui_MetadataBulkDialog):
|
||||
_('Lower Case') : lambda x: icu_lower(x),
|
||||
_('Upper Case') : lambda x: icu_upper(x),
|
||||
_('Title Case') : lambda x: titlecase(x),
|
||||
_('Capitalize') : lambda x: capitalize(x),
|
||||
}
|
||||
|
||||
s_r_match_modes = [ _('Character match'),
|
||||
|
@ -1023,8 +1023,7 @@ class DeviceBooksModel(BooksModel): # {{{
|
||||
x = ''
|
||||
if y == None:
|
||||
y = ''
|
||||
x, y = icu_lower(x.strip()), icu_lower(y.strip())
|
||||
return icu_strcmp(x, y)
|
||||
return icu_strcmp(x.strip(), y.strip())
|
||||
return _strcmp
|
||||
def datecmp(x, y):
|
||||
x = self.db[x].datetime
|
||||
|
@ -8,6 +8,7 @@ import re, string, traceback
|
||||
|
||||
from calibre.constants import DEBUG
|
||||
from calibre.utils.titlecase import titlecase
|
||||
from calibre.utils.icu import capitalize
|
||||
|
||||
class TemplateFormatter(string.Formatter):
|
||||
'''
|
||||
@ -86,7 +87,7 @@ class TemplateFormatter(string.Formatter):
|
||||
'uppercase' : (0, lambda s,x: x.upper()),
|
||||
'lowercase' : (0, lambda s,x: x.lower()),
|
||||
'titlecase' : (0, lambda s,x: titlecase(x)),
|
||||
'capitalize' : (0, lambda s,x: x.capitalize()),
|
||||
'capitalize' : (0, lambda s,x: capitalize(x)),
|
||||
'contains' : (3, _contains),
|
||||
'ifempty' : (1, _ifempty),
|
||||
'lookup' : (-1, _lookup),
|
||||
|
@ -69,7 +69,7 @@ def icu_case_sensitive_sort_key(collator, obj):
|
||||
return collator.sort_key(obj)
|
||||
|
||||
def icu_strcmp(collator, a, b):
|
||||
return collator.strcmp(a.lower(), b.lower())
|
||||
return collator.strcmp(lower(a), lower(b))
|
||||
|
||||
def py_strcmp(a, b):
|
||||
return cmp(a.lower(), b.lower())
|
||||
@ -104,6 +104,13 @@ lower = (lambda s: s.lower()) if _icu_not_ok else \
|
||||
title_case = (lambda s: s.title()) if _icu_not_ok else \
|
||||
partial(_icu.title, get_locale())
|
||||
|
||||
def icu_capitalize(s):
|
||||
s = lower(s)
|
||||
return s.replace(s[0], upper(s[0]))
|
||||
|
||||
capitalize = (lambda s: s.capitalize()) if _icu_not_ok else \
|
||||
(lambda s: icu_capitalize(s))
|
||||
|
||||
################################################################################
|
||||
|
||||
def test(): # {{{
|
||||
@ -215,14 +222,15 @@ pêché'''
|
||||
print '\t', x.encode('utf-8')
|
||||
if fs != create(french_good):
|
||||
print 'French failed (note that French fails with icu < 4.6 i.e. on windows and OS X)'
|
||||
return
|
||||
# return
|
||||
test_strcmp(german + french)
|
||||
|
||||
print '\nTesting case transforms in current locale'
|
||||
for x in ('a', 'Alice\'s code'):
|
||||
print 'Upper:', x, '->', 'py:', x.upper().encode('utf-8'), 'icu:', upper(x).encode('utf-8')
|
||||
print 'Lower:', x, '->', 'py:', x.lower().encode('utf-8'), 'icu:', lower(x).encode('utf-8')
|
||||
print 'Title:', x, '->', 'py:', x.title().encode('utf-8'), 'icu:', title_case(x).encode('utf-8')
|
||||
print 'Upper: ', x, '->', 'py:', x.upper().encode('utf-8'), 'icu:', upper(x).encode('utf-8')
|
||||
print 'Lower: ', x, '->', 'py:', x.lower().encode('utf-8'), 'icu:', lower(x).encode('utf-8')
|
||||
print 'Title: ', x, '->', 'py:', x.title().encode('utf-8'), 'icu:', title_case(x).encode('utf-8')
|
||||
print 'Capitalize:', x, '->', 'py:', x.capitalize().encode('utf-8'), 'icu:', capitalize(x).encode('utf-8')
|
||||
print
|
||||
|
||||
# }}}
|
||||
|
@ -9,6 +9,8 @@ License: http://www.opensource.org/licenses/mit-license.php
|
||||
|
||||
import re
|
||||
|
||||
from calibre.utils.icu import capitalize
|
||||
|
||||
__all__ = ['titlecase']
|
||||
__version__ = '0.5'
|
||||
|
||||
@ -40,11 +42,6 @@ def titlecase(text):
|
||||
|
||||
"""
|
||||
|
||||
def capitalize(w):
|
||||
w = icu_lower(w)
|
||||
w = w.replace(w[0], icu_upper(w[0]))
|
||||
return w
|
||||
|
||||
all_caps = ALL_CAPS.match(text)
|
||||
|
||||
words = re.split('\s', text)
|
||||
|
Loading…
x
Reference in New Issue
Block a user