* Added approaches and articles for reverse-string. * Added code snippets for each approach. * remaned files to silence configlet. * renamed article snippets to .md to satisfy configlet. * Apply suggestions from code review Therefor != Therefore. TIL. Added missing link, so should no longer be broken. * Added more on the downfalls and gotchas of unicode. * Wrapping this up for now. * Deleted the Unicode directory for now.
8 lines
413 B
Plaintext
8 lines
413 B
Plaintext
given, output = bytearray(text.encode("utf-8")), bytearray(len(given))
|
|
index, LENGTH_MASK = 0, 0xE0 # 0b11110000 or 224
|
|
while index < len(given):
|
|
seq_len = not(given[index] >> 7) or (given[index] & LENGTH_MASK).bit_count()
|
|
location = index + seq_len +1
|
|
output[-location:-index or None] = given[index:index + seq_len]
|
|
index += seq_len
|
|
return output.decode("utf-8") |