Method: rich.text.Text.highlight_words
Calls: 20, Exceptions: 0, Paths: 2Back
Path 1: 16 calls (0.8)
['GET', 'POST', 'HEAD', 'PUT', 'DELETE', 'OPTIONS', 'TRACE', 'PATCH'] (16)
'logging.keyword' (16)
True (16)
0 (16)
1def highlight_words(
2 self,
3 words: Iterable[str],
4 style: Union[str, Style],
5 *,
6 case_sensitive: bool = True,
7 ) -> int:
8 """Highlight words with a style.
9
10 Args:
11 words (Iterable[str]): Worlds to highlight.
12 style (Union[str, Style]): Style to apply.
13 case_sensitive (bool, optional): Enable case sensitive matchings. Defaults to True.
14
15 Returns:
16 int: Number of words highlighted.
17 """
18 re_words = "|".join(re.escape(word) for word in words)
19 add_span = self._spans.append
20 count = 0
21 _Span = Span
22 for match in re.finditer(
23 re_words, self.plain, flags=0 if case_sensitive else re.IGNORECASE
24 ):
25 start, end = match.span(0)
26 add_span(_Span(start, end, style))
27 count += 1
28 return count
Path 2: 4 calls (0.2)
['AB'] (2) ['NOT', '!'] (1) ['[a|e|i]', '[o|u]'] (1)
'red' (4)
True (3) False (1)
1 (2) 3 (1) 4 (1)
1def highlight_words(
2 self,
3 words: Iterable[str],
4 style: Union[str, Style],
5 *,
6 case_sensitive: bool = True,
7 ) -> int:
8 """Highlight words with a style.
9
10 Args:
11 words (Iterable[str]): Worlds to highlight.
12 style (Union[str, Style]): Style to apply.
13 case_sensitive (bool, optional): Enable case sensitive matchings. Defaults to True.
14
15 Returns:
16 int: Number of words highlighted.
17 """
18 re_words = "|".join(re.escape(word) for word in words)
19 add_span = self._spans.append
20 count = 0
21 _Span = Span
22 for match in re.finditer(
23 re_words, self.plain, flags=0 if case_sensitive else re.IGNORECASE
24 ):
25 start, end = match.span(0)
26 add_span(_Span(start, end, style))
27 count += 1
28 return count