6

How an Arabic string can be reversed using C++? For instance, the reverse of كلمة is ةملك. Shape of Arabic letters differs according to position in the word. (initial,medial or final of word). Are there other rules to concatenate Arabic letters?

Shafik Yaghmour
  • 154,301
  • 39
  • 440
  • 740
user1766006
  • 177
  • 1
  • 14
  • 5
    This looks like it's going to be a difficult task unless you have a library to do it. Does the Unicode specification capture this concept of "reversing" where the reverse string is not just the same characters in reverse? If so, maybe a Unicode implementation will work... Or is it up to the font renderer to draw the glyphs correctly depending on their order and so you can just reverse the order of characters? – Joseph Mansfield Feb 25 '15 at 14:06
  • 2
    The recommendation is just [logically reverse the text](http://www.w3.org/International/questions/qa-visual-vs-logical), and leave the visual reversing to the rendering engine. – Anya Shenanigans Feb 25 '15 at 14:08
  • Why do you want to do this anyway? – dfeuer Feb 25 '15 at 14:10
  • You might look at the implementation details of the [Pango](http://www.pango.org/) library. IIRC, it handles things like direction, ligatures, etc., and supports Semitic languages, as well as many others. – Brett Hale Feb 25 '15 at 14:35

1 Answers1

5

As Petesh says and according to the references I can find such as Wikipedia the rendering engine should take of using the appropriate glyphs for you. Quoting the article:

For example, many Arabic letters are represented by a different glyph when the letter appears at the end of a word than when the letter appears at the beginning of a word. Unicode's approach prefers to have these letters mapped to the same character for ease of internal machine text processing and storage. To complement this approach, the text software must select different glyph variants for display of the character based on its context

A quick experiment with an online unicode convertor seem to confirm that:

كلمة

in hex code points is:

0643 0644 0645 0629

while:

ةملك

is:

0629 0645 0644 0643

which is the exact reverse of the previous code points.

Shafik Yaghmour
  • 154,301
  • 39
  • 440
  • 740