RTLFixer.cs 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. using System;
  2. namespace I2.Loc
  3. {
  4. public class RTLFixer
  5. {
  6. public static string Fix(string str)
  7. {
  8. return RTLFixer.Fix(str, false, true);
  9. }
  10. public static string Fix(string str, bool rtl)
  11. {
  12. if (rtl)
  13. {
  14. return RTLFixer.Fix(str);
  15. }
  16. string[] array = str.Split(new char[]
  17. {
  18. ' '
  19. });
  20. string text = string.Empty;
  21. string text2 = string.Empty;
  22. foreach (string text3 in array)
  23. {
  24. if (char.IsLower(text3.ToLower()[text3.Length / 2]))
  25. {
  26. text = text + RTLFixer.Fix(text2) + text3 + " ";
  27. text2 = string.Empty;
  28. }
  29. else
  30. {
  31. text2 = text2 + text3 + " ";
  32. }
  33. }
  34. if (text2 != string.Empty)
  35. {
  36. text += RTLFixer.Fix(text2);
  37. }
  38. return text;
  39. }
  40. public static string Fix(string str, bool showTashkeel, bool useHinduNumbers)
  41. {
  42. string text = HindiFixer.Fix(str);
  43. if (text != str)
  44. {
  45. return text;
  46. }
  47. RTLFixerTool.showTashkeel = showTashkeel;
  48. RTLFixerTool.useHinduNumbers = useHinduNumbers;
  49. if (str.Contains("\n"))
  50. {
  51. str = str.Replace("\n", Environment.NewLine);
  52. }
  53. if (!str.Contains(Environment.NewLine))
  54. {
  55. return RTLFixerTool.FixLine(str);
  56. }
  57. string[] separator = new string[]
  58. {
  59. Environment.NewLine
  60. };
  61. string[] array = str.Split(separator, StringSplitOptions.None);
  62. if (array.Length == 0)
  63. {
  64. return RTLFixerTool.FixLine(str);
  65. }
  66. if (array.Length == 1)
  67. {
  68. return RTLFixerTool.FixLine(str);
  69. }
  70. string text2 = RTLFixerTool.FixLine(array[0]);
  71. int i = 1;
  72. if (array.Length > 1)
  73. {
  74. while (i < array.Length)
  75. {
  76. text2 = text2 + Environment.NewLine + RTLFixerTool.FixLine(array[i]);
  77. i++;
  78. }
  79. }
  80. return text2;
  81. }
  82. }
  83. }