MCPcopy Index your code
hub / github.com/dbcli/mycli / last_word

Function last_word

mycli/packages/sql_utils.py:27–78  ·  view source on GitHub ↗

r""" Find the last word in a sentence. >>> last_word('abc') 'abc' >>> last_word(' abc') 'abc' >>> last_word('') '' >>> last_word(' ') '' >>> last_word('abc ') '' >>> last_word('abc def') 'def' >>> last_word('abc def ') '' >>> last_word

(
    text: str,
    include: Literal[
        'alphanum_underscore',
        'many_punctuations',
        'most_punctuations',
        'all_punctuations',
    ] = 'alphanum_underscore',
)

Source from the content-addressed store, hash-verified

25
26
27def last_word(
28 text: str,
29 include: Literal[
30 'alphanum_underscore',
31 'many_punctuations',
32 'most_punctuations',
33 'all_punctuations',
34 ] = 'alphanum_underscore',
35) -> str:
36 r"""
37 Find the last word in a sentence.
38
39 >>> last_word('abc')
40 'abc'
41 >>> last_word(' abc')
42 'abc'
43 >>> last_word('')
44 ''
45 >>> last_word(' ')
46 ''
47 >>> last_word('abc ')
48 ''
49 >>> last_word('abc def')
50 'def'
51 >>> last_word('abc def ')
52 ''
53 >>> last_word('abc def;')
54 ''
55 >>> last_word('bac $def')
56 'def'
57 >>> last_word('bac $def', include='most_punctuations')
58 '$def'
59 >>> last_word('bac \def', include='most_punctuations')
60 '\\\\def'
61 >>> last_word('bac \def;', include='most_punctuations')
62 '\\\\def;'
63 >>> last_word('bac::def', include='most_punctuations')
64 'def'
65 """
66
67 if not text: # Empty string
68 return ""
69
70 if text[-1].isspace():
71 return ""
72 else:
73 regex = cleanup_regex[include]
74 matches = regex.search(text)
75 if matches:
76 return matches.group(0)
77 else:
78 return ""
79
80
81# This code is borrowed from sqlparse example script.

Callers 5

find_matchesMethod · 0.90
get_completionsMethod · 0.90
_emit_lparenFunction · 0.90
suggest_typeFunction · 0.90
test_last_wordFunction · 0.90

Calls

no outgoing calls

Tested by 1

test_last_wordFunction · 0.72