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

Method replace

pythonx/UltiSnips/text_objects/transformation.py:81–116  ·  view source on GitHub ↗

Replaces 'match' through the correct replacement string.

(self, match)

Source from the content-addressed store, hash-verified

79 self._expression = expression
80
81 def replace(self, match):
82 """Replaces 'match' through the correct replacement string."""
83 transformed = self._expression
84 # Replace all $? with capture groups
85 transformed = _DOLLAR.subn(lambda m: match.group(int(m.group(1))), transformed)[
86 0
87 ]
88
89 # Shelter escaped backslashes (\\) so they are not consumed by
90 # case-switch regexes (\l, \u, \U, \L) or whitespace escapes
91 # (\n, \t, ...). Restored before the final unescape() which
92 # turns \\ into a literal \. GH #998, GH #1495.
93 _ESCAPED_BSLASH = "\x00"
94 transformed = transformed.replace("\\\\", _ESCAPED_BSLASH)
95
96 # Replace Case switches
97 def _one_char_case_change(match):
98 """Replaces one character case changes."""
99 if match.group(1)[0] == "u":
100 return match.group(1)[-1].upper()
101 return match.group(1)[-1].lower()
102
103 transformed = _ONE_CHAR_CASE_SWITCH.subn(_one_char_case_change, transformed)[0]
104
105 def _multi_char_case_change(match):
106 """Replaces multi character case changes."""
107 if match.group(1)[0] == "U":
108 return match.group(1)[1:].upper()
109 return match.group(1)[1:].lower()
110
111 transformed = _LONG_CASEFOLDINGS.subn(_multi_char_case_change, transformed)[0]
112 transformed = _replace_conditional(match, transformed)
113
114 transformed = fill_in_whitespace(transformed)
115 transformed = transformed.replace(_ESCAPED_BSLASH, "\\\\")
116 return unescape(transformed)
117
118
119# flag used to display only one time the lack of unidecode

Callers 15

fill_in_whitespaceFunction · 0.80
_show_user_warningFunction · 0.80
indent_to_spacesMethod · 0.80
spaces_to_indentMethod · 0.80
convFunction · 0.80
evalFunction · 0.80
_eval_codeMethod · 0.80
_precompile_globalsMethod · 0.80
handle_actionFunction · 0.80
handle_contextFunction · 0.80

Calls 3

fill_in_whitespaceFunction · 0.90
unescapeFunction · 0.90
_replace_conditionalFunction · 0.85

Tested by

no test coverage detected