mirror of
https://github.com/SubtitleEdit/subtitleedit.git
synced 2024-11-25 12:44:46 +01:00
Fix issue with "remove texgt for hi" and "interjections in separate line" - thx Сергей :)
This commit is contained in:
parent
d85c5c7c03
commit
38fa31398f
@ -2018,5 +2018,19 @@ namespace Test.Logic.Forms
|
||||
string actual = new RemoveInterjection().Invoke(GetRemoveInterjectionContext("Hey, ahhhh!?", onlyInSeparatedLine: false));
|
||||
Assert.AreEqual("Hey!?", actual);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void RemoveInterjectionsAllDualOh()
|
||||
{
|
||||
string actual = new RemoveInterjection().Invoke(GetRemoveInterjectionContext("- Oh, what?" + Environment.NewLine + "- Oh.", onlyInSeparatedLine: false));
|
||||
Assert.AreEqual("What?", actual);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void RemoveInterjectionsAllDualOhOnlySeparateLine()
|
||||
{
|
||||
string actual = new RemoveInterjection().Invoke(GetRemoveInterjectionContext("- Oh, what?" + Environment.NewLine + "- Oh.", onlyInSeparatedLine: true));
|
||||
Assert.AreEqual("Oh, what?", actual);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -299,6 +299,7 @@ namespace Nikse.SubtitleEdit.Core.Forms
|
||||
}
|
||||
}
|
||||
|
||||
var lineIndexRemoved = -1;
|
||||
var lines = text.SplitToLines();
|
||||
if (lines.Count == 2 && text != oldText)
|
||||
{
|
||||
@ -402,11 +403,13 @@ namespace Nikse.SubtitleEdit.Core.Forms
|
||||
{
|
||||
text = lines[0];
|
||||
lines = text.SplitToLines();
|
||||
lineIndexRemoved = 1;
|
||||
}
|
||||
else if (string.IsNullOrWhiteSpace(lines[0].RemoveChar('.', '?', '!', '-', '—')))
|
||||
{
|
||||
text = lines[1];
|
||||
lines = text.SplitToLines();
|
||||
lineIndexRemoved = 0;
|
||||
}
|
||||
}
|
||||
|
||||
@ -469,10 +472,19 @@ namespace Nikse.SubtitleEdit.Core.Forms
|
||||
var newLines = text.SplitToLines();
|
||||
if (oldLines.Count == 2 && newLines.Count == 1 &&
|
||||
(oldLines[0] == newLines[0] || oldLines[1] == newLines[0]))
|
||||
{
|
||||
{
|
||||
return text;
|
||||
}
|
||||
|
||||
if (lineIndexRemoved == 0)
|
||||
{
|
||||
return RemoveStartDashSingleLine(oldLines[1]);
|
||||
}
|
||||
else if (lineIndexRemoved == 1)
|
||||
{
|
||||
return RemoveStartDashSingleLine(oldLines[0]);
|
||||
}
|
||||
|
||||
return oldText;
|
||||
}
|
||||
}
|
||||
@ -487,5 +499,41 @@ namespace Nikse.SubtitleEdit.Core.Forms
|
||||
|
||||
return text;
|
||||
}
|
||||
|
||||
private string RemoveStartDashSingleLine(string input)
|
||||
{
|
||||
if (string.IsNullOrEmpty(input))
|
||||
{
|
||||
return input;
|
||||
}
|
||||
|
||||
var s = input;
|
||||
if (s[0] == '-')
|
||||
{
|
||||
return s.TrimStart('-').TrimStart();
|
||||
}
|
||||
|
||||
var pre = string.Empty;
|
||||
if (s.StartsWith("{\\") && s.Contains("}"))
|
||||
{
|
||||
var idx = s.IndexOf('}');
|
||||
pre = s.Substring(0, idx + 1);
|
||||
s = s.Remove(0, idx + 1).TrimStart();
|
||||
}
|
||||
|
||||
if (s.StartsWith("<i>", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
pre += "<i>";
|
||||
s = s.Remove(0, 3).TrimStart();
|
||||
}
|
||||
|
||||
if (s.StartsWith("<font>", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
pre += "<font>";
|
||||
s = s.Remove(0, 6).TrimStart();
|
||||
}
|
||||
|
||||
return pre + s.TrimStart('-').TrimStart();
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user