| 66 | |
| 67 | |
| 68 | class Group: |
| 69 | def __init__(self, content): |
| 70 | self.data = list(content) |
| 71 | length = 0 |
| 72 | for texel in content: |
| 73 | length += len(texel) |
| 74 | self._length = length |
| 75 | |
| 76 | def __len__(self): |
| 77 | return self._length |
| 78 | |
| 79 | def __repr__(self): |
| 80 | return "G(%s)" % repr(self.data) |
| 81 | |
| 82 | def get_style(self, i): |
| 83 | for texel in self.data: |
| 84 | n = len(texel) |
| 85 | if n>i: |
| 86 | return texel.get_style(i) |
| 87 | i -= n |
| 88 | |
| 89 | def set_properties(self, i1, i2, properties): |
| 90 | r = [] |
| 91 | i = 0 |
| 92 | for texel in self.data: |
| 93 | n = len(texel) |
| 94 | if i1<n and i2>0: |
| 95 | r.append(texel.set_properties(i1, i2, properties)) |
| 96 | else: |
| 97 | r.append(texel) |
| 98 | i1 -= n |
| 99 | i2 -= n |
| 100 | return Group(r) |
| 101 | |
| 102 | def split(self, i): |
| 103 | if i<0 or i>len(self): |
| 104 | raise IndexError(i) |
| 105 | l = [] |
| 106 | r = [] |
| 107 | for texel in self.data: |
| 108 | n = len(texel) |
| 109 | if i<=0: |
| 110 | r.append(texel) |
| 111 | elif i>=n: |
| 112 | l.append(texel) |
| 113 | elif n>i: |
| 114 | a, b = texel.split(i) |
| 115 | l.append(a) |
| 116 | r.append(b) |
| 117 | i -= n |
| 118 | return Group(l), Group(r) |
| 119 | |
| 120 | def insert(self, i, texel): |
| 121 | if i == len(self): |
| 122 | return Group(self.data+[texel]) |
| 123 | |
| 124 | data = [] |
| 125 | for elem in self.data: |
no outgoing calls
no test coverage detected