[Utilities] - Optimize ReverseParenthesis.

This commit is contained in:
Ivandro Ismael 2016-11-24 18:05:57 +00:00
parent 4751547332
commit 6865c7a238

View File

@ -1218,17 +1218,35 @@ namespace Nikse.SubtitleEdit.Core
private static string ReverseParenthesis(string s)
{
const string k = "@__<<>___@";
s = s.Replace("(", k);
s = s.Replace(')', '(');
s = s.Replace(k, ")");
s = s.Replace("[", k);
s = s.Replace(']', '[');
s = s.Replace(k, "]");
return s;
if (string.IsNullOrEmpty(s))
{
return s;
}
int len = s.Length;
char[] chars = new char[len];
// O(n)
for (int i = len - 1; i >= 0; i--)
{
char ch = s[i];
if (ch == '(')
{
ch = ')';
}
else if (ch == ')')
{
ch = '(';
}
else if (ch == '[')
{
ch = ']';
}
else if (ch == ']')
{
ch = '[';
}
chars[i] = ch;
}
return new string(chars);
}
public static string FixEnglishTextInRightToLeftLanguage(string text, string reverseChars)