SYNOPSIS
DESCRIPTION
The function string.utf8bidi() implements an algorithm that handles bidirectional languages and arabic joining.
The source string is scanned in logical order from first to last character. Any runs of characters that belong to a language which uses right-to-left writing are rearranged. The resulting string, then, when printed default left-to-right, will display correctly for these languages.
In addition, the function knows about the specialities of the arabic writing system. In arabic, a lot of letters need to be written differently based on their position in a word. The algorithm looks for generic arabic unicodes in the approximate range of 0x06xx. These codes are replaced by their arabic presentational forms in the range 0xFExx as appropriate.
Parameters select a substring of str that starts at i and continues until j; i and j can be negative. If j is absent, then it is assumed to be equal to -1 (which is the same as the string length).
RETURN VALUE
Returns an UTF-8 encoded string.
Due to possible ligatures, the resulting string can be shorter than the initial string. It is never longer.
NOTES
Incorporates code from the UCData package under a BSD style License.
ISSUES
The output of this function is of limited use to gcx:text(). When using word-wrap mode together with right-to-left languages, the order of lines may appear upside-down and word-wrapping wraps incorrectly.
It is recommended to use the built-in bidirectional support of gcx:text() instead, which does not have that issue.
EXAMPLE
This example uses the arabic word for "Thank you" as an example. After running through the algorithm, the order of the characters have been reversed. Also, the characters have been replaced by their presentational forms.
This prints: