mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Undo changes to the switch function. The new documentation left out the first parameter, in effect documenting the usage in single function mode.
This commit is contained in:
parent
078e2a2654
commit
266be27bc3
@ -768,8 +768,8 @@ class BuiltinSwitch(BuiltinFormatterFunction):
|
|||||||
category = 'Iterating over values'
|
category = 'Iterating over values'
|
||||||
__doc__ = doc = _(
|
__doc__ = doc = _(
|
||||||
r'''
|
r'''
|
||||||
``switch([pattern, value,]+ else_value)`` -- for each ``pattern, value`` pair,
|
``switch(value, [pattern, value,]+ else_value)`` -- for each ``pattern, value`` pair,
|
||||||
checks if the field matches the regular expression ``pattern`` and if so returns
|
checks if the value matches the regular expression ``pattern`` and if so returns
|
||||||
the associated ``value``. If no ``pattern`` matches, then ``else_value`` is
|
the associated ``value``. If no ``pattern`` matches, then ``else_value`` is
|
||||||
returned. You can have as many ``pattern, value`` pairs as you wish. The first
|
returned. You can have as many ``pattern, value`` pairs as you wish. The first
|
||||||
match is returned.
|
match is returned.
|
||||||
@ -777,7 +777,7 @@ match is returned.
|
|||||||
|
|
||||||
def evaluate(self, formatter, kwargs, mi, locals, val, *args):
|
def evaluate(self, formatter, kwargs, mi, locals, val, *args):
|
||||||
if (len(args) % 2) != 1:
|
if (len(args) % 2) != 1:
|
||||||
raise ValueError(_('switch requires an odd number of arguments'))
|
raise ValueError(_('switch requires an even number of arguments'))
|
||||||
i = 0
|
i = 0
|
||||||
while i < len(args):
|
while i < len(args):
|
||||||
if i + 1 >= len(args):
|
if i + 1 >= len(args):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user