| 131 | print("%r: Clean bill of health." % (file,)) |
| 132 | |
| 133 | class Whitespace: |
| 134 | # the characters used for space and tab |
| 135 | S, T = ' \t' |
| 136 | |
| 137 | # members: |
| 138 | # raw |
| 139 | # the original string |
| 140 | # n |
| 141 | # the number of leading whitespace characters in raw |
| 142 | # nt |
| 143 | # the number of tabs in raw[:n] |
| 144 | # norm |
| 145 | # the normal form as a pair (count, trailing), where: |
| 146 | # count |
| 147 | # a tuple such that raw[:n] contains count[i] |
| 148 | # instances of S * i + T |
| 149 | # trailing |
| 150 | # the number of trailing spaces in raw[:n] |
| 151 | # It's A Theorem that m.indent_level(t) == |
| 152 | # n.indent_level(t) for all t >= 1 iff m.norm == n.norm. |
| 153 | # is_simple |
| 154 | # true iff raw[:n] is of the form (T*)(S*) |
| 155 | |
| 156 | def __init__(self, ws): |
| 157 | self.raw = ws |
| 158 | S, T = Whitespace.S, Whitespace.T |
| 159 | count = [] |
| 160 | b = n = nt = 0 |
| 161 | for ch in self.raw: |
| 162 | if ch == S: |
| 163 | n = n + 1 |
| 164 | b = b + 1 |
| 165 | elif ch == T: |
| 166 | n = n + 1 |
| 167 | nt = nt + 1 |
| 168 | if b >= len(count): |
| 169 | count = count + [0] * (b - len(count) + 1) |
| 170 | count[b] = count[b] + 1 |
| 171 | b = 0 |
| 172 | else: |
| 173 | break |
| 174 | self.n = n |
| 175 | self.nt = nt |
| 176 | self.norm = tuple(count), b |
| 177 | self.is_simple = len(count) <= 1 |
| 178 | |
| 179 | # return length of longest contiguous run of spaces (whether or not |
| 180 | # preceding a tab) |
| 181 | def longest_run_of_spaces(self): |
| 182 | count, trailing = self.norm |
| 183 | return max(len(count)-1, trailing) |
| 184 | |
| 185 | def indent_level(self, tabsize): |
| 186 | # count, il = self.norm |
| 187 | # for i in range(len(count)): |
| 188 | # if count[i]: |
| 189 | # il = il + (i//tabsize + 1)*tabsize * count[i] |
| 190 | # return il |
no outgoing calls
no test coverage detected
searching dependent graphs…