[Python-ideas] Fwd: Add Unicode-aware str.reverse() function?

M.-A. Lemburg mal at egenix.com
Sat Sep 8 09:22:49 EDT 2018


On 08.09.2018 15:00, Jonathan Fine wrote:
> Stephan Houben wrote:
> 
>> To be honest, quite apart from the Unicode issue, I never had a need to
>> reverse a string in real code.
>>
>> .ytilibigel edepmi ot sdnet yllareneg tI
> 
> Sometimes we have to write 'backwards' to improve legibility. Odd
> though that may sound.
> 
> Some languages are written from left to right. Some from right to
> left. And some ancient writing alternates, line to line.
> 
> https://en.wikipedia.org/wiki/Right-to-left
> https://www.andiamo.co.uk/resources/right-left-languages
> https://en.wikipedia.org/wiki/Boustrophedon
> 
> Users of modern rendering systems, such as in modern browsers, don't
> have to worry about this. This is because the renderer will handle LTR
> and RTL switches based on the language attribute. (Alway, text should
> be encoded in reading order.)
> 
> But those implementing a bidectional rendering system might have to
> worry about such things.

Most likely yes, but they would not render RTL text by first
switching the direction and then printing them LTR again.

Please also note that switching from LTR to RTL and back again
is possible within a Unicode string, so applying str.reverse()
would actually make things worse and not better :-)

Processing in Unicode is always left to right, even if the resulting
text may actually be rendered right to left or top to bottom.

See UAX #9 for more details:
http://www.unicode.org/reports/tr9/

Here's a document outlining how to render scripts which are LTR,
RTL or TTB:
https://www.w3.org/International/questions/qa-scripts

-- 
Marc-Andre Lemburg
eGenix.com

Professional Python Services directly from the Experts (#1, Sep 08 2018)
>>> Python Projects, Coaching and Consulting ...  http://www.egenix.com/
>>> Python Database Interfaces ...           http://products.egenix.com/
>>> Plone/Zope Database Interfaces ...           http://zope.egenix.com/
________________________________________________________________________

::: We implement business ideas - efficiently in both time and costs :::

   eGenix.com Software, Skills and Services GmbH  Pastor-Loeh-Str.48
    D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg
           Registered at Amtsgericht Duesseldorf: HRB 46611
               http://www.egenix.com/company/contact/
                      http://www.malemburg.com/



More information about the Python-ideas mailing list