mirror of
https://github.com/SubtitleEdit/subtitleedit.git
synced 2024-11-26 05:02:36 +01:00
Merge pull request #497 from ivandrofly/fix/patch-11
Fixed problem for <tag>-- foobar</tag> or <tag>... foobar</i>\r\n<tag>--... text</tag>
This commit is contained in:
commit
dbc3fb6bf3
@ -27,8 +27,8 @@ namespace Nikse.SubtitleEdit.Core
|
||||
{
|
||||
if (threeLengthTag && text.Length > 3 && text[0] == '<' && text[2] == '>' && (text[1] == 'i' || text[1] == 'I' || text[1] == 'u' || text[1] == 'U' || text[1] == 'b' || text[1] == 'B'))
|
||||
return true;
|
||||
if (includeFont && text.Length > 22 && text.StartsWith("<font ", StringComparison.OrdinalIgnoreCase))
|
||||
return true;
|
||||
if (includeFont && text.Length > 5 && text.StartsWith("<font", StringComparison.OrdinalIgnoreCase))
|
||||
return text.IndexOf('>', 5) >= 5; // <font> or <font color="#000000">
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -2884,14 +2884,18 @@ namespace Nikse.SubtitleEdit.Forms
|
||||
text = text.Replace("... </", "...</"); // </i>, </font>...
|
||||
text = text.Replace("... ?", "...?");
|
||||
text = text.Replace("... !", "...!");
|
||||
if (text.StartsWith("... ", StringComparison.Ordinal))
|
||||
text = text.Remove(3, 1);
|
||||
if (text.StartsWith("<i>... ", StringComparison.Ordinal))
|
||||
text = text.Remove(6, 1);
|
||||
if (text.StartsWith("<font>... ", StringComparison.Ordinal))
|
||||
text = text.Remove("<font>... ".Length - 1, 1);
|
||||
if (text.StartsWith("<b>... ", StringComparison.Ordinal))
|
||||
text = text.Remove("<b>... ".Length - 1, 1);
|
||||
|
||||
if (text.IndexOf(Environment.NewLine, StringComparison.Ordinal) > 1)
|
||||
{
|
||||
var lines = text.SplitToLines();
|
||||
for (int k = 0; k < lines.Length; k++)
|
||||
lines[k] = FixCommonErrorsHelper.RemoveSpacesBeingLineAfterEllipese(lines[k]);
|
||||
text = string.Join(Environment.NewLine, lines);
|
||||
}
|
||||
else
|
||||
{
|
||||
text = FixCommonErrorsHelper.RemoveSpacesBeingLineAfterEllipese(text);
|
||||
}
|
||||
}
|
||||
//if (text.EndsWith('-'))
|
||||
//{
|
||||
|
@ -29,10 +29,10 @@ namespace Nikse.SubtitleEdit.Logic.Forms
|
||||
}
|
||||
|
||||
// "...foobar"
|
||||
if(text.StartsWith("\"..", StringComparison.Ordinal))
|
||||
if (text.StartsWith("\"..", StringComparison.Ordinal))
|
||||
{
|
||||
var endIdx = 0;
|
||||
while (text[++endIdx] == '.');
|
||||
while (text[++endIdx] == '.') ;
|
||||
text = text.Remove(1, endIdx - 1);
|
||||
}
|
||||
|
||||
@ -305,14 +305,41 @@ namespace Nikse.SubtitleEdit.Logic.Forms
|
||||
if (text.LineStartsWithHtmlTag(false, true))
|
||||
{
|
||||
var closeIdx = text.IndexOf('>');
|
||||
if (closeIdx > -1 && text[closeIdx + 1] == 0x20)
|
||||
{
|
||||
if (closeIdx > 6 && text[closeIdx + 1] == 0x20)
|
||||
text = text.Remove(closeIdx + 1, 1);
|
||||
}
|
||||
}
|
||||
return text;
|
||||
}
|
||||
|
||||
public static string RemoveSpacesBeingLineAfterEllipese(string line)
|
||||
{
|
||||
if (line.StartsWith("... ", StringComparison.Ordinal))
|
||||
line = line.Remove(3, 1);
|
||||
if (line.Length > 6 && line.LineStartsWithHtmlTag(true)) // <i>... foobar
|
||||
{
|
||||
var idx = line.IndexOf('>') + 1;
|
||||
var pre = line.Substring(0, idx);
|
||||
line = line.Remove(0, idx).TrimStart();
|
||||
if(line.StartsWith("... "))
|
||||
line = line.Remove(3, 1);
|
||||
line = pre + line;
|
||||
}
|
||||
if (line.LineStartsWithHtmlTag(false, true)) //<font color="#000000"> and <font>
|
||||
{
|
||||
// Todo: what if line number is > 1
|
||||
var closeIdx = line.IndexOf('>', 5);
|
||||
if (closeIdx >= 5 && line.Length > closeIdx + 5)
|
||||
{
|
||||
var fontTag = line.Substring(0, closeIdx + 1).TrimStart();
|
||||
line = line.Substring(closeIdx + 1).TrimStart();
|
||||
if (line.StartsWith("... ", StringComparison.Ordinal))
|
||||
line = line.Remove("... ".Length - 1, 1);
|
||||
line = fontTag + line;
|
||||
}
|
||||
}
|
||||
return line;
|
||||
}
|
||||
|
||||
public static string FixHyphensAdd(Subtitle subtitle, int i, string language)
|
||||
{
|
||||
Paragraph p = subtitle.Paragraphs[i];
|
||||
@ -351,7 +378,7 @@ namespace Nikse.SubtitleEdit.Logic.Forms
|
||||
{
|
||||
// add dash in second line.
|
||||
newLineIdx += 2;
|
||||
if(text.LineBreakStartsWithHtmlTag(true))
|
||||
if (text.LineBreakStartsWithHtmlTag(true))
|
||||
{
|
||||
text = text.Insert(newLineIdx + 3, "- ").TrimEnd();
|
||||
}
|
||||
|
@ -1312,5 +1312,34 @@ namespace Test
|
||||
|
||||
#endregion Fix dialogs on one line
|
||||
|
||||
#region FixDoubleDash
|
||||
|
||||
[TestMethod]
|
||||
[DeploymentItem("SubtitleEdit.exe")]
|
||||
public void FixDoubleDashTest1()
|
||||
{
|
||||
using (var target = GetFixCommonErrorsLib())
|
||||
{
|
||||
// <font color="#000000"> and <font>
|
||||
InitializeFixCommonErrorsLine(target, "<font color=\"#000000\">-- Mm-hmm.</font>");
|
||||
target.FixDoubleDash();
|
||||
Assert.AreEqual(target.Subtitle.Paragraphs[0].Text, "<font color=\"#000000\">...Mm-hmm.</font>");
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[DeploymentItem("SubtitleEdit.exe")]
|
||||
public void FixDoubleDashTest2()
|
||||
{
|
||||
using (var target = GetFixCommonErrorsLib())
|
||||
{
|
||||
// <font color="#000000"> and <font>
|
||||
InitializeFixCommonErrorsLine(target, "<b>Mm-hmm.</b>\r\n<font color=\"#000000\">-- foobar</font>");
|
||||
target.FixDoubleDash();
|
||||
Assert.AreEqual(target.Subtitle.Paragraphs[0].Text, "<b>Mm-hmm.</b>\r\n<font color=\"#000000\">...foobar</font>");
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user