Merge pull request #1660 from ivandrofly/st-patch-2

[StrippableText] - Don't need to loop to replaceIds.Count for every name inserted.
This commit is contained in:
Nikolaj Olsson 2016-03-27 18:27:21 +02:00
commit e751b2f704

View File

@ -103,15 +103,9 @@ namespace Nikse.SubtitleEdit.Core
StrippedText = text;
}
private static string GetAndInsertNextId(List<string> replaceIds, List<string> replaceNames, string name)
private static string GetAndInsertNextId(List<string> replaceIds, List<string> replaceNames, string name, int idName)
{
int i = 0;
string id = string.Format("_@{0}_", i);
while (replaceIds.Contains(id))
{
i++;
id = string.Format("_@{0}_", i);
}
string id = $"_@{idName}_";
replaceIds.Add(id);
replaceNames.Add(name);
return id;
@ -126,7 +120,7 @@ namespace Nikse.SubtitleEdit.Core
}
string lower = StrippedText.ToLower();
int idName = 0;
foreach (string name in namesEtc)
{
int start = lower.IndexOf(name, StringComparison.OrdinalIgnoreCase);
@ -151,14 +145,14 @@ namespace Nikse.SubtitleEdit.Core
string originalName = StrippedText.Substring(start, name.Length);
originalNames.Add(originalName);
StrippedText = StrippedText.Remove(start, name.Length);
StrippedText = StrippedText.Insert(start, GetAndInsertNextId(replaceIds, replaceNames, name));
StrippedText = StrippedText.Insert(start, GetAndInsertNextId(replaceIds, replaceNames, name, idName++));
lower = StrippedText.ToLower();
}
}
if (start + 3 > lower.Length)
start = lower.Length + 1;
else
start = lower.IndexOf(name.ToLower(), start + 3, StringComparison.Ordinal);
start = lower.IndexOf(name, start + 3, StringComparison.OrdinalIgnoreCase);
}
}
@ -276,10 +270,7 @@ namespace Nikse.SubtitleEdit.Core
StrippedText = sb.ToString();
}
if (changeNameCases)
ReplaceNames2Fix(replaceIds, replaceNames);
else
ReplaceNames2Fix(replaceIds, originalNames);
ReplaceNames2Fix(replaceIds, changeNameCases ? replaceNames : originalNames);
}
}