Improved: FixEllipsesStartHelper

This commit is contained in:
ivandrofly 2015-02-08 16:29:26 +00:00
parent 4bd0ba0657
commit 6e7a2166f0

View File

@ -12,106 +12,47 @@ namespace Nikse.SubtitleEdit.Logic.Forms
if (string.IsNullOrEmpty(text) || text.Trim().Length < 4 || !(text.Contains("..", StringComparison.Ordinal) || text.Contains(". .", StringComparison.Ordinal)))
return text;
const string preChars = ">-\"”“'`´¶#♪♫¿¡—";
var pre = string.Empty;
if (text.StartsWith("<font ", StringComparison.Ordinal) && text.IndexOf('>', 5) >= 0)
text = text.TrimStart();
for (int i = 0; i < 3; i++)
{
var idx = text.IndexOf('>', 5);
if (idx >= 0)
while (text.Length > 1 && preChars.Contains(text[0]))
{
pre = text.Substring(0, text.IndexOf('>') + 1);
text = text.Substring(idx + 1).TrimStart();
pre += text[0];
text = text.Substring(1).TrimStart();
}
}
if (text.StartsWith("...", StringComparison.Ordinal))
{
text = text.TrimStart('.').TrimStart();
}
// "...foobar" / "... foobar" / ". .. foobar"
if (text.StartsWith("\"") && (text.StartsWith("\"..") || text.StartsWith("\". .") || text.StartsWith("\" ..") || text.StartsWith("\" . .")))
{
int removeLength = 0;
while (removeLength + 1 < text.Length && (text[1 + removeLength] == '.' || text[1 + removeLength] == ' '))
removeLength++;
text = text.Remove(1, removeLength);
}
text = text.Replace("-..", "- ..");
var tag = "- ...";
if (text.StartsWith(tag, StringComparison.Ordinal))
{
text = "- " + text.Substring(tag.Length);
while (text.StartsWith("- .", StringComparison.Ordinal))
//<font color="#000000">
if (text.StartsWith("<font", StringComparison.OrdinalIgnoreCase) && text.IndexOf('>', 5) >= 5)
{
text = "- " + text.Substring(3);
text = text.Replace(" ", " ");
var idx = text.IndexOf('>', 5);
if (idx >= 5)
{
pre += text.Substring(0, text.IndexOf('>') + 1);
text = text.Substring(idx + 1).TrimStart();
}
}
// <b>, <u>, <i>
while (text.Length > 3 && text[0] == '<' && text[2] == '>')
{
pre += "<" + text[1] + ">";
text = text.Substring(3).TrimStart();
}
}
tag = "<i>...";
if (text.StartsWith(tag, StringComparison.Ordinal))
{
text = "<i>" + text.Substring(tag.Length);
while (text.StartsWith("<i>.", StringComparison.Ordinal) || text.StartsWith("<i> ", StringComparison.Ordinal))
text = "<i>" + text.Substring(4);
}
tag = "<i> ...";
if (text.StartsWith(tag, StringComparison.Ordinal))
{
text = "<i>" + text.Substring(tag.Length);
while (text.StartsWith("<i>.", StringComparison.Ordinal) || text.StartsWith("<i> ", StringComparison.Ordinal))
text = "<i>" + text.Substring(4, text.Length - 4);
}
tag = "- <i>...";
if (text.StartsWith(tag, StringComparison.Ordinal))
{
text = "- <i>" + text.Substring(tag.Length);
while (text.StartsWith("- <i>.", StringComparison.Ordinal))
text = "- <i>" + text.Substring(6);
}
tag = "- <i> ...";
if (text.StartsWith(tag, StringComparison.Ordinal))
{
text = "- <i>" + text.Substring(tag.Length);
while (text.StartsWith("- <i>.", StringComparison.Ordinal))
text = "- <i>" + text.Substring(6);
}
// Narrator:... Hello foo!
text = text.Replace(":..", ": ..");
tag = ": ..";
if (text.Contains(tag, StringComparison.Ordinal))
{
text = text.Replace(": ..", ": ");
while (text.Contains(": ."))
text = text.Replace(": .", ": ");
}
// <i>- ... Foo</i>
tag = "<i>- ...";
if (text.StartsWith(tag, StringComparison.Ordinal))
{
text = text.Substring(tag.Length);
text = text.TrimStart('.', ' ');
text = "<i>- " + text;
}
text = text.Replace(" ", " ");
// WOMAN 2: <i>...24 hours a day at BabyC.</i>
var index = text.IndexOf(':');
if (index > 0 && text.Length > index + 2 && !char.IsDigit(text[index + 1]) && text.Contains("..", StringComparison.Ordinal))
if (index >= 1 && !Utilities.IsBetweenNumbers(text, index) &&
(text.Contains("..", StringComparison.Ordinal) || text.Contains(". .", StringComparison.Ordinal)))
{
pre += text.Substring(0, index + 1);
if (pre.Length < 2)
return text;
text = text.Remove(0, index + 1).TrimStart();
text = text.Substring(index + 1).TrimStart();
text = FixEllipsesStartHelper(text);
if (pre.Length > 0)
pre += " ";
}
if (pre.Length > 1 && !" >\"".Contains(pre[pre.Length - 1]))
pre += " ";
return pre + text;
}