Quote:
Originally Posted by DMee
My bad re comples_series - I had forgotten we went for a manual Y/N re complex series
I was thinking of the code
https://www.mobileread.com/forums/sho...&postcount=552
To set the correct format.
I thought the code before the latest tweak took care of leading spaces later on - yours adds brackets and then original adds 2 more brackets later on :-)
|
Whoopsie.
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(stripped, 4, '-' ,4);
initials = re(list_re(stripped, ' ', '[\s]?([^\s]{1,3})[^\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.
#
# Using the new ser_num calculation from https://www.mobileread.com/forums/showpost.php?p=2916022&postcount=548
s_index = test(
field('#complex_series'),
finish_formatting(
field('series_index'),
'_>7.2f',
'',
''
),
finish_formatting(
field('series_index'),
'_>4d',
'',
''
),
);
# 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')
);
If we are using chaley's script, it's even easier. Just plug in "#complex_series" as the actual value of s_index.
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(stripped, 4, '-' ,4);
initials = re(list_re(stripped, ' ', '[\s]?([^\s]{1,3})[^\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 is now a manually set value using field "#complex_series"
s_index = field('#complex_series');
# 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')
);