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