mirror of
https://github.com/SubtitleEdit/subtitleedit.git
synced 2024-11-25 12:44:46 +01:00
[Utilities] - Optimize ReverseParenthesis.
This commit is contained in:
parent
4751547332
commit
6865c7a238
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user