mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-08-05 08:40:13 -04:00
Test the 'test' function. Add 're' function and test it.
This commit is contained in:
parent
5297562383
commit
25905a349c
@ -43,6 +43,9 @@ class TemplateFormatter(string.Formatter):
|
|||||||
else:
|
else:
|
||||||
return val
|
return val
|
||||||
|
|
||||||
|
def _re(self, val, pattern, replacement):
|
||||||
|
return re.sub(pattern, replacement, val)
|
||||||
|
|
||||||
functions = {
|
functions = {
|
||||||
'uppercase' : (0, lambda s,x: x.upper()),
|
'uppercase' : (0, lambda s,x: x.upper()),
|
||||||
'lowercase' : (0, lambda s,x: x.lower()),
|
'lowercase' : (0, lambda s,x: x.lower()),
|
||||||
@ -50,8 +53,9 @@ class TemplateFormatter(string.Formatter):
|
|||||||
'capitalize' : (0, lambda s,x: x.capitalize()),
|
'capitalize' : (0, lambda s,x: x.capitalize()),
|
||||||
'ifempty' : (1, _ifempty),
|
'ifempty' : (1, _ifempty),
|
||||||
'lookup' : (2, _lookup),
|
'lookup' : (2, _lookup),
|
||||||
|
're' : (2, _re),
|
||||||
'shorten' : (3, _shorten),
|
'shorten' : (3, _shorten),
|
||||||
'test' : (2, _lookup),
|
'test' : (2, _test),
|
||||||
}
|
}
|
||||||
|
|
||||||
format_string_re = re.compile(r'^(.*)\|(.*)\|(.*)$')
|
format_string_re = re.compile(r'^(.*)\|(.*)\|(.*)$')
|
||||||
|
Loading…
x
Reference in New Issue
Block a user