Skip to content

Instantly share code, notes, and snippets.

@hassanselim0
Created December 8, 2016 09:09
Show Gist options
  • Save hassanselim0/1019a9742168eedf4e67df78df5ef066 to your computer and use it in GitHub Desktop.
Save hassanselim0/1019a9742168eedf4e67df78df5ef066 to your computer and use it in GitHub Desktop.
Unity Arabic String Fix
using System;
public class ArabicFix
{
private const int N_DISTINCT_CHARACTERS = 36;
private string str;
private string Pstr;
private char[,] a;
private char[] theSet1;
private char[] theSet2;
public ArabicFix()
{
this.theSet1 = new char[] { '\u062C', '\u062D', '\u062E', '\u0647', '\u0639', '\u063A', '\u0641', '\u0642', '\u062B', '\u0635', '\u0636', '\u0637', '\u0643', '\u0645', '\u0646', '\u062A', '\u0644', '\u0628', '\u064A', '\u0633', '\u0634', '\u0638' };
this.theSet2 = new char[] { '\u0627', '\u0623', '\u0625', '\u0622', '\u062F', '\u0630', '\u0631', '\u0632', '\u0648', '\u0624', '\u0629', '\u0649', '\u0621', '\u0698' };
this.a = new char[,] { { '\u0630', '\uFEAC', '\uFEAB', '\uFEAC', '\uFEAB' }, { '\u062F', '\uFEAA', '\uFEA9', '\uFEAA', '\uFEA9' }, { '\u062C', '\uFE9E', '\uFE9F', '\uFEA0', '\uFE9D' }, { '\u062D', '\uFEA2', '\uFEA3', '\uFEA4', '\uFEA1' }, { '\u062E', '\uFEA6', '\uFEA7', '\uFEA8', '\uFEA5' }, { '\u0647', '\uFEEA', '\uFEEB', '\uFEEC', '\uFEE9' }, { '\u0639', '\uFECA', '\uFECB', '\uFECC', '\uFEC9' }, { '\u063A', '\uFECE', '\uFECF', '\uFED0', '\uFECD' }, { '\u0641', '\uFED2', '\uFED3', '\uFED4', '\uFED1' }, { '\u0642', '\uFED6', '\uFED7', '\uFED8', '\uFED5' }, { '\u062B', '\uFE9A', '\uFE9B', '\uFE9C', '\uFE99' }, { '\u0635', '\uFEBA', '\uFEBB', '\uFEBC', '\uFEB9' }, { '\u0636', '\uFEBE', '\uFEBF', '\uFEC0', '\uFEBD' }, { '\u0637', '\uFEC2', '\uFEC3', '\uFEC4', '\uFEC1' }, { '\u0643', '\uFEDA', '\uFEDB', '\uFEDC', '\uFED9' }, { '\u0645', '\uFEE2', '\uFEE3', '\uFEE4', '\uFEE1' }, { '\u0646', '\uFEE6', '\uFEE7', '\uFEE8', '\uFEE5' }, { '\u062A', '\uFE96', '\uFE97', '\uFE98', '\uFE95' }, { '\u0627', '\uFE8E', '\uFE8D', '\uFE8E', '\uFE8D' }, { '\u0644', '\uFEDE', '\uFEDF', '\uFEE0', '\uFEDD' }, { '\u0628', '\uFE90', '\uFE91', '\uFE92', '\uFE8F' }, { '\u064A', '\uFEF2', '\uFEF3', '\uFEF4', '\uFEF1' }, { '\u0633', '\uFEB2', '\uFEB3', '\uFEB4', '\uFEB1' }, { '\u0634', '\uFEB6', '\uFEB7', '\uFEB8', '\uFEB5' }, { '\u0638', '\uFEC6', '\uFEC7', '\uFEC8', '\uFEC5' }, { '\u0632', '\uFEB0', '\uFEAF', '\uFEB0', '\uFEAF' }, { '\u0648', '\uFEEE', '\uFEED', '\uFEEE', '\uFEED' }, { '\u0629', '\uFE94', '\uFE93', '\uFE93', '\uFE93' }, { '\u0649', '\uFEF0', '\uFEEF', '\uFEF0', '\uFEEF' }, { '\u0631', '\uFEAE', '\uFEAD', '\uFEAE', '\uFEAD' }, { '\u0624', '\uFE86', '\uFE85', '\uFE86', '\uFE85' }, { '\u0621', '\uFE80', '\uFE80', '\uFE80', '\uFE7F' }, { '\u0626', '\uFE8A', '\uFE8B', '\uFE8C', '\uFE89' }, { '\u0623', '\uFE84', '\uFE83', '\uFE84', '\uFE83' }, { '\u0622', '\uFE82', '\uFE81', '\uFE82', '\uFE81' }, { '\u0625', '\uFE88', '\uFE87', '\uFE88', '\uFE87' } };
}
private void ArabiChar(ref string s)
{
string str = "";
char[] charArray = s.ToCharArray();
Array.Reverse(charArray, 0, (int)charArray.Length);
s = new string(charArray);
int num = 0;
while (num < s.Length)
{
if ((s[num] < '0' ? true : s[num] > '9'))
{
str = string.Concat(str, s[num]);
num++;
}
else
{
string str1 = "";
while (true)
{
if ((s[num] < '0' ? true : s[num] > '9'))
{
break;
}
str1 = string.Concat(str1, s[num]);
num++;
}
charArray = str1.ToCharArray();
Array.Reverse(charArray, 0, (int)charArray.Length);
str1 = new string(charArray);
str = string.Concat(str, str1);
}
}
s = str;
}
public string DisplayArabic(string s)
{
bool flag;
bool flag1;
string pstr;
bool flag2;
if (s.Length > 1)
{
this.str = s;
this.Pstr = this.str;
for (int i = 0; i < this.str.Length; i++)
{
char charArray = this.str.ToCharArray()[i];
if (charArray < '\u0621' || charArray > '\u064A')
{
flag2 = (charArray < '\u067E' ? true : charArray > '\u06D5');
}
else
{
flag2 = false;
}
if (!flag2)
{
int num = 0;
while (num < 36)
{
if (this.a[num, 0] != this.str.ToCharArray()[i])
{
num++;
}
else
{
break;
}
}
if (i != this.str.Length - 1)
{
flag1 = (this.isFromTheSet1(this.str.ToCharArray()[i + 1]) ? true : this.isFromTheSet2(this.str.ToCharArray()[i + 1]));
}
else
{
flag1 = false;
}
flag = (i != 0 ? this.isFromTheSet1(this.str.ToCharArray()[i - 1]) : false);
if ((!flag ? false : flag1))
{
this.Pstr = this.Pstr.Remove(i, 1);
this.Pstr = this.Pstr.Insert(i, new string(this.a[num, 3], 1));
}
if ((!flag ? false : !flag1))
{
this.Pstr = this.Pstr.Remove(i, 1);
this.Pstr = this.Pstr.Insert(i, new string(this.a[num, 1], 1));
}
if ((flag ? false : flag1))
{
this.Pstr = this.Pstr.Remove(i, 1);
this.Pstr = this.Pstr.Insert(i, new string(this.a[num, 2], 1));
}
if ((flag ? false : !flag1))
{
this.Pstr = this.Pstr.Remove(i, 1);
this.Pstr = this.Pstr.Insert(i, new string(this.a[num, 4], 1));
}
}
}
this.ArabiChar(ref this.Pstr);
pstr = this.Pstr;
}
else
{
pstr = s;
}
return pstr;
}
private bool isFromTheSet1(char ch)
{
bool flag;
int num = 0;
while (true)
{
if (num >= 22)
{
flag = false;
break;
}
else if (ch != this.theSet1[num])
{
num++;
}
else
{
flag = true;
break;
}
}
return flag;
}
private bool isFromTheSet2(char ch)
{
bool flag;
int num = 0;
while (true)
{
if (num >= 13)
{
flag = false;
break;
}
else if (ch != this.theSet2[num])
{
num++;
}
else
{
flag = true;
break;
}
}
return flag;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment