The process is described by the bidirectional Unicode algorithm described here: http://www.unicode.org/reports/tr9/ .
By default, text is left to right (level 0). Unicode has special character codes for delimiting RTL text within level 0 (level 1). You use special characters to distinguish between LTR in RTL, etc. I think you can have up to 61 embed level.
HTML tags have the "dir" attribute to indicate the default direction.
The process is platform neutral, but you will rely on the unicode algorithm to get it right.
source share