[Python-il] Determining if a string is RTL
Amit Aronovitch
aronovitch at gmail.com
Sun Jan 4 02:20:33 IST 2009
Whoops...
I see that (1) seems that you really do want to test for base
direction (missed that substr 0,1 in the php code...), so my examples
were really irrelevant.
(2) Meir had already made it quite explicit (providing actual code).
Conclusion:
I should never post after midnight, especially when I did not read
all the thread carefuly.
Oh well, at least I got an excuse for my fribidi-py plug (even if that
excuse was irrelevant)...
Apologies, and good night,
Amit
On Sun, Jan 4, 2009 at 1:40 AM, Amit Aronovitch <aronovitch at gmail.com> wrote:
> On Sat, Jan 3, 2009 at 11:11 PM, Dotan Cohen <dotancohen at gmail.com> wrote:
>> 2009/1/3 Meir Kriheli <meir at mksoft.co.il>:
>>> In that case he can use pygtk's pango module with the function Ori
>>> pointed to:
>>>
>
> 1) Let us make things more explicit:
>
> From the original regex, I guess you want to find whether the string
> contains any RTL characters, which is different than the question of
> finding the base direction (English text with some Hebrew words in the
> middle still has LTR direction).
>
> In that case, the relevant function is pango_unichar_direction, and
> from python it would look something like this:
>
>>>> has_rtl = pango.DIRECTION_RTL in map(pango.unichar_direction, text.decode("utf-8"))
>
> (If you wish to find the base direction, the code would be something like:
>
>>>> has_rtl = pango.DIRECTION_RTL == pango.find_base_dir(text, len(text))
> )
>
> 2) Plug: reviving my abended fribidi-py code...
>
More information about the Python-il
mailing list