MCPcopy Create free account
hub / github.com/ElementsProject/elements / normalize

Function normalize

test/lint/lint-format-strings.py:50–62  ·  view source on GitHub ↗

Return a normalized version of string s with newlines, tabs and C style comments ("/* ... */") replaced with spaces. Multiple spaces are replaced with a single space. >>> normalize(" /* nothing */ foo\tfoo /* bar */ foo ") 'foo foo foo'

(s)

Source from the content-addressed store, hash-verified

48
49
50def normalize(s):
51 """Return a normalized version of string s with newlines, tabs and C style comments ("/* ... */")
52 replaced with spaces. Multiple spaces are replaced with a single space.
53
54 >>> normalize(" /* nothing */ foo\tfoo /* bar */ foo ")
55 'foo foo foo'
56 """
57 assert type(s) is str
58 s = s.replace("\n", " ")
59 s = s.replace("\t", " ")
60 s = re.sub(r"/\*.*?\*/", " ", s)
61 s = re.sub(" {2,}", " ", s)
62 return s.strip()
63
64
65ESCAPE_MAP = {

Callers 2

parse_string_contentFunction · 0.85

Calls 1

typeClass · 0.50

Tested by

no test coverage detected