From b83560f85c62f25d42c9556534bac6b112794797 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Thu, 16 Dec 2021 21:58:01 +0530 Subject: [PATCH] string changes --- manual/template_lang.rst | 2 +- resources/default_tweaks.py | 2 +- src/calibre/utils/formatter_functions.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/manual/template_lang.rst b/manual/template_lang.rst index c3c2176ad4..c32ae80dfd 100644 --- a/manual/template_lang.rst +++ b/manual/template_lang.rst @@ -161,7 +161,7 @@ The functions intended for use in Single Function Mode are: * ``rating_to_stars(use_half_stars)`` -- Returns the rating as string of star (``★``) characters. The value must be a number between 0 and 5. Set use_half_stars to 1 if you want half star characters for fractional numbers available with custom ratings columns. * ``re(pattern, replacement)`` -- return the value after applying the regular expression. All instances of ``pattern`` in the value are replaced with ``replacement``. The template language uses case insensitive `Python regular expressions `_. * ``select(key)`` -- interpret the value as a comma-separated list of items with each item having the form ``id:value`` (the calibre ``identifier`` format). The function finds the first pair with the id equal to key and returns the corresponding value. If no id matches then the function returns the empty string. -* ``shorten(left chars, middle text, right chars)`` -- Return a shortened version of the value, consisting of ``left chars`` characters from the beginning of the value, followed by ``middle text``, followed by ``right chars`` characters from the end of the value. ``Left chars`` and ``right chars`` must be non-negative integers. Example: assume you want to display the title with a length of at most 15 characters in length. One template that does this is ``{title:shorten(9,-,5)}``. For a book with the title `Ancient English Laws in the Times of Ivanhoe` the result will be `Ancient E-nhoe`: the first 9 characters of the title, a ``-``, then the last 5 characters. If the value's length is less than ``left chars`` + ``right chars`` + the length of ``middle text`` then the value will be returned unchanged. For example, the title `The Dome` would not be changed. +* ``shorten(left chars, middle text, right chars)`` -- Return a shortened version of the value, consisting of ``left chars`` characters from the beginning of the value, followed by ``middle text``, followed by ``right chars`` characters from the end of the value. ``Left chars`` and ``right chars`` must be non-negative integers. Example: assume you want to display the title with a length of at most 15 characters in length. One template that does this is ``{title:shorten(9,-,5)}``. For a book with the title `Ancient English Laws in the Times of Ivanhoe` the result will be `Ancient E-anhoe`: the first 9 characters of the title, a ``-``, then the last 5 characters. If the value's length is less than ``left chars`` + ``right chars`` + the length of ``middle text`` then the value will be returned unchanged. For example, the title `The Dome` would not be changed. * ``str_in_list(separator, [ string, found_val, ]+ not_found_val)`` -- interpret the value as a list of items separated by ``separator`` then compare ``string`` against each value in the list. The ``string`` is not a regular expression. If ``string`` is equal to any item (ignoring case) then return the corresponding ``found_val``. If ``string`` contains ``separators`` then it is also treated as a list and each subvalue is checked. The ``string`` and ``found_value`` pairs can be repeated as many times as desired, permitting returning different values depending on string's value. If none of the strings match then ``not_found_value`` is returned. The strings are checked in order. The first match is returned. * ``subitems(start_index, end_index)`` -- This function breaks apart lists of tag-like hierarchical items such as genres. It interprets the value as a comma-separated list of tag-like items, where each item is a period-separated list. It returns a new list made by extracting from each item the components from ``start_index`` to ``end_index``, then merging the results back together. Duplicates are removed. The first subitem in a period-separated list has an index of zero. If an index is negative then it counts from the end of the list. As a special case, an end_index of zero is assumed to be the length of the list. diff --git a/resources/default_tweaks.py b/resources/default_tweaks.py index b84ce214c7..32e15e0418 100644 --- a/resources/default_tweaks.py +++ b/resources/default_tweaks.py @@ -582,7 +582,7 @@ show_saved_search_box = False # Edit metadata->Copy metadata/Paste metadata actions. For example, # exclude_fields_on_paste = ['cover', 'timestamp', '#mycolumn'] # to prevent pasting of the cover, Date and custom column, mycolumn. -# You can also add a shortcut in Preferences->Shortcut->Edit metadata +# You can also add a shortcut in Preferences->Shortcuts->Edit metadata # to paste metadata ignoring this tweak. exclude_fields_on_paste = [] diff --git a/src/calibre/utils/formatter_functions.py b/src/calibre/utils/formatter_functions.py index d8ae667309..d1387c39b0 100644 --- a/src/calibre/utils/formatter_functions.py +++ b/src/calibre/utils/formatter_functions.py @@ -810,7 +810,7 @@ class BuiltinShorten(BuiltinFormatterFunction): 'integers. For example, assume the title of the book is ' '`Ancient English Laws in the Times of Ivanhoe`, and you want ' 'it to fit in a space of at most 15 characters. If you use ' - '{title:shorten(9,-,5)}, the result will be `Ancient E-nhoe`. ' + '{title:shorten(9,-,5)}, the result will be `Ancient E-anhoe`. ' 'If the field\'s length is less than left chars + right chars + ' 'the length of `middle text`, then the field will be used ' 'intact. For example, the title `The Dome` would not be changed.')