For ref: http://en.wikipedia.org/wiki/Arabic_alphabet and http://en.wikipedia.org/wiki/Arabic_characters_in_Unicode
Firstly, I don't know much about Arabic word forms and I just read the Wikipedia doc on it (linked above). Thanks for giving me a reason to read up on it but forgive me if I totally mess this up :-)...
The problem seems to be mapping the char to it's correct "case" based on it's position in the word, right? I'm basing this on the changes you showed in your examples. Anyway, in English this would be like upper-casing the the first letter. In Arabic it appears there are 4 char cases( Beginning, Middle, End and Isolated ). If this is correct here is an example in C# which does this mapping:
class ArabicMapper
{
enum CaseMap{End=0, Middle=1, Beginning=2, Isolated=3};
Dictionary<char, char[]> charMap; // This maps base letters to one of their four cases.
public ArabicMapper()
{
//Create the char map for each letter in the alphabet. {BaseLetter, {End, Middle, Beginning, Isolated}}
charMap = new Dictionary<char, char[]>();
charMap.Add(0627, new char[] { FE8D, 0627, 0627, FE8E }); // ʾalif : Not sure of the rules for middle/beginning, so just using the isolated...
charMap.Add(0628, new char[] { FE90, FE92, FE91, FE8F }); // bāʾ :
//... and so on for each char ...
}
public string charsToWord(char[] word)
{
if (word.Length >= 2)
{
StringBuilder finalWord = new StringBuilder();
for(int i=0; i<word.Length; i++)
{
if (i == 0)
finalWord.Append((charMap[word[i]])[CaseMap.Beginning]);
else if(i == word.Length-1)
finalWord.Append((charMap[word[i]])[CaseMap.End]);
else
finalWord.Append((charMap[word[i]])[CaseMap.Middle]);
}
return finalWord.ToString();
}
else
{
(charMap[word[0]])[CaseMap.Isolated].ToString();
}
}
}
P.S. I didn't test this code so it may not work. Treat it as pseudocode, please.