Manual de Calibre | Page 179

Manual de usuario de calibre, Publicación 2.73.0 Series: Berserkers Series Index: 4 Title: Berserker Throne Output: Bers-kers [04] Berserker Throne Series: Meg Langslow Mysteries Series Index: 3 Title: Revenge of the Wrought-Iron Flamingos Output: MLM [03] Revenge of the Wrought-Iron Flamingos El siguiente programa produce los mismos resultados que la fórmula original, usando solamente una columna personalizada para mantener los resultados de un programa que calcule el valor de título especial: Custom column: Name: #special_title Template: (the following with all leading spaces removed) program: # compute the equivalent of the composite fields and store them in local ˓→variables stripped = re(field('series'), '^(A|The|An)\s+', ''); shortened = shorten(stripped, 4, '-' ,4); initials = re(stripped, '[^\w]*(\w?)[^\s]+(\s|$)', '\1'); # # # # # # # # # # # Format the series index. Ends up as empty if there is no series index. Note that leading and trailing spaces will be removed by the formatter, so we cannot add them here. We will do that in the strcat below. Also note that because we are in 'program' mode, we can freely use curly brackets in strings, something we cannot do in template mode. s_index = template('{series_index:0>2.0f}'); print(stripped, shortened, initials, s_index); Now concatenate all the bits together. The switch picks between initials and shortened, depending on whether there is a space in stripped. We then add the brackets around s_index if it is not empty. Finally, add the title. As this is the last function in the program, its value will be returned. strcat( switch( stripped, '.\s', initials, '.', shortened, field('series')), test(s_index, strcat(' [', s_index, '] '), ''), field('title')); Plugboard expression: Template:{#special_title} Destination field