mirror of
https://github.com/SubtitleEdit/subtitleedit.git
synced 2024-10-28 15:02:35 +01:00
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:
commit
e751b2f704
@ -103,15 +103,9 @@ namespace Nikse.SubtitleEdit.Core
|
|||||||
StrippedText = text;
|
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 = $"_@{idName}_";
|
||||||
string id = string.Format("_@{0}_", i);
|
|
||||||
while (replaceIds.Contains(id))
|
|
||||||
{
|
|
||||||
i++;
|
|
||||||
id = string.Format("_@{0}_", i);
|
|
||||||
}
|
|
||||||
replaceIds.Add(id);
|
replaceIds.Add(id);
|
||||||
replaceNames.Add(name);
|
replaceNames.Add(name);
|
||||||
return id;
|
return id;
|
||||||
@ -126,7 +120,7 @@ namespace Nikse.SubtitleEdit.Core
|
|||||||
}
|
}
|
||||||
|
|
||||||
string lower = StrippedText.ToLower();
|
string lower = StrippedText.ToLower();
|
||||||
|
int idName = 0;
|
||||||
foreach (string name in namesEtc)
|
foreach (string name in namesEtc)
|
||||||
{
|
{
|
||||||
int start = lower.IndexOf(name, StringComparison.OrdinalIgnoreCase);
|
int start = lower.IndexOf(name, StringComparison.OrdinalIgnoreCase);
|
||||||
@ -151,14 +145,14 @@ namespace Nikse.SubtitleEdit.Core
|
|||||||
string originalName = StrippedText.Substring(start, name.Length);
|
string originalName = StrippedText.Substring(start, name.Length);
|
||||||
originalNames.Add(originalName);
|
originalNames.Add(originalName);
|
||||||
StrippedText = StrippedText.Remove(start, name.Length);
|
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();
|
lower = StrippedText.ToLower();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (start + 3 > lower.Length)
|
if (start + 3 > lower.Length)
|
||||||
start = lower.Length + 1;
|
start = lower.Length + 1;
|
||||||
else
|
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();
|
StrippedText = sb.ToString();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (changeNameCases)
|
ReplaceNames2Fix(replaceIds, changeNameCases ? replaceNames : originalNames);
|
||||||
ReplaceNames2Fix(replaceIds, replaceNames);
|
|
||||||
else
|
|
||||||
ReplaceNames2Fix(replaceIds, originalNames);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user