MCPcopy Create free account
hub / github.com/ActiveState/code / Characters

Class Characters

recipes/Python/577978_Text_Model/recipe-577978.py:25–64  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

23
24
25class Characters:
26 style = None
27 def __init__(self, text, style=defaultstyle):
28 self.data = text
29 self.style = style
30
31 def __len__(self):
32 return len(self.data)
33
34 def get_style(self, i):
35 return self.style
36
37 def __repr__(self):
38 return "C(%s)" % repr(self.data)
39
40 def __len(self):
41 return len(self.data)
42
43 def split(self, i):
44 if i<0 or i>len(self):
45 raise IndexError(i)
46 l = Characters(self.data[:i], self.style)
47 r = Characters(self.data[i:], self.style)
48 return l, r
49
50 def set_properties(self, i1, i2, properties):
51 i1 = max(0, i1)
52 i2 = min(len(self), i2)
53 tmp, r = self.split(i2)
54 l, tmp = tmp.split(i1)
55 style = updated_style(self.style, properties)
56 c = Characters(tmp.data, style)
57 return Group([l, c, r])
58
59 def insert(self, i, texel):
60 if isinstance(texel, Characters) and texel.style is self.style:
61 text = self.data[:i]+texel.data+self.data[i:]
62 return Characters(text, self.style)
63 a, b = self.split(i)
64 return Group([a, texel, b])
65
66
67

Callers 3

splitMethod · 0.85
set_propertiesMethod · 0.85
insertMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected