I found a bug in my code submitted later,, if we have a word that contains شدة & the previous letter has a tashkeel, then the Shada will be assigned to the previous letter instead of the correct one.
internal static string RemoveTashkeel(string str, out List<TashkeelLocation> tashkeelLocation)
{
tashkeelLocation = new List<TashkeelLocation>();
char[] letters = str.ToCharArray();
int index = 0;
bool lastWasLetter = true;
int combined = 0;
for (int i = 0; i < letters.Length; i++)
{
bool currentIsLetter = false;
if (letters[i] == (char)0x064B)
{ // Tanween Fatha
tashkeelLocation.Add(new TashkeelLocation((char)0x064B, i - combined));
index++;
}
else if (letters[i] == (char)0x064C)
{ // Tanween Damma
if (index > 0 && combineTashkeel && lastWasLetter == false)
{
if (tashkeelLocation[index - 1].tashkeel == (char)0x0651) // Shadda
{
tashkeelLocation[index - 1] = new TashkeelLocation((char)0xFC5E, i - 1 - combined); // Shadda With Tanween Damma
combined++;
continue;
}
}
tashkeelLocation.Add(new TashkeelLocation((char)0x064C, i - combined));
index++;
}
else if (letters[i] == (char)0x064D)
{ // Tanween Kasra
if (index > 0 && combineTashkeel && lastWasLetter == false)
{
if (tashkeelLocation[index - 1].tashkeel == (char)0x0651) // Shadda
{
tashkeelLocation[index - 1] = new TashkeelLocation((char)0xFC5F, i - 1 - combined); // Shadda With Tanween Kasra
combined++;
continue;
}
}
tashkeelLocation.Add(new TashkeelLocation((char)0x064D, i - combined));
index++;
}
else if (letters[i] == (char)0x064E)
{ // Fatha
if (index > 0 && combineTashkeel && lastWasLetter == false)
{
if (tashkeelLocation[index - 1].tashkeel == (char)0x0651) // Shadda
{
tashkeelLocation[index - 1] = new TashkeelLocation((char)0xFC60, i - 1 - combined); // Shadda With Fatha
combined++;
continue;
}
}
tashkeelLocation.Add(new TashkeelLocation((char)0x064E, i - combined));
index++;
}
else if (letters[i] == (char)0x064F)
{ // DAMMA
if (index > 0 && combineTashkeel && lastWasLetter == false)
{
if (tashkeelLocation[index - 1].tashkeel == (char)0x0651)
{ // SHADDA
tashkeelLocation[index - 1] = new TashkeelLocation((char)0xFC61, i - 1 - combined); // Shadda With DAMMA
combined++;
continue;
}
}
tashkeelLocation.Add(new TashkeelLocation((char)0x064F, i - combined));
index++;
}
else if (letters[i] == (char)0x0650)
{ // KASRA
if (index > 0 && combineTashkeel && lastWasLetter == false)
{
if (tashkeelLocation[index - 1].tashkeel == (char)0x0651)
{ // SHADDA
tashkeelLocation[index - 1] = new TashkeelLocation((char)0xFC62, i - 1 - combined); // Shadda With KASRA
combined++;
continue;
}
}
tashkeelLocation.Add(new TashkeelLocation((char)0x0650, i - combined));
index++;
}
else if (letters[i] == (char)0x0651)
{ // SHADDA
if (index > 0 && combineTashkeel && lastWasLetter == false)
{
if (tashkeelLocation[index - 1].tashkeel == (char)0x064E) // FATHA
{
tashkeelLocation[index - 1] = new TashkeelLocation((char)0xFC60, i - 1 - combined); // Shadda With Fatha
combined++;
continue;
}
if (tashkeelLocation[index - 1].tashkeel == (char)0x064F) // DAMMA
{
tashkeelLocation[index - 1] = new TashkeelLocation((char)0xFC61, i - 1 - combined); // Shadda With DAMMA
combined++;
continue;
}
if (tashkeelLocation[index - 1].tashkeel == (char)0x0650) // KASRA
{
tashkeelLocation[index - 1] = new TashkeelLocation((char)0xFC62, i - 1 - combined); // Shadda With KASRA
combined++;
continue;
}
if (tashkeelLocation[index - 1].tashkeel == (char)0x064D) // Tanween Kasra
{
tashkeelLocation[index - 1] = new TashkeelLocation((char)0xFC5F, i - 1 - combined); // Shadda With Tanween Kasra
combined++;
continue;
}
if (tashkeelLocation[index - 1].tashkeel == (char)0x064C) // Tanween Damma
{
tashkeelLocation[index - 1] = new TashkeelLocation((char)0xFC5E, i - 1 - combined); // Shadda With Tanween Damma
combined++;
continue;
}
}
tashkeelLocation.Add(new TashkeelLocation((char)0x0651, i - combined));
index++;
}
else if (letters[i] == (char)0x0652)
{ // SUKUN
tashkeelLocation.Add(new TashkeelLocation((char)0x0652, i - combined));
index++;
}
else if (letters[i] == (char)0x0653)
{ // MADDAH ABOVE
tashkeelLocation.Add(new TashkeelLocation((char)0x0653, i - combined));
index++;
}
else if (letters[i] == (char)0xFC62)
{
tashkeelLocation.Add(new TashkeelLocation((char)0xFC62, i - combined));
index++;
}
else if (letters[i] == (char)0xFC61)
{
tashkeelLocation.Add(new TashkeelLocation((char)0xFC61, i - combined));
index++;
}
else if (letters[i] == (char)0xFC60)
{
tashkeelLocation.Add(new TashkeelLocation((char)0xFC60, i - combined));
index++;
}
else
currentIsLetter = true;
lastWasLetter = currentIsLetter;
}
string[] split = str.Split(new char[]{(char)0x064B,(char)0x064C,(char)0x064D,
(char)0x064E,(char)0x064F,(char)0x0650,
(char)0x0651,(char)0x0652,(char)0x0653,(char)0xFC60,(char)0xFC61,(char)0xFC62});
str = "";
foreach (string s in split)
{
str += s;
}
return str;
}
Another Edit ( 4 Feb 2019 )
Edit ( 19Dec2018 )
Function is updated to fix some bugs.
Hi :)
I found a bug in my code submitted later,, if we have a word that contains شدة & the previous letter has a tashkeel, then the Shada will be assigned to the previous letter instead of the correct one.
I have to fix it
but if someone is searching for a fix until a Merge request is created
Just replace the RemoveTaskeel method