MCPcopy
hub / github.com/dbcli/pgcli / last_word

Function last_word

pgcli/packages/parseutils/utils.py:21–66  ·  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, include="alphanum_underscore")

Source from the content-addressed store, hash-verified

19
20
21def last_word(text, include="alphanum_underscore"):
22 r"""
23 Find the last word in a sentence.
24
25 >>> last_word('abc')
26 'abc'
27 >>> last_word(' abc')
28 'abc'
29 >>> last_word('')
30 ''
31 >>> last_word(' ')
32 ''
33 >>> last_word('abc ')
34 ''
35 >>> last_word('abc def')
36 'def'
37 >>> last_word('abc def ')
38 ''
39 >>> last_word('abc def;')
40 ''
41 >>> last_word('bac $def')
42 'def'
43 >>> last_word('bac $def', include='most_punctuations')
44 '$def'
45 >>> last_word('bac \def', include='most_punctuations')
46 '\\\\def'
47 >>> last_word('bac \def;', include='most_punctuations')
48 '\\\\def;'
49 >>> last_word('bac::def', include='most_punctuations')
50 'def'
51 >>> last_word('"foo*bar', include='most_punctuations')
52 '"foo*bar'
53 """
54
55 if not text: # Empty string
56 return ""
57
58 if text[-1].isspace():
59 return ""
60 else:
61 regex = cleanup_regex[include]
62 matches = regex.search(text)
63 if matches:
64 return matches.group(0)
65 else:
66 return ""
67
68
69def find_prev_keyword(sql, n_skip=0):

Callers 4

find_matchesMethod · 0.85
get_column_matchesMethod · 0.85
__init__Method · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected