MCPcopy
hub / github.com/SirVer/ultisnips / _replace_conditional

Function _replace_conditional

pythonx/UltiSnips/text_objects/transformation.py:52–66  ·  view source on GitHub ↗

Replaces a conditional match in a transformation.

(match, string)

Source from the content-addressed store, hash-verified

50
51
52def _replace_conditional(match, string):
53 """Replaces a conditional match in a transformation."""
54 conditional_match = _CONDITIONAL.search(string)
55 while conditional_match:
56 start = conditional_match.start()
57 end = _find_closing_brace(string, start + 4)
58 args = _split_conditional(string[start + 4 : end - 1])
59 rv = ""
60 if match.group(int(conditional_match.group(1))):
61 rv = unescape(_replace_conditional(match, args[0]))
62 elif len(args) > 1:
63 rv = unescape(_replace_conditional(match, args[1]))
64 string = string[:start] + rv + string[end:]
65 conditional_match = _CONDITIONAL.search(string)
66 return string
67
68
69_ONE_CHAR_CASE_SWITCH = re.compile(r"\\([ul].)", re.DOTALL)

Callers 1

replaceMethod · 0.85

Calls 4

unescapeFunction · 0.90
_find_closing_braceFunction · 0.85
_split_conditionalFunction · 0.85
startMethod · 0.80

Tested by

no test coverage detected