This uses the ICU BiDi functionality (where available) to detect whether text is left-to-right, right-to-left, or mixed, and in the mixed case, can give you a breakdown of the direction of each sub-section of text.
[CL 2652930 by Jamie Dale in Main branch]