From 629133a27aec45aa7f5bc2b3ef3dc33714c57572 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20F=C3=A4hrmann?= Date: Mon, 2 Nov 2015 15:52:26 +0100 Subject: [PATCH] document text.extract --- gallery_dl/text.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/gallery_dl/text.py b/gallery_dl/text.py index 7cf996fa..18f62e3f 100644 --- a/gallery_dl/text.py +++ b/gallery_dl/text.py @@ -54,6 +54,25 @@ def shorten_filename(filename, limit=255, encoding=sys.getfilesystemencoding()): return bname.decode(encoding, "ignore") + extension def extract(txt, begin, end, pos=0): + """Extract the text between 'begin' and 'end' from 'txt' + + Args: + txt: String to search in + begin: First string to be searched for + end: Second string to be searched for after 'begin' + pos: Starting position for searches in 'txt' + + Returns: + The string between the two search-strings 'begin' and 'end' beginning + with position 'pos' in 'txt' as well as the position after 'end'. + + If at least one of 'begin' or 'end' is not found, None and the original + value of 'pos' is returned + + Examples: + extract("abcde", "b", "d") -> "c" , 4 + extract("abcde", "b", "d", 3) -> None, 3 + """ try: first = txt.index(begin, pos) + len(begin) last = txt.index(end, first)