View Single Post
Old 09-18-2014, 06:55 PM   #568
eschwartz
Ex-Helpdesk Junkie
eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.
 
eschwartz's Avatar
 
Posts: 19,421
Karma: 85400180
Join Date: Nov 2012
Location: The Beaten Path, USA, Roundworld, This Side of Infinity
Device: Kindle Touch fw5.3.7 (Wifi only)
Quote:
Originally Posted by crissman View Post
Yes and No, Even though is a tad annoying to have a series truncated so abruptly, I do see the need for it on single word series that happens to be extra long and so I would still like to use it. Going to test out the lengths available to me on the Kindle to see what I can use.

I do like Dmee idea about having a few more letters on the Intitial Column

Code:
Name: #initials Template: {#stripped_series:re([\s]?([^\s]{1,3})[^\s]+(\s|$),\1)}
However I do get and error: I am sure it is something I am doing, but I can't see it, I copied and pasted from your post.

{#stripped_series:re([\s]?([^\s]{1,3})[^\s]+(\s|$),\1)}
Template Value: EXCEPTION: Value: unknown field 1,3
Ah, yes.

The brackets are reserved in template mode. That's why I like general program mode. Well, that and you can limit yourself to only using one custom column.

Use the general program mode version found here: http://manual.calibre-ebook.com/temp...l-program-mode
Simply fix the "stripped" variable.

PHP Code:
program:
#       compute the equivalent of the composite fields and store them in local variables
stripped re(field('series'), '^(A|The|An)\s+''');
shortened shorten(stripped4'-' ,4);
initials re(stripped'[\s]?([^\s])[^\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')
); 

Last edited by eschwartz; 09-18-2014 at 07:01 PM.
eschwartz is offline   Reply With Quote