270 else: |
270 else: |
271 utf8Len = 1 |
271 utf8Len = 1 |
272 while len(ch) < utf8Len: |
272 while len(ch) < utf8Len: |
273 pos += 1 |
273 pos += 1 |
274 ch += self.byteAt(pos) |
274 ch += self.byteAt(pos) |
275 return ch.decode('utf8') |
275 try: |
|
276 return ch.decode('utf8') |
|
277 except UnicodeDecodeError: |
|
278 if pos > 0: |
|
279 # try it one position before; maybe we are in the |
|
280 # middle of a unicode character |
|
281 return self.charAt(pos - 1) |
|
282 else: |
|
283 return "" |
276 else: |
284 else: |
277 return ch.decode() |
285 return ch.decode() |
278 |
286 |
279 def byteAt(self, pos): |
287 def byteAt(self, pos): |
280 """ |
288 """ |