Mercurial > public > mercurial-scm > hg
comparison mercurial/encoding.py @ 34200:112f118ecb00
encoding: ensure getutf8char always returns a bytestr, never an int
author | Augie Fackler <raf@durin42.com> |
---|---|
date | Fri, 15 Sep 2017 19:43:32 -0400 |
parents | a8994d08e4a2 |
children | 1c601df9894c |
comparison
equal
deleted
inserted
replaced
34199:90b0e1639fd4 | 34200:112f118ecb00 |
---|---|
456 Raises a UnicodeError if the given location does not start a valid | 456 Raises a UnicodeError if the given location does not start a valid |
457 utf-8 character. | 457 utf-8 character. |
458 ''' | 458 ''' |
459 | 459 |
460 # find how many bytes to attempt decoding from first nibble | 460 # find how many bytes to attempt decoding from first nibble |
461 l = _utf8len[ord(s[pos]) >> 4] | 461 l = _utf8len[ord(s[pos:pos + 1]) >> 4] |
462 if not l: # ascii | 462 if not l: # ascii |
463 return s[pos] | 463 return s[pos:pos + 1] |
464 | 464 |
465 c = s[pos:pos + l] | 465 c = s[pos:pos + l] |
466 # validate with attempted decode | 466 # validate with attempted decode |
467 c.decode("utf-8") | 467 c.decode("utf-8") |
468 return c | 468 return c |